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 (
12 parent_place_id BIGINT,
18 CREATE OR REPLACE FUNCTION tiger_line_import(linegeo GEOMETRY, in_startnumber INTEGER,
19 in_endnumber INTEGER, interpolationtype TEXT,
20 token_info JSONB, in_postcode TEXT) RETURNS INTEGER
27 place_centroid GEOMETRY;
28 out_partition INTEGER;
29 out_parent_place_id BIGINT;
34 IF in_endnumber > in_startnumber THEN
35 startnumber := in_startnumber;
36 endnumber := in_endnumber;
38 startnumber := in_endnumber;
39 endnumber := in_startnumber;
40 linegeo := ST_Reverse(linegeo);
43 IF startnumber < 0 THEN
44 RAISE WARNING 'Negative house number range (% to %)', startnumber, endnumber;
48 numberrange := endnumber - startnumber;
50 IF (interpolationtype = 'odd' AND startnumber % 2 = 0) OR (interpolationtype = 'even' AND startnumber % 2 = 1) THEN
51 startnumber := startnumber + 1;
54 IF (interpolationtype = 'odd' OR interpolationtype = 'even') THEN
56 ELSE -- everything else assumed to be 'all'
61 -- Filter out really broken tiger data
63 and numberrange::float/stepsize::float > 500
64 and ST_length(linegeo)/(numberrange::float/stepsize::float) < 0.000001
66 RAISE WARNING 'Road too short for number range % to % (%)',startnumber,endnumber,
67 ST_length(linegeo)/(numberrange::float/stepsize::float);
71 place_centroid := ST_Centroid(linegeo);
72 out_partition := get_partition('us');
74 out_parent_place_id := getNearestNamedRoadPlaceId(out_partition, place_centroid,
77 IF out_parent_place_id IS NULL THEN
78 SELECT getNearestParallelRoadFeature(out_partition, linegeo)
79 INTO out_parent_place_id;
82 IF out_parent_place_id IS NULL THEN
83 SELECT getNearestRoadPlaceId(out_partition, place_centroid)
84 INTO out_parent_place_id;
87 --insert street(line) into import table
88 insert into location_property_tiger_import (linegeo, place_id, partition,
89 parent_place_id, startnumber, endnumber,
91 values (linegeo, nextval('seq_place'), out_partition,
92 out_parent_place_id, startnumber, endnumber,
93 stepsize, in_postcode);