[gdal-dev] crop a non-square subwindow?

Marius Jigmond mariusjigmond at hotmail.com
Wed Mar 9 19:05:20 EST 2011



On Wed, 2011-03-09 at 12:35 -0500, Frank Warmerdam wrote: 
> On 11-03-09 11:51 AM, Wendell Turner wrote:
> >
> > Do any of the gdal utilities crop an image on non-square
> > boundaries?
> >
> > I use gdal_translate with -projwin ulx uly lrx lry to crop
> > an image that is square (left and right edges are vertical,
> > and the top and bottom edges are horizontal).  Is there a
> > command that will crop other shapes, for instance a diamond
> > shape, where the edges are not horizontal/vertical?
> >
> > If it must be done by programming (pref. Python), is there a
> > sample that I could use to start with?
> 
> Wendell,
> 
> I think gdalwarp with -crop_to_cutline and a cutline specified
> with the shape will accomplish what you want.
> 
>    http://www.gdal.org/gdalwarp.html
> 
> The cutline comes from an OGR supported file but this can be as simple
> as a .csv file with a WKT geometry in it.   The -crop_to_cutline may be
> new to 1.8.
> 
> Best regards,

Wendell,

Please be aware that this method may introduce raster shifting and
possibly resampling (depending on the original cell size). It might or
might not matter for your purposes. A better approach is to use
gdal_translate with -projwin to extract to shape envelope and then
gdal_rasterize with -i to burn nodata where shape is missing.

-marius



More information about the gdal-dev mailing list