mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 10:57:58 +00:00
Store entrance fields as columns on table
This commit is contained in:
@@ -629,19 +629,27 @@ CREATE OR REPLACE FUNCTION place_update_entrances(placeid BIGINT, osmid BIGINT)
|
||||
RETURNS INTEGER
|
||||
AS $$
|
||||
DECLARE
|
||||
entrances JSONB;
|
||||
entrance RECORD;
|
||||
osm_ids BIGINT[];
|
||||
BEGIN
|
||||
SELECT jsonb_agg(jsonb_build_object('osm_id', osm_id, 'type', type, 'lat', ST_Y(geometry), 'lon', ST_X(geometry), 'extratags', extratags))
|
||||
osm_ids := '{}';
|
||||
FOR entrance in SELECT osm_id, type, geometry, extratags
|
||||
FROM place
|
||||
WHERE osm_id IN (SELECT unnest(nodes) FROM planet_osm_ways WHERE id=osmid) AND class IN ('routing:entrance', 'entrance')
|
||||
INTO entrances;
|
||||
IF entrances IS NOT NULL THEN
|
||||
INSERT INTO place_entrance (place_id, entrances)
|
||||
SELECT placeid, entrances
|
||||
ON CONFLICT (place_id) DO UPDATE
|
||||
SET entrances = excluded.entrances;
|
||||
WHERE osm_type = 'N'
|
||||
AND osm_id IN (SELECT unnest(nodes) FROM planet_osm_ways WHERE id=osmid)
|
||||
AND class IN ('routing:entrance', 'entrance')
|
||||
LOOP
|
||||
osm_ids := array_append(osm_ids, entrance.osm_id);
|
||||
INSERT INTO placex_entrance (place_id, osm_id, type, location, extratags)
|
||||
VALUES (placeid, entrance.osm_id, entrance.type, entrance.geometry, entrance.extratags)
|
||||
ON CONFLICT (place_id, osm_id) DO UPDATE
|
||||
SET type = excluded.type, location = excluded.location, extratags = excluded.extratags;
|
||||
END LOOP;
|
||||
|
||||
IF array_length(osm_ids, 1) > 0 THEN
|
||||
DELETE FROM placex_entrance WHERE place_id=placeid AND NOT osm_id=ANY(osm_ids);
|
||||
ELSE
|
||||
DELETE FROM place_entrance WHERE place_id=placeid;
|
||||
DELETE FROM placex_entrance WHERE place_id=placeid;
|
||||
END IF;
|
||||
|
||||
RETURN NULL;
|
||||
|
||||
@@ -245,18 +245,21 @@ CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry) {{
|
||||
GRANT SELECT ON location_postcode TO "{{config.DATABASE_WEBUSER}}" ;
|
||||
|
||||
-- Table to store location of entrance nodes
|
||||
DROP TABLE IF EXISTS place_entrance;
|
||||
CREATE TABLE place_entrance (
|
||||
DROP TABLE IF EXISTS placex_entrance;
|
||||
CREATE TABLE placex_entrance (
|
||||
place_id BIGINT NOT NULL,
|
||||
entrances JSONB NOT NULL
|
||||
osm_id BIGINT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
location GEOMETRY(Point, 4326) NOT NULL,
|
||||
extratags HSTORE
|
||||
);
|
||||
CREATE UNIQUE INDEX idx_place_entrance_place_id ON place_entrance
|
||||
USING BTREE (place_id) {{db.tablespace.search_index}};
|
||||
GRANT SELECT ON place_entrance TO "{{config.DATABASE_WEBUSER}}" ;
|
||||
CREATE UNIQUE INDEX idx_placex_entrance_place_id_osm_id ON placex_entrance
|
||||
USING BTREE (place_id, osm_id) {{db.tablespace.search_index}};
|
||||
GRANT SELECT ON placex_entrance TO "{{config.DATABASE_WEBUSER}}" ;
|
||||
|
||||
-- Create an index on the place table for lookups to populate the entrance
|
||||
-- table
|
||||
CREATE INDEX IF NOT EXISTS idx_place_entrance_lookup ON place
|
||||
CREATE INDEX IF NOT EXISTS idx_placex_entrance_lookup ON place
|
||||
USING BTREE (osm_id)
|
||||
WHERE class IN ('routing:entrance', 'entrance');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user