但是也有一些细微的差别需要自己去琢磨
关于Geoprocessing 参考文档 Using Geoprocessing Tools in VB
上代码:
var
pInLayer :ILayer;
pClipLayer :ILayer;
pFeaInLayer :IFeatureLayer;
pFeaClipLayer :IFeatureLayer;
sInFeatures,sClipFeature,sOutFeatures : WideString;
pathName:WideString;
pDataset:IDataset;
pFeaClass:IFeatureClass;
pWS:IWorkspace;
pGeoResult:IGeoprocessorResult;
pAOI : IAoInitialize;
pLicenseStatus:TOleenum;
pVA :IVariantArray;
pGP :IGeoProcessor;
begin
pFeaInLayer:=pInLayer as IFeatureLayer;
pFeaClipLayer:=pClipLayer as IFeatureLayer;
pAOI:=CoAoInitialize.Create as IAoInitialize;
pAOI.Initialize(esriLicenseProductCodeArcInfo,pLicenseStatus);
pGP:=CoGeoprocessor.Create as IGeoprocessor;
//pGP.ResetEnvironments;
//pGP.SetEnvironmentValue('workspace','C:\temp');
//pGP.AddToolbox('D:\Program Files\ArcGIS\ArcToolBox\Toolboxes\Analysis Tools.tbx');
pGP.Set_AddOutputsToMap(True);
pGP.Set_OverwriteOutput(True);
pVA:=CoVarArray.Create as IVariantArray;
pFeaInLayer.Get_FeatureClass(pFeaClass);
pDataset:=pFeaClass as IDataset;
pDataset.Get_Workspace(pWS);
pWS.Get_PathName(pathName);
sInFeatures:=pathName+'\'+OverlayChooseLayerFrm.LayerName1+'.shp';
pFeaClipLayer.Get_FeatureClass(pFeaClass);
pDataset:=pFeaClass as IDataset;
pDataset.Get_Workspace(pWS);
pWS.Get_PathName(pathName);
sClipFeature:=pathName+'\'+OverlayChooseLayerFrm.LayerName2+'.shp';
CreateDirectory(pChar('C:\temp'),Nil);
sOutFeatures:='C:\temp\Clip_output.shp';
pVA.Add(sInFeatures);
pVA.Add(sClipFeature);
pVA.Add(sOutFeatures);
pGP.Execute('Clip_analysis',pVA,Nil,pGeoResult);
pGP.Get_MessageCount(layercount);
{ for I := 0 to layercount - 1 do
begin
pGP.GetMessage(i,sOutFeatures);
showmessage(sOutFeatures);
end; }
pAOI.shutdown;
ShowMessage('裁剪完成,裁剪结果保存于C:\Temp目录下');
end