Select to view content in your preferred language

Raster ExtractByMask with python

1840
13
06-29-2010 02:39 AM
bogdanpalade1
Deactivated User
Hello,

I am trying to clip a raster with a polygon shapefile.The shapefile contains several polygons representing administrative regions. The method is to temporarily export each polygon to a new shapefile and to extract the coresponding piece of raster.

The problem is that the output of

gp.ExtractByMask_sa(raster, shapefile, newRaster) 


is always just one band of the original RGB raster. Do you know how to extract all the 3 bands?

The original raster is .img

Thank you
0 Kudos
13 Replies
ChrisSnyder
Honored Contributor
Try naming your shapefile something else than a number (1.shp). Generally it is a bad idea to name a layer or field with a number as the 1st character.
0 Kudos
bogdanpalade1
Deactivated User
Tried changing the shapefile name but still the same error....
0 Kudos
ChrisSnyder
Honored Contributor
Not sure what's wrong... Take look at the sample code: http://forums.arcgis.com/threads/9512-Rectangle-for-Clip_management-tool-in-arcpy (my post Aug 2nd @10:25). 

Are you sure that your raster and shapefile are using the same projection?
0 Kudos
JamieWilliams
New Contributor
I had the same problem. I solved it by adding the full file path to the feature name.
eg. pathFeature = "R:\\folderContainingShpFile\\" + str(feature)

gp.clip_management(raster,"446716,298473 4425996,437405 499153,348855 4492682,68626",outRaster,pathFeature,"255","ClippingGeometry")
0 Kudos