I have a need to take all the streets belonging to a certain area (in OpenStreetMap) and split each street by each other and form polygons from the segments that result from the split operation. I do not know whether such a function exists in the GIS tools that are available or if the algorithm needs to be written.
If I should write the algorithm, what would be a good way to approach the problem?
If the street network looks like below, polygons like given in red needs to be created (only as an example, in fact all the intersections between streets should produce polygons like these)
Answer
There is ST_Node
& ST_Polygonize
, which should do what you need:
SELECT (ST_Dump(ST_Polygonize(ST_Node(multi_geom)))).geom
FROM (
SELECT ST_Collect() AS multi_geom
FROM
-- WHERE
-- GROUP BY
) q
;
You might want to use a filter and/or grouping attribute to put a limit on the amount of edges to process.
There's no guarantee ST_Polygonize
will create all polygons you want, or leaves out those you don't expect, so validate the result.
No comments:
Post a Comment