6

I'm currently working with gdalwarp to split some tiffs.

gdalwarp -cutline file.shp -dstalpha -of GTiff image.tif split_image.tif

I wanted to know if I can use an other source rather than use a shapefile, for example I'd like to use a WKT entry, something like POLYGON ((0 0, 0 1, 1 1 , 1 0, 0 0))

2 Answers2

7

It should be possible by using the -csql parameter http://www.gdal.org/gdalwarp.html and SQLite dialect http://www.gdal.org/ogr_sql_sqlite.html. Gdalwarp does not have an option for selecting the SQL dialect so you must help it by using some SpatiaLite database as a fake source for the cutline. GDAL selects automatically SQLite dialect when it reads SpatiaLite. The database must exist but it does not matter what it contains.

gdalwarp  -cutline foo.sqlite -csql "select ST_GeomFromText('POLYGON ((
0 0, 0 1, 1 1 , 1 0, 0 0))')" -dstalpha -of GTiff image.tif split_image.tif

BTW. your polygon was invalid because it was not closed. Using .csv file as source for cutline is straight forward as well.

user30184
  • 65,331
  • 4
  • 65
  • 118
  • that seems great even if we need to create an sqlite database You also need to create a table to be able to use that databas. Thanks – Geek Junior Dec 20 '17 at 16:04
4

Welcome to GIS StackExchange. Have you looked at the gdalwarp help page here http://www.gdal.org/gdalwarp.html? I think there's an example for GDAL > 2.2 combining different ways to cut/clip using extents and a csv file containing a WKT description.

cm1
  • 2,280
  • 14
  • 26