[gdal-dev] Re: Cropping raster by vector files

jorgepsantos2002 jorgepsantos2002 at gmail.com
Mon Jan 24 05:08:04 EST 2011


Hi,

Another option is make a subset by mask with GDAL using three algorithms:
gdal_translate, gdal_rasterize and gdalwarp.

1 - Original Full Raster + ROI in shapefile format:

http://osgeo-org.1803224.n2.nabble.com/file/n5954709/ftolls0.png 

2 - Generate a Raster Black with gdal translate:

In Ftools prompt, past a code below to generate a black raster (replace de
subdirectories):

gdal_translate D:\GDAL\LS5_20100208_216_075_RGB.tif D:\GDAL\LS_SCALE.tif
-scale 0 255 0 0.01

http://osgeo-org.1803224.n2.nabble.com/file/n5954709/ftools4.png 

* LS5_20100208_216_075_RGB.tif is the original raster.
* LS_SCALE.tif is the name I gave to the opaque raster.

3 - Create a Raster Mask with gdal_rasterize:

Paste new commandline in Ftools prompt:

gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 255 -burn 255 -l VETOR_SHP
D:/GDAL/VETOR_SHP.shp D:/GDAL/LS_SCALE.tif

http://osgeo-org.1803224.n2.nabble.com/file/n5954709/ftools2.png 

4 - Finally, generate the image subset with gdalwarp:

gdalwarp D:/GDAL/LS_SCALE.tif -srcnodata "255"
D:\GDAL\LS5_20100208_216_075_RGB.tif

http://osgeo-org.1803224.n2.nabble.com/file/n5954709/ftools3.png 

The NoDATA value is zero. Since the algorithm gdalwarp not generate a third
image, you must delete any .AUX and .RRD files after unning this command.
This prevents the GIS (ArcGIS, Quantum GIS, etc) remains continuously
displaying the entire image in the editing area.

Full article in my blog Processamento Digital:

http://processamentodigital.blogspot.com/2011/01/recorte-irregular-em-arquivos-raster.html 
http://processamentodigital.blogspot.com/2011/01/recorte-irregular-em-arquivos-raster.html 

Regards,

_________________
Jorge Santos
Téc. em Geodésia e Cartografia
http://processamentodigital.blogspot.com/
http://processamentodigital.blogspot.com/ 
http://twitter.com/jpsantos2002 http://twitter.com/jpsantos2002 
Skype: jorgepsantos2002

-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Cropping-raster-by-vector-files-tp5271977p5954709.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list