]> git.openstreetmap.org Git - nominatim.git/blob - sql/functions/aux_property.sql
Merge branch 'separate-compilation' of https://github.com/eyusupov/Nominatim into...
[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_ids 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_ids := word_ids_from_name(in_street);
25   IF address_street_word_ids IS NOT NULL THEN
26     out_parent_place_id := getNearestNamedRoadPlaceId(out_partition, place_centroid,
27                                                       address_street_word_ids);
28   END IF;
29
30   IF out_parent_place_id IS NULL THEN
31     SELECT getNearestRoadPlaceId(out_partition, place_centroid)
32       INTO out_parent_place_id;
33     END LOOP;
34   END IF;
35
36   out_postcode := in_postcode;
37   IF out_postcode IS NULL THEN
38     SELECT postcode from placex where place_id = out_parent_place_id INTO out_postcode;
39   END IF;
40   -- XXX look into postcode table
41
42   newpoints := 0;
43   insert into location_property_aux (place_id, partition, parent_place_id,
44                                      housenumber, postcode, centroid)
45     values (nextval('seq_place'), out_partition, out_parent_place_id,
46             in_housenumber, out_postcode, place_centroid);
47   newpoints := newpoints + 1;
48
49   RETURN newpoints;
50 END;
51 $$
52 LANGUAGE plpgsql;
53