Cropping maps means taking the contents of one map (the source) and eliminating all data outside of the area you are studying (the boundary) to yield a smaller new map (the cropped map). Techniques differ depending on whether your source is raster or vector and whether your boundary is defined by another map or by coordinates. You especially might want to do this with vectors because GRASS operations always operate on the whole vector map, even features outside of the current region.
Vector source map and vector map as boundary. Use
Example: you have a map of roads of the USA and you want a map of only roads in California. Formerly the module v.cutter did this task; it has however been replaced byin GRASS release 6.
Vector source map and coordinates as boundary. Set region to desired coordinates (), create new vector from region extent to use as boundary using , then as above.
Otherwise, consider to Crop a shapefile during import.
Raster source map and vector map as boundary. Make boundary into mask usingthen use :
vector=boundary "cropped = raster_source" map=cropped rast=source # may be required to transfer the color table
The same procedure can be followed for a raster map as boundary. However, with a raster map one can easily just use r.mapcalc in one single go, without using a mask:
"cropped = if(boundary, raster_source)"
The size of the resulting cropped raster map will be the same as that of raster_source as this is defined by the computational region, but all cells outside the mask will be set to NULL. If you want to reduce the size of the raster map you can use, with the zoom parameter, and then r.mapcalc. Here an example with the North Carolina Demo dataset and a vector boundary:
rast=elev_state_500m -p vector=census_wake2000 zoom=elev_state_500m -p # will reduce the region to the non-null part of elev_state_500m, taking the mask into account "cropped = elev_state_500m" -r
Raster source map and vector boundary. Convert the vector to a raster mask (1 where inside, null elsewhere):
in=vector_boundary out=raster_boundary use=val value=1
Then proceed as above for two rasters.
Update for GRASS GIS 7
- Simply use which also supports vector maps nowadays.