0

I am trying to convert a binary raster to polyline using r.to.vect in QGIS 3.4.

It keeps giving me an empty output, however. This is my input raster:

enter image description here

And I am expecting an output (more or less) like this:

enter image description here

All of my attempts result in an empty polyline layer, however, with this in the logs:

Processing algorithm…
Algorithm 'r.to.vect' starting…
Input parameters:
{ '-b' : False, '-s' : False, '-t' : False, '-v' : True, '-z' : False, 'GRASS_OUTPUT_TYPE_PARAMETER' : 2, 'GRASS_REGION_CELLSIZE_PARAMETER' : 0, 'GRASS_REGION_PARAMETER' : None, 'GRASS_VECTOR_DSCO' : '', 'GRASS_VECTOR_EXPORT_NOCAT' : False, 'GRASS_VECTOR_LCO' : '', 'column' : 'value', 'input' : '/home/isaac/raster_to_line/dummy_img.tiff', 'output' : '/tmp/processing_f785fcf97bd74b71ae07fd43d69b03cc/984b737cf59b428380ad5d6b4a2ec9c3/output.gpkg', 'type' : 0 }

g.proj -c proj4="+proj=longlat +datum=WGS84 +no_defs"
r.external input="/home/isaac/raster_to_line/dummy_img.tiff" band=1 output="rast_5d4331d87fa689" --overwrite -o
g.region n=0.0 s=-5.0 e=5.0 w=0.0 res=1.0
r.to.vect input=rast_5d4331d87fa689 type="line" column="value" -v output=outpute51df7d2d5ef43198c5d492a6ac8df29 --overwrite
v.out.ogr type="line" input="outpute51df7d2d5ef43198c5d492a6ac8df29" output="/tmp/processing_f785fcf97bd74b71ae07fd43d69b03cc/984b737cf59b428380ad5d6b4a2ec9c3/output.gpkg" format="GPKG" --overwrite
Starting GRASS GIS...
Executing </tmp/processing_f785fcf97bd74b71ae07fd43d69b03cc/grassdata/grass_batch_job.sh> ...
Default region was updated to the new projection, but if you have multiple mapsets `g.region -d` should be run in each to update the region from the default
Projection information updated
No projection information available
Over-riding projection check
Reading band 1 of 1...
Link to raster map <rast_5d4331d87fa689> created.
WARNING: Raster is not CELL, '-v' flag ignored, raster values will be written to the table.
Extracting lines...
20..40..60..80..100
120..Building topology for vector map <outpute51df7d2d5ef43198c5d492a6ac8df29@PERMANENT>...
Registering primitives...
r.to.vect complete.
WARNING: No lines found, but requested to be exported. Will skip this feature type.
Exporting 0 features...
WARNING: Output layer is empty, no features written
v.out.ogr complete. 0 features (Line String type) written to <outpute51df7d2d5ef43198c5d492a6ac8df29> (GPKG format).
Execution of </tmp/processing_f785fcf97bd74b71ae07fd43d69b03cc/grassdata/grass_batch_job.sh> finished.
Cleaning up default sqlite database ...
Cleaning up temporary files...
Execution completed in 0.61 seconds
Results:
{'output': <QgsProcessingOutputLayerDefinition {'sink':/tmp/processing_f785fcf97bd74b71ae07fd43d69b03cc/984b737cf59b428380ad5d6b4a2ec9c3/output.gpkg, 'createOptions': {'fileEncoding': 'System'}}>}

Loading resulting layers
Algorithm 'r.to.vect' finished

I think that this is the culprit:

WARNING: Raster is not CELL, '-v' flag ignored, raster values will be written to the table.

But what does this mean? I have indicated in the tool dialog that it should "Use raster values as categories", which is what the -v flag is supposed to do, but because the raster is "not CELL" it gets ignored. The docs don't seem to say anything about what makes it "CELL".

Can anybody shed some light on this?

This is a screenshot of my inputs:

Part 1:

enter image description here

Part 2:

enter image description here

0

I found the solution myself eventually. I did the following things, although it is possible that some of them actually had no effect, but I am writing them all anyway in case they are indeed important:

  1. I changed the image from a geographic CRS to a projected CRS. I doubt this did anything to change it but I know sometimes some algorithms don't play nice with geographic CRS

  2. I changed the datatype to an Integer (Int32, specifically, but any Integer should work), because the algorithm wanted to have discrete value codes and not messy floating point values.

  3. In the image I posted, the black areas were equal to 0 and the yellow areas were equal to 1. This was causing the algorithm to break down because it didn't know how to process big blocks of areas it thought were labeled as "class 0". I replaced the 0 values with NoData.

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.