#!/bin/sh
############################################################################
#                          clip_raster.sh                                  #
#                          Copyright (C) 2012, Gary Sherman                #
# Clip a GRASS raster using a vector layer and mask                        #
#                                                                          #
############################################################################

# import the DRG
r.in.GDAL input=i61149e3_albers.tif output=ancc7_collars
# Extract the quad boundary from the boundary map
v.extract input=itma output=ancc7 where="TILE_NAME=’ANCC7’"
# Set the region to that extracted vector
g.region vect=ancc7
# Convert the extracted vector quad feature to a raster map
v.to.rast input=ancc7 output=ancc7_itma use=val
# Set the region to operate on to that of our DRG
g.region rast=ancc7_collars
# Set the mask for the operation to the raster created from the
# quad boundary vector
g.copy ancc7_itma,MASK
# Use map algebra to create the "clipped" raster
r.mapcalc ancc7=ancc7_collars
# Delete the mask
g.remove MASK
