Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can not figure out how I directly can read a polygon into gdawarp's -cutline argument.

My current approach is:

ogr2ogr -f "ESRI Shapefile" mydata.shp PG:"user=myuser dbname=gisdb" -sql "select * from polys where id='12345'"
and then I run

gdalwarp -cutline mydata.shp in.tif out.tif

How could I skip the step with the shapefile?

Thanks in advance for any hints

share|improve this question
I don't see any option "-cut_to_line" in the manual:, is it "-crop_to_cutline" instead? – Pablo May 11 '11 at 16:06
Thanks for noticing, I used "-cutline" – rengis May 11 '11 at 16:19
up vote 8 down vote accepted

If you're using GDAL 1.8.0 (which I recommend because it adds a number of useful features), you can use:

gdalwarp -cutline "PG:dbname=gisdb" -csql 'select * from polytest where id=1' -crop_to_cutline -of GTiff -srcnodata -9999 -dstnodata -9999 src.tif dest.tif

Note the "-crop_to_cutline" parameter.

With gdalwarp, I have found it always pays to use -srcnodata and -dstnodata explicitly, otherwise it'll fill the nodata areas with 0/black which quite often is a valid value.

share|improve this answer
Thanks, exactly what I was looking for – rengis May 11 '11 at 17:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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