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_id 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 numberrange := endnumber - startnumber;
31 IF (interpolationtype = 'odd' AND startnumber%2 = 0) OR (interpolationtype = 'even' AND startnumber%2 = 1) THEN
32 startnumber := startnumber + 1;
35 IF (interpolationtype = 'odd' OR interpolationtype = 'even') THEN
37 ELSE -- everything else assumed to be 'all'
42 -- Filter out really broken tiger data
43 IF numberrange > 0 AND (numberrange::float/stepsize::float > 500)
44 AND ST_length(linegeo)/(numberrange::float/stepsize::float) < 0.000001 THEN
45 RAISE WARNING 'Road too short for number range % to % on %, % (%)',startnumber,endnumber,in_street,in_isin,
46 ST_length(linegeo)/(numberrange::float/stepsize::float);
50 place_centroid := ST_Centroid(linegeo);
51 out_partition := get_partition('us');
52 out_parent_place_id := null;
54 address_street_word_id := get_name_id(make_standard_name(in_street));
55 IF address_street_word_id IS NOT NULL THEN
56 FOR location IN SELECT * from getNearestNamedRoadFeature(out_partition, place_centroid, ARRAY[address_street_word_id]) LOOP
57 out_parent_place_id := location.place_id;
61 IF out_parent_place_id IS NULL THEN
62 FOR location IN SELECT place_id FROM getNearestParellelRoadFeature(out_partition, linegeo) LOOP
63 out_parent_place_id := location.place_id;
67 IF out_parent_place_id IS NULL THEN
68 FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP
69 out_parent_place_id := location.place_id;
73 --insert street(line) into import table
74 insert into location_property_tiger_import (linegeo, place_id, partition, parent_place_id, startnumber, endnumber, interpolationtype, postcode)
75 values (linegeo, nextval('seq_place'), out_partition, out_parent_place_id, startnumber, endnumber, interpolationtype, in_postcode);