- IF interpolationtype = 'odd' OR interpolationtype = 'even' THEN
- stepsize := 2;
- ELSEIF interpolationtype = 'all' THEN
- stepsize := 1;
- ELSEIF interpolationtype ~ '^\d+$' THEN
- stepsize := interpolationtype::INTEGER;
- ELSE
- RETURN 0;
- END IF;
-
- select nodes from planet_osm_ways where id = wayid INTO waynodes;
-
- IF array_upper(waynodes, 1) IS NULL THEN
- RETURN 0;
- END IF;
-
- linegeo := geom;
- 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 * 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 nextnode;
- IF nextnode.place_id IS NOT NULL THEN
-
- 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 place_id != prevnode.place_id;
- FOR housenum IN startnumber..endnumber BY stepsize LOOP
- insert into placex (place_id, partition, osm_type, osm_id,
- class, type, admin_level, housenumber,
- postcode,
- country_code, parent_place_id, rank_address, rank_search,
- indexed_status, indexed_date, geometry_sector,
- geometry)
- values (nextval('seq_place'), partition, 'N', prevnode.osm_id,
- 'place', 'address', prevnode.admin_level, housenum,
- coalesce(prevnode.postcode, defpostalcode),
- prevnode.country_code, parent_place_id, 30, 30,
- 0, now(), geometry_sector, calculated_country_code,
- ST_LineInterpolatePoint(sectiongeo, (housenum::float-orginalstartnumber::float)/originalnumberrange::float));
- newpoints := newpoints + 1;
---RAISE WARNING 'interpolation number % % ',prevnode.place_id,housenum;
- END LOOP;
- END IF;