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.
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.

rasterio.featuresdid you try vectorizing the white pixels as opposed to the blue ones? – mikewatt Feb 13 '19 at 16:54{}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