QGIS – How to Clip/Mask a Satellite Photo to a Polygon

clipopenlayers-2qgissatellite

Given a shapefile composed of contiguous polygons, I'd like to clip (or mask) regions of satellite photo to the polygon outlines, and export each resulting raster in medium resolution for further processing.

I've gotten as far as overlaying the shapefile on Google Maps imagery (in QGIS, with Openlayers plugin), but I can't find any operation to intersect vector data with raster data (presuming that the Openlayers layer is indeed treated as a raster layer).

A simple solution would be great, and suggestions of other free OSX-compatible software are fine. A programmatic solution would be ideal (though not requisite) as I'd like to export many such images, each named by an attribute field in the shapefile.

I hope I haven't over-explained a simple problem, but alas, I'm rather new to GIS software. Trying to move forward with this project as quickly as possible, but stymied by data acquisition… Thanks a ton!

Best Answer

In QGIS, use the Clipper raster tool, under the Raster-> Extraction menu. See: Clipping raster with vector boundaries using QGIS?

enter image description here

You may have issues trying to clip data in a plugin layer (e.g. Openlayers) because the Clipper function requires a input graphic file (raster) from disk. Your best bet is to get the satellite imagery directly from the source and load that into QGIS.

Check here for most from Landsat missions:
USGS Global Visualization Viewer

Once you get it working in QGIS, delve into the gdalwarp utility (see code generated at bottom of Clipper dialog) to see about scripting your clippings (via bash or Python).

If you have installed QGIS using the KyngChaos.com frameworks, then gdal and its utility programs are located in:

/Library/Frameworks/GDAL.framework/Versions/1.9/Programs

Read the README included with the KyngChaos.com installers to see about updating your bash (Terminal) PATH environment variable.

EDIT: In your scripting you will need to loop through the features of your shapefile (used here as a cutline) and spatially match it up to the appropriate imagery. Alternatively, if it is a one-off project, you can export features to separate shapefiles using the Split vector layer tool, located under the Vector-> Data Management Tools menu. It may make your life easier when learning to make your first batch scripts.

enter image description here

Related Question