I have a dump of OSM data in my city and wrote a query to polygonize it. In the first attempt, the result looked like this:
The problem was that OSM lines were not split and I guessed that the polygonizer only made polygons of entire linestrings:
^^ here, the green nodes are used for polygons, the blue ones are ignored, together with line 3.
Since st_split
supports slice by multiple points only in PostGIS 2.2, I decided to write a Python script to do this. Together with some SQL code, it splits lines into segments that respect intersections. Every road joining an intersection is unique.
The way I understand it now:
CREATE VIEW nodes AS
SELECT ROW_NUMBER() OVER () id, st_node(way) nd
FROM rd_sliced_roads;
DROP VIEW IF EXISTS pg;
CREATE VIEW pg AS
WITH
polygroup AS (SELECT ST_Polygonize(way) initial FROM nodes),
dumped AS (SELECT (st_dump(initial)).geom result FROM polygroup)
SELECT ROW_NUMBER() OVER () id, result
FROM dumped;
The result is still quite similar: polygons are ignored, even though lines join each other. Red lines are both source and st_nodified lines. Why does st_polygonize
ignore these small quarters?
What am I missing here?