From f1a5862f3d030ed3c609c1bb56a2f76d03c0fa09 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 5 Jan 2020 16:04:04 +0100 Subject: [PATCH] move creation function for aux data into own file This function is currently unused, so don't even load it. --- sql/functions.sql | 48 ------------------------------ sql/functions/aux_property.sql | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 sql/functions/aux_property.sql diff --git a/sql/functions.sql b/sql/functions.sql index 24acf7c8..6a8c0d77 100644 --- a/sql/functions.sql +++ b/sql/functions.sql @@ -2144,54 +2144,6 @@ $$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION aux_create_property(pointgeo GEOMETRY, in_housenumber TEXT, - in_street TEXT, in_isin TEXT, in_postcode TEXT, in_countrycode char(2)) RETURNS INTEGER - AS $$ -DECLARE - - newpoints INTEGER; - place_centroid GEOMETRY; - out_partition INTEGER; - out_parent_place_id BIGINT; - location RECORD; - address_street_word_id INTEGER; - out_postcode TEXT; - -BEGIN - - place_centroid := ST_Centroid(pointgeo); - out_partition := get_partition(in_countrycode); - out_parent_place_id := null; - - address_street_word_id := get_name_id(make_standard_name(in_street)); - IF address_street_word_id IS NOT NULL THEN - FOR location IN SELECT * from getNearestNamedRoadFeature(out_partition, place_centroid, address_street_word_id) LOOP - out_parent_place_id := location.place_id; - END LOOP; - END IF; - - IF out_parent_place_id IS NULL THEN - FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP - out_parent_place_id := location.place_id; - END LOOP; - END IF; - - out_postcode := in_postcode; - IF out_postcode IS NULL THEN - SELECT postcode from placex where place_id = out_parent_place_id INTO out_postcode; - END IF; - -- XXX look into postcode table - - newpoints := 0; - insert into location_property_aux (place_id, partition, parent_place_id, housenumber, postcode, centroid) - values (nextval('seq_place'), out_partition, out_parent_place_id, in_housenumber, out_postcode, place_centroid); - newpoints := newpoints + 1; - - RETURN newpoints; -END; -$$ -LANGUAGE plpgsql; - CREATE OR REPLACE FUNCTION get_osm_rel_members(members TEXT[], member TEXT) RETURNS TEXT[] AS $$ DECLARE diff --git a/sql/functions/aux_property.sql b/sql/functions/aux_property.sql new file mode 100644 index 00000000..b622f78b --- /dev/null +++ b/sql/functions/aux_property.sql @@ -0,0 +1,54 @@ +-- Functions for adding external data (currently unused). + +CREATE OR REPLACE FUNCTION aux_create_property(pointgeo GEOMETRY, in_housenumber TEXT, + in_street TEXT, in_isin TEXT, + in_postcode TEXT, in_countrycode char(2)) + RETURNS INTEGER + AS $$ +DECLARE + + newpoints INTEGER; + place_centroid GEOMETRY; + out_partition INTEGER; + out_parent_place_id BIGINT; + location RECORD; + address_street_word_id INTEGER; + out_postcode TEXT; + +BEGIN + + place_centroid := ST_Centroid(pointgeo); + out_partition := get_partition(in_countrycode); + out_parent_place_id := null; + + address_street_word_id := get_name_id(make_standard_name(in_street)); + IF address_street_word_id IS NOT NULL THEN + FOR location IN SELECT * from getNearestNamedRoadFeature(out_partition, place_centroid, address_street_word_id) LOOP + out_parent_place_id := location.place_id; + END LOOP; + END IF; + + IF out_parent_place_id IS NULL THEN + FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP + out_parent_place_id := location.place_id; + END LOOP; + END IF; + + out_postcode := in_postcode; + IF out_postcode IS NULL THEN + SELECT postcode from placex where place_id = out_parent_place_id INTO out_postcode; + END IF; + -- XXX look into postcode table + + newpoints := 0; + insert into location_property_aux (place_id, partition, parent_place_id, + housenumber, postcode, centroid) + values (nextval('seq_place'), out_partition, out_parent_place_id, + in_housenumber, out_postcode, place_centroid); + newpoints := newpoints + 1; + + RETURN newpoints; +END; +$$ +LANGUAGE plpgsql; +