[Gdal-dev] Re: gdal_translate with polygon clip option

Quentin S. quickstuff at altern.org
Tue Feb 20 10:05:26 EST 2007


Hi,

you can achieve this with the various utilities from GDAL and OGR.
It would involve many steps though - let's summarize them briefly:

1/ Create your polygon in some vector format. You can even create it by 
hand in GML or some other simple text format.
2/ With gdal_translate, create an exact duplicate of the raster to crop 
*but* scaling down its values to a unique "opaque" value (e.g. to zero 
with parameters such as "-scale 0 255 0 0.01")
3/ 'Burn' the vector polygon in your newly-created black raster with 
gdal_rasterize, setting the burnt value for this polygon to 255 for 
instance. With this step, you now have some kind of a raster mask to 
apply on top of your original image.
4/ Combine the mask with the original raster using gdalwarp, defining 
what value of your mask you want to be transparent (=nodata). To stick 
with my example: "gdalwarp mask.tif -srcnodata "255" originalraster.tif".

Sure, there must be simpler ways involving some python scripting etc. 
Moreover you could save some time and disk space by first identifying 
the bounding box for your polygon (with ogrinfo), then processing only 
this limited part of the rasters thanks to the -projwin argument.

Hope this helps,

Quentin S.


SriRam Prasad Bhasker wrote:
> 
> Hi.
> 
> Using Gdal_translate we can clip an Image with the below options (in a 
> rectangle)
>         [-srcwin xoff yoff xsize ysize] [-projwin ulx uly lrx lry]
> 
> Is there any option by which we can clip an Image Irregularly .. Thru a 
> Set of Points that form a closed Polygon ????
> Images will be rectangular anyway.. If we can fill the Outer regions of 
> Polygon with Nodata value.. this will be of great help.
> 
> 
> cheers
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev




More information about the Gdal-dev mailing list