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 rangestartnumber INTEGER;
14 place_centroid GEOMETRY;
15 out_partition INTEGER;
16 out_parent_place_id BIGINT;
18 address_street_word_id INTEGER;
22 IF in_endnumber > in_startnumber THEN
23 startnumber = in_startnumber;
24 endnumber = in_endnumber;
26 startnumber = in_endnumber;
27 endnumber = in_startnumber;
30 numberrange := endnumber - startnumber;
31 rangestartnumber := startnumber;
33 IF (interpolationtype = 'odd' AND startnumber%2 = 0) OR (interpolationtype = 'even' AND startnumber%2 = 1) THEN
34 startnumber := startnumber + 1;
37 IF (interpolationtype = 'odd' OR interpolationtype = 'even') THEN
39 ELSE -- everything else assumed to be 'all'
44 -- Filter out really broken tiger data
45 IF numberrange > 0 AND (numberrange::float/stepsize::float > 500)
46 AND ST_length(linegeo)/(numberrange::float/stepsize::float) < 0.000001 THEN
47 RAISE WARNING 'Road too short for number range % to % on %, % (%)',startnumber,endnumber,in_street,in_isin,
48 ST_length(linegeo)/(numberrange::float/stepsize::float);
52 place_centroid := ST_Centroid(linegeo);
53 out_partition := get_partition('us');
54 out_parent_place_id := null;
56 address_street_word_id := get_name_id(make_standard_name(in_street));
57 IF address_street_word_id IS NOT NULL THEN
58 FOR location IN SELECT * from getNearestNamedRoadFeature(out_partition, place_centroid, ARRAY[address_street_word_id]) LOOP
59 out_parent_place_id := location.place_id;
63 IF out_parent_place_id IS NULL THEN
64 FOR location IN SELECT place_id FROM getNearestParellelRoadFeature(out_partition, linegeo) LOOP
65 out_parent_place_id := location.place_id;
69 IF out_parent_place_id IS NULL THEN
70 FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP
71 out_parent_place_id := location.place_id;
75 --insert street(line) into import table
76 insert into location_property_tiger_import (linegeo, place_id, partition, parent_place_id, startnumber, endnumber, interpolationtype, postcode)
77 values (linegeo, nextval('seq_place'), out_partition, out_parent_place_id, startnumber, endnumber, interpolationtype, in_postcode);