- startnumber := NULL;
- newpoints := 0;
-
- FOR nodeidpos in 1..array_upper(waynodes, 1) LOOP
-
- -- If there is a place of a type other than place/house, use that because
- -- it is guaranteed to be the original node. For place/house types use the
- -- one with the smallest id because the original node was created first.
- -- Ignore all nodes marked for deletion. (Might happen when the type changes.)
- select place_id from placex where osm_type = 'N' and osm_id = waynodes[nodeidpos]::BIGINT and indexed_status < 100 order by (type = 'house'),place_id limit 1 INTO search_place_id;
- IF search_place_id IS NOT NULL THEN
- select * from placex where place_id = search_place_id INTO nextnode;
-
- IF nodeidpos > 1 and nodeidpos < array_upper(waynodes, 1) THEN
- -- Make sure that the point is actually on the line. That might
- -- be a bit paranoid but ensures that the algorithm still works
- -- should osm2pgsql attempt to repair geometries.
- splitline := split_line_on_node(linegeo, nextnode.geometry);
- sectiongeo := ST_GeometryN(splitline, 1);
- linegeo := ST_GeometryN(splitline, 2);
- ELSE
- sectiongeo = linegeo;
- END IF;
- endnumber := substring(nextnode.housenumber,'[0-9]+')::integer;
-
- IF startnumber IS NOT NULL AND endnumber IS NOT NULL
- AND @(startnumber - endnumber) < 1000 AND startnumber != endnumber
- AND ST_GeometryType(sectiongeo) = 'ST_LineString' THEN
-
- IF (startnumber > endnumber) THEN
- housenum := endnumber;
- endnumber := startnumber;
- startnumber := housenum;
- sectiongeo := ST_Reverse(sectiongeo);
- END IF;
- orginalstartnumber := startnumber;
- originalnumberrange := endnumber - startnumber;
-
- startnumber := startnumber + stepsize;
- -- correct for odd/even
- IF (interpolationtype = 'odd' AND startnumber%2 = 0) OR (interpolationtype = 'even' AND startnumber%2 = 1) THEN
- startnumber := startnumber - 1;
- END IF;
- endnumber := endnumber - 1;
-
- delete from placex where osm_type = 'N' and osm_id = prevnode.osm_id and type = 'house' and place_id != prevnode.place_id;
- FOR housenum IN startnumber..endnumber BY stepsize LOOP
- -- this should really copy postcodes but it puts a huge burden on
- -- the system for no big benefit ideally postcodes should move up to the way
- insert into placex (osm_type, osm_id, class, type, admin_level,
- housenumber, street, addr_place, isin, postcode,
- country_code, parent_place_id, rank_address, rank_search,
- indexed_status, geometry)
- values ('N', prevnode.osm_id, 'place', 'house', prevnode.admin_level,
- housenum, prevnode.street, prevnode.addr_place, prevnode.isin, coalesce(prevnode.postcode, defpostalcode),
- prevnode.country_code, prevnode.parent_place_id, prevnode.rank_address, prevnode.rank_search,
- 1, ST_LineInterpolatePoint(sectiongeo, (housenum::float-orginalstartnumber::float)/originalnumberrange::float));
- newpoints := newpoints + 1;
---RAISE WARNING 'interpolation number % % ',prevnode.place_id,housenum;
- END LOOP;
- END IF;
-
- -- early break if we are out of line string,
- -- might happen when a line string loops back on itself
- IF ST_GeometryType(linegeo) != 'ST_LineString' THEN
- RETURN newpoints;
- END IF;
-
- startnumber := substring(nextnode.housenumber,'[0-9]+')::integer;
- prevnode := nextnode;
- END IF;
- END LOOP;
-
---RAISE WARNING 'interpolation points % ',newpoints;
-
- RETURN newpoints;