1 -- SPDX-License-Identifier: GPL-2.0-only
3 -- This file is part of Nominatim. (https://nominatim.org)
5 -- Copyright (C) 2022 by the Nominatim developer community.
6 -- For a full list of authors see the git log.
7 DROP TABLE IF EXISTS location_property_tiger_import;
8 CREATE TABLE location_property_tiger_import (linegeo GEOMETRY, place_id BIGINT, partition INTEGER, parent_place_id BIGINT, startnumber INTEGER, endnumber INTEGER, interpolationtype TEXT, postcode TEXT);
10 CREATE OR REPLACE FUNCTION tiger_line_import(linegeo GEOMETRY, in_startnumber INTEGER,
11 in_endnumber INTEGER, interpolationtype TEXT,
12 token_info JSONB, in_postcode TEXT) RETURNS INTEGER
19 place_centroid GEOMETRY;
20 out_partition INTEGER;
21 out_parent_place_id BIGINT;
26 IF in_endnumber > in_startnumber THEN
27 startnumber := in_startnumber;
28 endnumber := in_endnumber;
30 startnumber := in_endnumber;
31 endnumber := in_startnumber;
32 linegeo := ST_Reverse(linegeo);
35 IF startnumber < 0 THEN
36 RAISE WARNING 'Negative house number range (% to %)', startnumber, endnumber;
40 numberrange := endnumber - startnumber;
42 IF (interpolationtype = 'odd' AND startnumber % 2 = 0) OR (interpolationtype = 'even' AND startnumber % 2 = 1) THEN
43 startnumber := startnumber + 1;
46 IF (interpolationtype = 'odd' OR interpolationtype = 'even') THEN
48 ELSE -- everything else assumed to be 'all'
53 -- Filter out really broken tiger data
55 and numberrange::float/stepsize::float > 500
56 and ST_length(linegeo)/(numberrange::float/stepsize::float) < 0.000001
58 RAISE WARNING 'Road too short for number range % to % (%)',startnumber,endnumber,
59 ST_length(linegeo)/(numberrange::float/stepsize::float);
63 place_centroid := ST_Centroid(linegeo);
64 out_partition := get_partition('us');
66 out_parent_place_id := getNearestNamedRoadPlaceId(out_partition, place_centroid,
69 IF out_parent_place_id IS NULL THEN
70 SELECT getNearestParallelRoadFeature(out_partition, linegeo)
71 INTO out_parent_place_id;
74 IF out_parent_place_id IS NULL THEN
75 SELECT getNearestRoadPlaceId(out_partition, place_centroid)
76 INTO out_parent_place_id;
79 --insert street(line) into import table
80 insert into location_property_tiger_import (linegeo, place_id, partition,
81 parent_place_id, startnumber, endnumber,
83 values (linegeo, nextval('seq_place'), out_partition,
84 out_parent_place_id, startnumber, endnumber,
85 stepsize, in_postcode);