2

Just like the title, I am extracting OSM riverbank and a lot of riverbanks in OSM is in 'unclosed' linestring.

This is the original river shape i extracted from OSM enter image description here

In order to polygonize the linestring, I tried to use ST_MakePolygon (or Polygonize); yet, it says the linestrings are not closed and it cannot make polygons in some areas.

select st_makepolygon(st_makevalid(shape)) as shape from asia_waterway_line where waterway ='riverbank'
and st_isclosed(shape)

enter image description here

However, I just ran with QGIS Polygonize tool in vector tool and it gives me a polygon that I want to make.

enter image description here

Polygonize of GRASS, SAGA brought me weird polygon (I'm just giving you other trials that I tried)

Because all my data are stored in postgresql, I really do want to make them working using PostGIS Spatial Query. I tried with someone's ST_ForceClosed function but it didn't work either. Is there any ways that I can solve this issue?

I extraxcted waterway using osmosis tag info and imported them using ogr2ogr.

  • From the GRASS output, it looks like the river is made of two lines (well, more than that, but most importantly more than 1 line running around both sides of the river). You could try unioning all the lines of a river, then transforming this one line into a polygon. – JGH Jul 12 at 12:39
  • I tried that. Unioning (dissolving) all the lines and convert them to Polygon. the results remained same. – Pil Kwon Jul 13 at 11:48
2

Try enforcing closed LineStrings by adding their ST_StartPoint to the end of the them:

SELECT ST_MakePolygon( ST_MakeValid( ST_AddPoint( shape. ST_StartPoint( shape ) ) ) ) AS shape
FROM   asia_waterway_line
WHERE  waterway ='riverbank'
;

If you want to make sure you are not duplicating points for when a LineString is already closed, run:

SELECT ST_MakePolygon( ST_MakeValid( ST_AddPoint( shape. ST_StartPoint( shape ) ) ) ) AS shape
FROM   asia_waterway_line
WHERE  waterway ='riverbank'
  AND  NOT ST_IsClosed(shape)
UNION ALL
SELECT ST_MakePolygon( ST_MakeValid( shape ) ) AS shape
FROM   asia_waterway_line
WHERE  waterway ='riverbank'
  AND  ST_IsClosed(shape)
;

I guess that custom ST_ForceClosed function ought to be doing the same, though?

  • 1
    It won't have the desired effect if each side of the river has its own line – JGH Jul 12 at 12:42
  • @JGH definetely good to mention that. sounds like OP has a single LineString, though, or the question needs clarification. the multiple lines case is sth. else entirely... – ThingumaBob Jul 12 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.