3

I would like to convert all values having the value 1 in a binary raster to a line vector layer. The following image shows the binary raster (1=white and 0=black):

binary raster

The optimal output would look like the red lines in the following image (which I realized by modifying the GDAL script raster to vector line):

raster to lines

However, this is very slow and not applicable on large rasters. Is there a similar open-source implementation (callable in Python) that does the same with less processing time?

Would it decrease the processing time of the GDAL script raster to vector line when writing each single wkbLineString to a shapefile instead of adding them all to a wkbMultiLineString before writing them to a shapefile?

The only related posts I found so far are referring to polygonizing the raster (which I realized with GRASS GIS r.to.vect), which creates polygons and thus two lines, where I need only one:

raster to polygons

2
  • 2
    Hi Sophie. You asked a very similar question here which you could solve. What is the difference now? Are these lines really just one pixel wide or do you need to run r.thin?
    – pLumo
    Commented Apr 17, 2018 at 7:16
  • Hi @RoVo. Bascially now, I am looking for a more stable and faster solution. When I run those commands on my new data, r.mapcalculator does not produce any result, I didn't succeed yet in setting a nodata value with 'gdal_translate', so `r.thin' only produces one line of pixels. Also I am now asked to avoid GRASS modules. Converting a raster to a line vector seems such a 'normal' geoprocessing issue to me that I thought it might be worth asking if there is already something available. The white pixels are just one pixel wide, not sure if you mean that. Commented Apr 17, 2018 at 8:35

1 Answer 1

1

WhiteboxTools' RasterToVectorLines function might be what you're looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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