0

QGIS/GDAL environment: QGIS 3.8, gdal 2.4.0, macOS 10.14.6, python 3.6.5

I have successfully added a polygon ( as 2D and 25D objects ) to my project from CSV files using WKT format. With a corresponding .VRT file the CSV files seem to be parsed satisfactorily with ogrinfo. I have re-coded the polygon as a linestring & that also loads into the project.

My objective is to use the polygon as a mask layer to clip an area from a raster file, a TIF.

When I attempt to execute Raster/Extraction/Clip Raster by Mask Layer, the gdalwarp command that is constructed and submitted by QGIS fails. The error relates to the cutfile.

gdalwarp -of GTiff -tr 45.0 -45.0 -tap -cutline file://test_poly2.csv?type=csv&delimiter=%20%5Ct;&detectTypes=yes&wktField=Geom&crs=EPSG:32746&spatialIndex=no&subsetIndex=yes&watchFile=yes -crop_to_cutline si46_45m.tif OUTPUT.tif

For clarity above, I have removed the absolute paths to files. The error is:

/bin/sh: -c: line 0: syntax error near unexpected token `&'

I'm puzzled why the -cutline file is referred by the URI file: scheme.

Given that QGIS is simply composing a gdalwarp command I have tried to execute the gdalwarp, as composed by QGIS, in a bash shell (various attempts at escaping/quoting special characters): same failure.

I then exported the polygon, previously added as a delimited text layer, as a SHP file & added this SHP into the project. Executing the Raster/Extraction/Clip Raster by Mask Layer with the SHP polygon completes successfully, result as expected!

As I have many, many Raster/Extraction/Clip Raster by Mask Layer operations to perform I really need this to work in the shell (my source data is all CSV format).

So, with gdalwarp failing to process a CSV cutfile, I attempted to convert my WKT coded CSVs to SHP files.

ogr2ogr should accomplish that... no, the conversion fails to produce a recognisable SHP file.

I'm now stuck.

Has any other QGIS/gdal/ogr2ogr user successfully use clipped a TIF file with a WKT formatted CSV cutfile?

Or, successfully converted a WKT formatted CSV file into a SHP file?

Your Answer

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

Browse other questions tagged or ask your own question.