Changes between Version 9 and Version 10 of FAQRaster
- Timestamp:
- Jun 6, 2008, 4:48:50 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
FAQRaster
v9 v10 29 29 Examples 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]. 30 30 31 However, 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 31 36 == How do I use gdal_translate to extract or clip a sub-section of a raster? == 32 37 33 38 Gdal_translate is designed to convert to and from a variety of raster formats, but it can also perform helpful geoprocessing operations during conversion. 34 39 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]) 40 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. 36 41 37 Here is an example of using gdal_translate on NAIP orthophotography in sid format to select a small subwindow that shows ofBlakely Island, WA:42 Here is an example of using gdal_translate on NAIP orthophotography in sid format to select a small subwindow that shows Blakely Island, WA: 38 43 {{{ 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.tif44 $ gdal_translate -projwin 510286 5385025 518708 5373405 ortho_1-1_1n_s_wa055_2006_1.sid naip_ortho_blakely_island.tif 40 45 }}} 41 46 42 47 This 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. 43 48 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. 49 Note: 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 45 51 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: 55 Extent: (268596, 5362330) - (278396, 5376592) 56 # which is (xMin,yMin) - (xMax,yMax) 57 }}} 58 Then 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 .