I have installed GDAL using the Osgeo installer. How can I clip a raster layer with a vector layer programmatically? Is there any GDAL API available which can help me with this? I am using Python.
[GIS] Clipping raster with vector layer using GDAL
gdalpython
Related Question
- [GIS] How to convert float raster to vector with python GDAL
- [GIS] Vector to Raster using GDAL (gdal.RasterizeLayer) : Error in Output Raster(generating output raster with NAN values)
- [GIS] using GDAL installed using homebrew from python on OSX
- GDAL – How to Clip Polygon Precisely to Raster Extent Using GDAL
- Python Vector Clipping – How to Clip a Vector Layer with Another Vector Layer Using Python
Best Answer
I'm not sure about the gdal api, there is
void* GDALWarpOptions::hCutline
in the Warp Options referenced from the Warp API tutorial, but no explicit examples. Are you sure you need a programmatic answer? The command line utilities can do it out of the box:ogrinfo
to determine the extent of the clipping shapefilegdal_translate
to clip to the shape extentsgdalwarp
with-cutline
parameterSteps 2 & 3 are for optimization, you could get by with just
gdalwarp -cutline ...
.See Clipping rasters with GDAL using polygons from Linfinity for linux based solution all wrapped up in one script. Another cutline example can be seen in Michael Corey's tutorial creating hillshades for Mapnik.