Clipping images
Very rarely is an analyst interested in an entire satellite scene, which can easily cover hundreds of square miles. And given the size of satellite data we are highly motivated to reduce the size of an image to only our area of interest. The best way to accomplish this reduction is to clip an image to a boundary which defines our study area. We can use shapefiles (or other vector data) as our boundary definition and basically get rid of all the data outside that boundary. The following image contains our stretched.tif
image with a county boundary file layered on top, visualized in Quantum GIS (QGIS):
In order to clip the image, our next example executes the following steps:
Load the image into an array using
gdalnumeric
.Create a
shapefile
reader usingPyShp
.Rasterize the
shapefile
into a georeferenced image.Turn the
shapefile
image into a binary mask.Filter the satellite image through the mask.
Discard satellite image data outside the mask.
Save the clipped satellite image as...