Use ArcGISEngine to crop Raster Data
Previous/next article 00:09:47/person type: ArcGISEngine Development
View (189)/comment (0)/score (0/0)
The ArcGIS Spatial Analysis extension module provides the ability to crop and extract raster data. In ArcGISEngine, you can call related GP tools to operate raster data.
- Call the Extract By Polygon tool in Space Analysis ArcToolbox
Private void ExtractByPolygon ()
{
IVariantArray parameters = new VarArrayClass ();
String sDocPath = @ "C: \ filerastergdb. gdb \ raster"; // map document path
String sDocPath1 = @ "C: \ filerasteroutput. gdb \ outraster ";
Parameters. Add (sDocPath );
String ss1 = "'2017. 545160 944 '; '2017. 4639276.889 545216'; '2017. 242 4639266.57 '";;
Parameters. Add (ss1 );
Parameters. Add (sDocPath1 );
Parameters. Add ("INSIDE ");
IGeoProcessor2 gp = new GeoProcessorClass ();
Gp. OverwriteOutput = true;
IGeoProcessorResult pResult = null;
Try
{
PResult = gp. Execute ("ExtractByPolygon", parameters, null );
IWorkspaceFactory pFWSF = new ESRI. ArcGIS. DataSourcesGDB. FileGDBWorkspaceFactoryClass ();
ESRI. ArcGIS. Geodatabase. IWorkspace pWS = pFWSF. OpenFromFile (@ "C: \ filerasteroutput. gdb", 0 );
ESRI. ArcGIS. Geodatabase. IRasterWorkspaceEx pRasterWs = pWS as ESRI. ArcGIS. Geodatabase. IRasterWorkspaceEx;
IRasterDataset pRasterDataset = pRasterWs. OpenRasterDataset ("outraster ");
IRasterLayer pRasterLayer = new RasterLayerClass ();
PRasterLayer. CreateFromDataset (pRasterDataset );
AxMapControl1.AddLayer (pRasterLayer );
String mess = null;
For (int k = 0; k <gp. MessageCount; k ++)
{
Mess + = gp. GetMessage (k) + "\ n ";
}
MessageBox. Show (mess );
}
Catch (Exception err)
{
String msg = err. Message;
String mess = null;
For (int k = 0; k <gp. MessageCount; k ++)
{
Mess + = gp. GetMessage (k) + "\ n ";
}
MessageBox. Show (mess );
}
}
- Call the IExtractionOp interface to crop raster data.
Public void ExtractionRasterData (IGeoDataset pGeoDataset, ESRI. ArcGIS. Geometry. ipolympus Gon pPolygone, bool binside)
{
ESRI. ArcGIS. SpatialAnalyst. IExtractionOp pExtractionOp = new ESRI. ArcGIS. SpatialAnalyst. RasterExtractionOpClass ();
ESRI. ArcGIS. Geodatabase. IGeoDataset pgooutput = pExtractionOp. Polygon (pGeoDataset, pPolygone, binside );
}