Changes between Version 9 and Version 10 of FAQRaster


Ignore:
Timestamp:
Jun 6, 2008, 4:48:50 PM (16 years ago)
Author:
springmeyer
Comment:

Added further examples to gdal_rasterize and clipping with gdal_translate examples

Legend:

Unmodified
Added
Removed
Modified
  • FAQRaster

    v9 v10  
    2929Examples of other tools: [http://www.osgeo.org/qgis/ Quantum GIS], [http://www.osgeo.org/grass/ GRASS], [http://www.osgeo.org/mapserver/ MapServer], [http://gmt.soest.hawaii.edu/ GMT], [http://www.saga-gis.uni-goettingen.de/ SAGA GIS].
    3030
     31However, if your raster format supports transparency in the Alpha band (RGBA), then you can use gdal_rasterize to burn in fully transparent areas into your image like :
     32{{{
     33$ gdal_rasterize -b 4 -burn 0 -where your_field=some_value -l your_layer your_vector_file.shp your_raster
     34}}}
     35
    3136== How do I use gdal_translate to extract or clip a sub-section of a raster? ==
    3237
    3338Gdal_translate is designed to convert to and from a variety of raster formats, but it can also perform helpful geoprocessing operations during conversion.
    3439
    35 For example, if you would like to extract a sub-section of a raster you can use the -srcwin or -projwin options. In gdal terminology these are "subsetting" operations that allow you to select a "subwindow" to copy from the source dataset into the destination dataset. Currently, clipping raster images using vector extent polygons is not supported but is under discussion (see [http://trac.osgeo.org/gdal/ticket/1599])
     40If you would like to extract a sub-section of a raster you can use the -srcwin or -projwin options. In gdal terminology these are "subsetting" operations that allow you to select a "subwindow" to copy from the source dataset into the destination dataset.
    3641
    37 Here is an example of using gdal_translate on NAIP orthophotography in sid format to select a small subwindow that shows of Blakely Island, WA:
     42Here is an example of using gdal_translate on NAIP orthophotography in sid format to select a small subwindow that shows Blakely Island, WA:
    3843{{{
    39 gdal_translate -of GTiff -co TFW=YES -co INTERLEAVE=BAND -projwin 510286 5385025 518708 5373405 ortho_1-1_1n_s_wa055_2006_1.sid naip_ortho_blakely_island.tif
     44$ gdal_translate -projwin 510286 5385025 518708 5373405 ortho_1-1_1n_s_wa055_2006_1.sid naip_ortho_blakely_island.tif
    4045}}}
    4146
    4247This example uses the -projwin option which accepts the bounding coordinates in the projected coordinates rather than in pixels (-srcwin).  Gdal_translate -projwin needs the upper left x coordinate, the upper left y coordinate, the lower right x coordinate, and the lower right y coordinate. The naip imagery in this example is in NAD 83 Utm 10, so to get these bounding coordinates I simply loaded up the index shapefile that comes packaged with naip imagery in Quantum GIS and read the screen coordinates to form my extent.
    4348
    44 If you don't care what section you want to clip out but just want to preview a portion of the raster use gdalinfo to get the bounding/corner coordinates and select an arbitrary subset that fits within those extents.
     49Note: Currently, clipping raster images using vector extent polygons is not supported but is under discussion (see [http://trac.osgeo.org/gdal/ticket/1599]). However is is fairly easy to get the extents of a given shapefile and convert those coordinate pairs into the format needed by gdal_translate without manually reading the extents from another application like qgis. Say you have a shapefile named `clipping_mask.shp` use ogrinfo to get the extents:
     50 * note the use of the pipe and grep command is optional(`| grep Extent`), but is a slick way to limit the info reported by ogrinfo to just what you need in this case
    4551
    46 Also, this example uses the optional -co switch to use name=value tages for a given format. For Geotiff many are available [http://www.gdal.org/frmt_gtiff.html] and in this example allowed the generation of a world file and band interleaving.
     52{{{
     53$ ogrinfo clipping_mask.shp -so -al | grep Extent
     54# which gives the extent as xMin,yMin, xMax, yMax:
     55Extent: (268596, 5362330) - (278396, 5376592)
     56# which is (xMin,yMin) - (xMax,yMax)
     57}}}
     58Then copy and paste that text to create your gdal_translate clipping command:
     59{{{
     60# -projwin's ulx uly lrx lry is equivalent to xMin, yMax, xMax, yMin so just switch the Y coordinates
     61# For the above Extent that would turn into:
     62$ gdal_translate -projwin 268596 5376592 278396 5362330 src_dataset dst_dataset
     63}}}
     64
     65.