1 DROP TABLE IF EXISTS location_property_tiger_import;
2 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);
4 CREATE OR REPLACE FUNCTION tiger_line_import(linegeo GEOMETRY, in_startnumber INTEGER,
5 in_endnumber INTEGER, interpolationtype TEXT,
6 in_street TEXT, in_isin TEXT, in_postcode TEXT) RETURNS INTEGER
13 place_centroid GEOMETRY;
14 out_partition INTEGER;
15 out_parent_place_id BIGINT;
17 address_street_word_ids INTEGER[];
21 IF in_endnumber > in_startnumber THEN
22 startnumber = in_startnumber;
23 endnumber = in_endnumber;
25 startnumber = in_endnumber;
26 endnumber = in_startnumber;
29 IF startnumber < 0 THEN
30 RAISE WARNING 'Negative house number range (% to %) on %, %', startnumber, endnumber, in_street, in_isin;
34 numberrange := endnumber - startnumber;
36 IF (interpolationtype = 'odd' AND startnumber%2 = 0) OR (interpolationtype = 'even' AND startnumber%2 = 1) THEN
37 startnumber := startnumber + 1;
40 IF (interpolationtype = 'odd' OR interpolationtype = 'even') THEN
42 ELSE -- everything else assumed to be 'all'
47 -- Filter out really broken tiger data
48 IF numberrange > 0 AND (numberrange::float/stepsize::float > 500)
49 AND ST_length(linegeo)/(numberrange::float/stepsize::float) < 0.000001 THEN
50 RAISE WARNING 'Road too short for number range % to % on %, % (%)',startnumber,endnumber,in_street,in_isin,
51 ST_length(linegeo)/(numberrange::float/stepsize::float);
55 place_centroid := ST_Centroid(linegeo);
56 out_partition := get_partition('us');
57 out_parent_place_id := null;
59 address_street_word_ids := word_ids_from_name(in_street);
60 IF address_street_word_ids IS NOT NULL THEN
61 out_parent_place_id := getNearestNamedRoadPlaceId(out_partition, place_centroid,
62 address_street_word_ids);
65 IF out_parent_place_id IS NULL THEN
66 FOR location IN SELECT place_id FROM getNearestParellelRoadFeature(out_partition, linegeo) LOOP
67 out_parent_place_id := location.place_id;
71 IF out_parent_place_id IS NULL THEN
72 FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP
73 out_parent_place_id := location.place_id;
77 --insert street(line) into import table
78 insert into location_property_tiger_import (linegeo, place_id, partition, parent_place_id, startnumber, endnumber, interpolationtype, postcode)
79 values (linegeo, nextval('seq_place'), out_partition, out_parent_place_id, startnumber, endnumber, interpolationtype, in_postcode);