]> git.openstreetmap.org Git - nominatim.git/blob - sql/functions/aux_property.sql
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / sql / functions / aux_property.sql
1 -- Functions for adding external data (currently unused).
2
3 CREATE OR REPLACE FUNCTION aux_create_property(pointgeo GEOMETRY, in_housenumber TEXT,
4                                                in_street TEXT, in_isin TEXT,
5                                                in_postcode TEXT, in_countrycode char(2))
6   RETURNS INTEGER
7   AS $$
8 DECLARE
9
10   newpoints INTEGER;
11   place_centroid GEOMETRY;
12   out_partition INTEGER;
13   out_parent_place_id BIGINT;
14   location RECORD;
15   address_street_word_id INTEGER;
16   out_postcode TEXT;
17
18 BEGIN
19
20   place_centroid := ST_Centroid(pointgeo);
21   out_partition := get_partition(in_countrycode);
22   out_parent_place_id := null;
23
24   address_street_word_id := get_name_id(make_standard_name(in_street));
25   IF address_street_word_id IS NOT NULL THEN
26     FOR location IN SELECT * from getNearestNamedRoadFeature(out_partition, place_centroid, address_street_word_id) LOOP
27       out_parent_place_id := location.place_id;
28     END LOOP;
29   END IF;
30
31   IF out_parent_place_id IS NULL THEN
32     FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP
33       out_parent_place_id := location.place_id;
34     END LOOP;
35   END IF;
36
37   out_postcode := in_postcode;
38   IF out_postcode IS NULL THEN
39     SELECT postcode from placex where place_id = out_parent_place_id INTO out_postcode;
40   END IF;
41   -- XXX look into postcode table
42
43   newpoints := 0;
44   insert into location_property_aux (place_id, partition, parent_place_id,
45                                      housenumber, postcode, centroid)
46     values (nextval('seq_place'), out_partition, out_parent_place_id,
47             in_housenumber, out_postcode, place_centroid);
48   newpoints := newpoints + 1;
49
50   RETURN newpoints;
51 END;
52 $$
53 LANGUAGE plpgsql;
54