forked from hans/Nominatim
add postcode to location_area tables
This commit is contained in:
@@ -574,36 +574,39 @@ CREATE OR REPLACE FUNCTION add_location(
|
|||||||
keywords INTEGER[],
|
keywords INTEGER[],
|
||||||
rank_search INTEGER,
|
rank_search INTEGER,
|
||||||
rank_address INTEGER,
|
rank_address INTEGER,
|
||||||
|
in_postcode TEXT,
|
||||||
geometry GEOMETRY
|
geometry GEOMETRY
|
||||||
)
|
)
|
||||||
RETURNS BOOLEAN
|
RETURNS BOOLEAN
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
locationid INTEGER;
|
locationid INTEGER;
|
||||||
isarea BOOLEAN;
|
|
||||||
centroid GEOMETRY;
|
centroid GEOMETRY;
|
||||||
diameter FLOAT;
|
diameter FLOAT;
|
||||||
x BOOLEAN;
|
x BOOLEAN;
|
||||||
splitGeom RECORD;
|
splitGeom RECORD;
|
||||||
secgeo GEOMETRY;
|
secgeo GEOMETRY;
|
||||||
|
postcode TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
IF rank_search > 25 THEN
|
IF rank_search > 25 THEN
|
||||||
RAISE EXCEPTION 'Adding location with rank > 25 (% rank %)', place_id, rank_search;
|
RAISE EXCEPTION 'Adding location with rank > 25 (% rank %)', place_id, rank_search;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- RAISE WARNING 'Adding location with rank > 25 (% rank %)', place_id, rank_search;
|
|
||||||
|
|
||||||
x := deleteLocationArea(partition, place_id, rank_search);
|
x := deleteLocationArea(partition, place_id, rank_search);
|
||||||
|
|
||||||
isarea := false;
|
-- add postcode only if it contains a single entry, i.e. ignore postcode lists
|
||||||
IF (ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') AND ST_IsValid(geometry)) THEN
|
IF in_postcode IS NULL OR in_postcode similar to '%(,|;)%' THEN
|
||||||
|
postcode := NULL;
|
||||||
|
ELSE
|
||||||
|
postcode := in_postcode;
|
||||||
|
END IF;
|
||||||
|
|
||||||
isArea := true;
|
IF ST_GeometryType(geometry) in ('ST_Polygon','ST_MultiPolygon') THEN
|
||||||
centroid := ST_Centroid(geometry);
|
centroid := ST_Centroid(geometry);
|
||||||
|
|
||||||
FOR secgeo IN select split_geometry(geometry) AS geom LOOP
|
FOR secgeo IN select split_geometry(geometry) AS geom LOOP
|
||||||
x := insertLocationAreaLarge(partition, place_id, country_code, keywords, rank_search, rank_address, false, centroid, secgeo);
|
x := insertLocationAreaLarge(partition, place_id, country_code, keywords, rank_search, rank_address, false, postcode, centroid, secgeo);
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
ELSE
|
ELSE
|
||||||
@@ -628,7 +631,7 @@ BEGIN
|
|||||||
-- RAISE WARNING 'adding % diameter %', place_id, diameter;
|
-- RAISE WARNING 'adding % diameter %', place_id, diameter;
|
||||||
|
|
||||||
secgeo := ST_Buffer(geometry, diameter);
|
secgeo := ST_Buffer(geometry, diameter);
|
||||||
x := insertLocationAreaLarge(partition, place_id, country_code, keywords, rank_search, rank_address, true, ST_Centroid(geometry), secgeo);
|
x := insertLocationAreaLarge(partition, place_id, country_code, keywords, rank_search, rank_address, true, postcode, ST_Centroid(geometry), secgeo);
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
@@ -1529,7 +1532,7 @@ BEGIN
|
|||||||
-- Just be happy with inheriting from parent road only
|
-- Just be happy with inheriting from parent road only
|
||||||
|
|
||||||
IF NEW.rank_search <= 25 and NEW.rank_address > 0 THEN
|
IF NEW.rank_search <= 25 and NEW.rank_address > 0 THEN
|
||||||
result := add_location(NEW.place_id, NEW.country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, NEW.geometry);
|
result := add_location(NEW.place_id, NEW.country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, NEW.address->'postcode', NEW.geometry);
|
||||||
--DEBUG: RAISE WARNING 'Place added to location table';
|
--DEBUG: RAISE WARNING 'Place added to location table';
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
@@ -1901,7 +1904,7 @@ BEGIN
|
|||||||
IF NEW.name IS NOT NULL THEN
|
IF NEW.name IS NOT NULL THEN
|
||||||
|
|
||||||
IF NEW.rank_search <= 25 and NEW.rank_address > 0 THEN
|
IF NEW.rank_search <= 25 and NEW.rank_address > 0 THEN
|
||||||
result := add_location(NEW.place_id, NEW.country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, NEW.geometry);
|
result := add_location(NEW.place_id, NEW.country_code, NEW.partition, name_vector, NEW.rank_search, NEW.rank_address, NEW.address->'postcode', NEW.geometry);
|
||||||
--DEBUG: RAISE WARNING 'added to location (full)';
|
--DEBUG: RAISE WARNING 'added to location (full)';
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ $$
|
|||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
create or replace function insertLocationAreaLarge(
|
create or replace function insertLocationAreaLarge(
|
||||||
in_partition INTEGER, in_place_id BIGINT, in_country_code VARCHAR(2), in_keywords INTEGER[],
|
in_partition INTEGER, in_place_id BIGINT, in_country_code VARCHAR(2), in_keywords INTEGER[],
|
||||||
in_rank_search INTEGER, in_rank_address INTEGER, in_estimate BOOLEAN,
|
in_rank_search INTEGER, in_rank_address INTEGER, in_estimate BOOLEAN, postcode TEXT,
|
||||||
in_centroid GEOMETRY, in_geometry GEOMETRY) RETURNS BOOLEAN AS $$
|
in_centroid GEOMETRY, in_geometry GEOMETRY) RETURNS BOOLEAN AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
BEGIN
|
BEGIN
|
||||||
@@ -72,8 +72,8 @@ BEGIN
|
|||||||
|
|
||||||
-- start
|
-- start
|
||||||
IF in_partition = -partition- THEN
|
IF in_partition = -partition- THEN
|
||||||
INSERT INTO location_area_large_-partition- (partition, place_id, country_code, keywords, rank_search, rank_address, isguess, centroid, geometry)
|
INSERT INTO location_area_large_-partition- (partition, place_id, country_code, keywords, rank_search, rank_address, isguess, postcode, centroid, geometry)
|
||||||
values (in_partition, in_place_id, in_country_code, in_keywords, in_rank_search, in_rank_address, in_estimate, in_centroid, in_geometry);
|
values (in_partition, in_place_id, in_country_code, in_keywords, in_rank_search, in_rank_address, in_estimate, postcode, in_centroid, in_geometry);
|
||||||
RETURN TRUE;
|
RETURN TRUE;
|
||||||
END IF;
|
END IF;
|
||||||
-- end
|
-- end
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ CREATE TABLE location_area (
|
|||||||
rank_address SMALLINT NOT NULL,
|
rank_address SMALLINT NOT NULL,
|
||||||
country_code VARCHAR(2),
|
country_code VARCHAR(2),
|
||||||
isguess BOOL,
|
isguess BOOL,
|
||||||
|
postcode TEXT,
|
||||||
centroid GEOMETRY(Point, 4326),
|
centroid GEOMETRY(Point, 4326),
|
||||||
geometry GEOMETRY(Geometry, 4326)
|
geometry GEOMETRY(Geometry, 4326)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user