1

I'm using the following command to cut a GeoPackage from a GeoTIFF file:

gdalwarp -of GTiff -cutline input_database.gpkg -crop_to_cutline input_raster.tif output_raster.tif

Additionally, I know I can use -csql for making queries inside my GeoPackage database:

gdalwarp -of GTiff -cutline input_database.gpkg -csql "select geom from database" -crop_to_cutline input_raster.tif output_raster.tif

However, if I try to use any spatial function inside this query (like the st_buffer() function):

gdalwarp -of GTiff -cutline input_database.gpkg -csql "select st_buffer(geom,5) from database" -crop_to_cutline input_raster.tif output_raster.tif

I receive the error ERROR 1: Failed to identify source layer from datasource. While opening the GeoPackage with Spatialite, I can make this query work with this solution. One of them is adding the function GeomFromGPB() on my geometries, but I've tested the last command with it and it didn't work as well. What am I missing? How can I use spatial functions on GeoPackages while using gdalwarp to cut the new geometry from a GeoTIFF file?

3

1 Answer 1

1

As stated in the comments, this can be done in two lines. Using first ogr2ogr and then gdalwarp:

ogr2ogr -f GPKG -sql "select st_buffer(geom,5) from database"  bufferedOutput.gpkg input.gpkg
gdalwarp -of GTiff -cutline bufferedOutput.gpkg -crop_to_cutline input_raster.tif output_raster.tif

This is a functional solution. However, I didn't manage to use a query with gdalwarp where I can use spatial functions with the -csql parameter.

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.