2

I have a .png file coming from a WMS service (WFS is not available). It only contains "straight" lines and I would like to extract the geometries (shapely polygons) of the connected components of objects in the image.

enter image description here

I tried some basic solutions like using shapes from rasterio.features but the results were bad. There are 35 polygons in this image (if you pad the borders) and I either got thousands or a dozen. The polygons do not need to be perfectly aligned with the lines but I couldn't get even close to a working solution.

I consulted a solution to a similar problem (How to polygonize raster to shapely polygons) but it did not work well here.

I also tried finding contours and lines using various OpenCV methods but I still wasn't satisfied with the outcome. It seems like a pretty straightforward task but I can't find any working solution.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
robert
  • 21
  • 1
  • 1
    When using rasterio.features did you try vectorizing the white pixels as opposed to the blue ones? – mikewatt Feb 13 '19 at 16:54
  • Welcome to GIS SE! We're a little different from other sites. We're a Q&A site, not a discussion forum. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an [edit] button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. Please check out our short [tour] for more about how the site works. Thanks. – PolyGeo Feb 14 '19 at 01:24

0 Answers0