|
阅读:1351回复:1
有人ae做过叠加裁减么?(急)
<P>那位大侠ae做过裁剪啊?帮帮忙吧,下面是我的一段代码,有问题,没有效果</P>
<P>private void Overlayer_Click(object sender, System.EventArgs e)<BR> {<BR> GIS.Formclip formclip= new Formclip();<BR> formclip.mapControl=mapControl;<BR> if(formclip.ShowDialog()==DialogResult.OK)</P> <P> try<BR> {<BR> //分析overlayer层<BR> string overlayer=formclip.overlayer.SelectedItem.ToString();<BR> ILayer pLayer=this.GetLayer(overlayer);<BR> IFeatureLayer poverlayerLayer=pLayer as IFeatureLayer; <BR> ITable poverlayerTable=pLayer as ITable;</P> <P><BR> //分析input层<BR> string input=formclip.input.SelectedItem.ToString();<BR> ILayer pLayer2=this.GetLayer(input); <BR> IFeatureLayer pInputFeatLayer=pLayer2 as IFeatureLayer; <BR> ITable pInputTable=pLayer2 as ITable;<BR> IFeatureClass pInputFeatClass=pInputFeatLayer.FeatureClass;</P> <P> IFeatureClassName pFeatClassName = new FeatureClassNameClass();<BR> pFeatClassName.FeatureType = esriFeatureType.esriFTSimple;<BR> pFeatClassName.ShapeFieldName="shape";<BR> pFeatClassName.ShapeType=pInputFeatClass.ShapeType; </P> <P> //工作空间名称<BR> IWorkspaceName pNewWorkspaceName=new WorkspaceNameClass();<BR> pNewWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";<BR> pNewWorkspaceName.PathName = @"..\data\";</P> <P> //数据集<BR> IDatasetName pDatasetName=pFeatClassName as IDatasetName;<BR> pDatasetName.Name="clip";<BR> pDatasetName.WorkspaceName=pNewWorkspaceName; </P> <P> //裁</P> <P> IBasicGeoprocessor pBGP=new BasicGeoprocessorClass();<BR> IFeatureClass pOutputFeatClass=pBGP.Intersect(pInputTable,false,poverlayerTable,false,0.0001,pFeatClassName); <BR> <BR> //输出</P> <P> IFeatureLayer pOutputFeatLayer=new FeatureLayerClass();<BR> pOutputFeatLayer.FeatureClass=pOutputFeatClass;<BR> pOutputFeatLayer.Name=pOutputFeatClass.AliasName;</P> <P> mapControl.AddLayer((ILayer)pOutputFeatClass,0);<BR> axMapControlMain.Update();<BR> }<BR> catch(Exception ex)<BR> {<BR> MessageBox.Show(ex.Message);<BR> }<BR> 目的就是想要输入一个层,把另一个层在这个范围内的数据都裁下来,形成一个新层,每次都直接catch出来了,根本不执行裁剪,是代码由问题,还是思路根本不对?</P> <P>请各位大侠指教下阿,很着急</P> |
|
|
1楼#
发布于:2006-10-28 13:14
<PRE>Public Function ClipFeatClassWithShp(ByVal BaseLayerDB As String, _
ByVal BaseLayerFCName As String, _ ByVal ClipFolder As String, _ ByVal ClipShp As String, _ ByVal OutFolder As String, _ ByVal OutShp As String, _ ByVal Tolerance As Double) As System.Exception ' ----------------------------------------------------------- ' Clips a FeatureClass with a Shapefile. Returns an Exception ' ----------------------------------------------------------- Try Dim WSF As IWorkspaceFactory Dim FWS As IFeatureWorkspace Dim BaseLayerFC As IFeatureClass, ClipFC As IFeatureClass Dim OutWSN As IWorkspaceName Dim OutDSN As IDatasetName Dim BaseLayerTable As ITable, ClipTable As ITable Dim BGP As IBasicGeoprocessor Dim OutFC As IFeatureClass Dim OutFCN As IFeatureClassName ' Clip (ShapeFile WorkSpaceFactory) WSF = New ShapefileWorkspaceFactory() FWS = WSF.OpenFromFile(ClipFolder, 0) WSF = Nothing ClipFC = FWS.OpenFeatureClass(ClipShp) ' BaseLayer (Access WorkSpaceFactory) Dim WS As IWorkspace WSF = New AccessWorkspaceFactory() WS = WSF.OpenFromFile(BaseLayerDB, 0) FWS = WS BaseLayerFC = FWS.OpenTable(BaseLayerFCName) WSF = Nothing WS = Nothing BaseLayerFC = FWS.OpenFeatureClass(BaseLayerFCName) ' Out FeatureClass OutFCN = New FeatureClassName() With OutFCN .FeatureType = esriFeatureType.esriFTSimple .ShapeFieldName = "SHAPE" .ShapeType = BaseLayerFC.ShapeType End With ' Out WorkspaceName OutWSN = New WorkspaceName() With OutWSN .WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory" .PathName = BaseLayerDB End With OutDSN = OutFCN With OutDSN .Name = OutShp .WorkspaceName = OutWSN End With ' Tolerance (0.0 = Use Default) Tolerance = 0.0# ' ITable to be used in Clip BaseLayerTable = BaseLayerFC ClipTable = ClipFC ' Clip! BGP = New BasicGeoprocessor() OutFC = BGP.Clip(BaseLayerTable, False, ClipTable, False, Tolerance, OutFCN) FWS = Nothing BaseLayerFC = Nothing ClipFC = Nothing OutWSN = Nothing OutDSN = Nothing Tolerance = Nothing BaseLayerTable = Nothing ClipTable = Nothing BGP = Nothing OutFC = Nothing OutFCN = Nothing Catch ex As Exception Return ex End Try Return New Exception("") End Function</PRE> |
|
|