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

Wendell Turner wendell at enflight.com
Thu Mar 10 17:07:10 EST 2011


On Wed, Mar 09, 2011 at 06:05:20PM -0600, Marius Jigmond wrote:
> 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 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.
> 
> 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 & Frank,

The -crop_to_cutline worked as advertised, and I didn't
notice any shifting or resampling.

However, it seemed to place the cropped image into a larger
bounding box and the pixels that are outside the cropping
shapefile are black, not transparent.  The gdal_rasterize
with -i looks interesting, but my input is raster, not
vector, and gdal_rasterize doesn't seem to like that.

Is there a way to force pixels outside of the cropping
polygon to be 'not there', or transparent?  Is there a burn
value that indicates that?

Wendell



More information about the gdal-dev mailing list