IClipFilter clipRaster = new ClipFilterClass();
//Add the polygons from the shapefile to the clip filer
IGeometry clipGeometry;
IFeature feature;
for (int i = 0; i <= featureClass.FeatureCount(null) - 1; i++)
{
feature = featureClass.GetFeature(i);
clipGeometry = (IGeometry)feature.Shape;
clipRaster.Add(clipGeometry);
}
//Set the filter to the raster
IPixelOperation pixelOp = (IPixelOperation)raster;
pixelOp.PixelFilter = (IPixelFilter)clipRaster;
//Now we need to specify properties for the output. The output can
//be a file format or a geodatabase. This sample supports output
//to File geodatabase and Personal Geodatabase.
//If the output is a file format and input raster does not contain NoData and the max value
//of the pixel depth is being used. (For example 255 is used for
//8 bit unsigned case), output pixel depth needs to be promoted and NoData
//value need to set up properly.
IWorkspace workSpace = openWorkspace(outputFolder);
IRasterProps rasterProps = (IRasterProps)raster;
if (workSpace.PathName.Contains(".gdb") == false)
{
rasterProps.NoDataValue = 256;
rasterProps.PixelType = rstPixelType.PT_USHORT;
}
//Save the result out
ISaveAs saveas = (ISaveAs)raster;
saveas.SaveAs(outputFile, workSpace, Format);
//Add the polygons from the shapefile to the clip filer
IGeometry clipGeometry;
IFeature feature;
for (int i = 0; i <= featureClass.FeatureCount(null) - 1; i++)
{
feature = featureClass.GetFeature(i);
clipGeometry = (IGeometry)feature.Shape;
clipRaster.Add(clipGeometry);
}
//Set the filter to the raster
IPixelOperation pixelOp = (IPixelOperation)raster;
pixelOp.PixelFilter = (IPixelFilter)clipRaster;
//Now we need to specify properties for the output. The output can
//be a file format or a geodatabase. This sample supports output
//to File geodatabase and Personal Geodatabase.
//If the output is a file format and input raster does not contain NoData and the max value
//of the pixel depth is being used. (For example 255 is used for
//8 bit unsigned case), output pixel depth needs to be promoted and NoData
//value need to set up properly.
IWorkspace workSpace = openWorkspace(outputFolder);
IRasterProps rasterProps = (IRasterProps)raster;
if (workSpace.PathName.Contains(".gdb") == false)
{
rasterProps.NoDataValue = 256;
rasterProps.PixelType = rstPixelType.PT_USHORT;
}
//Save the result out
ISaveAs saveas = (ISaveAs)raster;
saveas.SaveAs(outputFile, workSpace, Format);