AE开发中,矢量图层叠加分析需要用到的主要类为BasicGeoprocessor,其主要接口为IBasicGeoprocessor。IBasicGeoprocessor接口提供了基本的空间数据处理的方法和属性,其中包括叠加求交(Interset)和叠加求和(Union)。
下面提供两个叠加求交的开发实例:
一、 VB+AE9.1叠加求交示例代码:
1
Private
Sub
M_OverLayer_Click()
2 ' Gettheinputlayerandfeatureclass
3 Dim pLayer As ILayer
4 Set pLayer = MapControl1.Layer( 0 )
5 Dim pInputFeatLayer As IFeatureLayer
6 Set pInputFeatLayer = pLayer
7 ' UsetheItableinterfacefromtheLayer(notfromtheFeatureClass)
8
9 Dim pInputTable As ITable
10 Set pInputTable = pLayer
11 ' Gettheinputfeatureclass.
12 ' TheInputfeatureclassproperties,suchasshapetype,
13 ' willbeneededfortheoutput
14
15 Dim pInputFeatClass As IFeatureClass
16 Set pInputFeatClass = pInputFeatLayer.FeatureClass
17 ' Gettheoverlaylayer
18 ' UsetheItableinterfacefromtheLayer(notfromtheFeatureClass)
19 Set pLayer = MapControl1.Layer( 1 )
20 Dim pOverlayTable As ITable
21 Set pOverlayTable = pLayer
22
23 ' Errorchecking
24 If pInputTable Is Nothing Then
25 MsgBox " TableQIFailed "
26 Exit Sub
27 End If
28
29 If pOverlayTable Is Nothing Then
30 MsgBox " TableQIFailed "
31 Exit Sub
32 End If
33
34 ' Definetheoutputfeatureclassnameandshapetype(takenfromthe
35 ' propertiesoftheinputfeatureclass)
36 Dim pFeatClassName As IFeatureClassName
37 Set pFeatClassName = New FeatureClassName
38 With pFeatClassName
39 .FeatureType = esriFTSimple
40 .ShapeFieldName = " Shape "
41 .ShapeType = pInputFeatClass.ShapeType
42 End With
43
44 ' Setoutputlocationandfeatureclassname
45 Dim pNewWSName As IWorkspaceName
46 Set pNewWSName = New WorkspaceName
47 pNewWSName.WorkspaceFactoryProgID = " esriCore.ShapeFileWorkspaceFactory.1 "
48 pNewWSName.PathName = " C:/temp "
49
50 Dim pDatasetName As IDatasetName
51 Set pDatasetName = pFeatClassName
52 pDatasetName.Name = " Intersect_result "
53 Set pDatasetName.WorkspaceName = pNewWSName
54 ' Setthetolerance.Passing0.0causesthedefaulttolerancetobeused.
55 ' Thedefaulttoleranceis1/10,000oftheextentofthedataframe'sspatialdomain
56
57 Dim tol As Double
58 tol = 0 # ' Performtheintersect
59 Dim pBGP As IBasicGeoprocessor
60 Set pBGP = New BasicGeoprocessor
61
62 Dim pOutputFeatClass As IFeatureClass
63 Set pOutputFeatClass = pBGP.Intersect(pInputTable, False ,pOverlayTable,_
64 tol,pFeatClassName)
65
66 ' Addtheoutputlayertothemap
67 Dim pOutputFeatLayer As IFeatureLayer
68 Set pOutputFeatLayer = New FeatureLayer
69 Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
70 pOutputFeatLayer.Name = pOutputFeatClass.AliasName
71 MapControl1.AddLayerpOutputFeatLayer
72 EndSub
73
74
75
2 ' Gettheinputlayerandfeatureclass
3 Dim pLayer As ILayer
4 Set pLayer = MapControl1.Layer( 0 )
5 Dim pInputFeatLayer As IFeatureLayer
6 Set pInputFeatLayer = pLayer
7 ' UsetheItableinterfacefromtheLayer(notfromtheFeatureClass)
8
9 Dim pInputTable As ITable
10 Set pInputTable = pLayer
11 ' Gettheinputfeatureclass.
12 ' TheInputfeatureclassproperties,suchasshapetype,
13 ' willbeneededfortheoutput
14
15 Dim pInputFeatClass As IFeatureClass
16 Set pInputFeatClass = pInputFeatLayer.FeatureClass
17 ' Gettheoverlaylayer
18 ' UsetheItableinterfacefromtheLayer(notfromtheFeatureClass)
19 Set pLayer = MapControl1.Layer( 1 )
20 Dim pOverlayTable As ITable
21 Set pOverlayTable = pLayer
22
23 ' Errorchecking
24 If pInputTable Is Nothing Then
25 MsgBox " TableQIFailed "
26 Exit Sub
27 End If
28
29 If pOverlayTable Is Nothing Then
30 MsgBox " TableQIFailed "
31 Exit Sub
32 End If
33
34 ' Definetheoutputfeatureclassnameandshapetype(takenfromthe
35 ' propertiesoftheinputfeatureclass)
36 Dim pFeatClassName As IFeatureClassName
37 Set pFeatClassName = New FeatureClassName
38 With pFeatClassName
39 .FeatureType = esriFTSimple
40 .ShapeFieldName = " Shape "
41 .ShapeType = pInputFeatClass.ShapeType
42 End With
43
44 ' Setoutputlocationandfeatureclassname
45 Dim pNewWSName As IWorkspaceName
46 Set pNewWSName = New WorkspaceName
47 pNewWSName.WorkspaceFactoryProgID = " esriCore.ShapeFileWorkspaceFactory.1 "
48 pNewWSName.PathName = " C:/temp "
49
50 Dim pDatasetName As IDatasetName
51 Set pDatasetName = pFeatClassName
52 pDatasetName.Name = " Intersect_result "
53 Set pDatasetName.WorkspaceName = pNewWSName
54 ' Setthetolerance.Passing0.0causesthedefaulttolerancetobeused.
55 ' Thedefaulttoleranceis1/10,000oftheextentofthedataframe'sspatialdomain
56
57 Dim tol As Double
58 tol = 0 # ' Performtheintersect
59 Dim pBGP As IBasicGeoprocessor
60 Set pBGP = New BasicGeoprocessor
61
62 Dim pOutputFeatClass As IFeatureClass
63 Set pOutputFeatClass = pBGP.Intersect(pInputTable, False ,pOverlayTable,_
64 tol,pFeatClassName)
65
66 ' Addtheoutputlayertothemap
67 Dim pOutputFeatLayer As IFeatureLayer
68 Set pOutputFeatLayer = New FeatureLayer
69 Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
70 pOutputFeatLayer.Name = pOutputFeatClass.AliasName
71 MapControl1.AddLayerpOutputFeatLayer
72 EndSub
73
74
75
二、C#+AE9.1叠加求交示例代码:
1
private
void
M_OverLayer_Click(
object
sender,System.EventArgse)
2 {
3try
4{
5//分析层
6ILayerpLayer=this.axMapControl1.get_Layer(0);
7IFeatureLayerpInputFeatLayer=pLayerasIFeatureLayer;
8ITablepInputTable=pLayerasITable;
9IFeatureClasspInputFeatClass=pInputFeatLayer.FeatureClass;
10
11//叠加表
12pLayer=this.axMapControl1.get_Layer(1);
13ITablepOverlayTable=pLayerasITable;
14
15//叠加分析表
16IFeatureClassNamepFeatClassName=newFeatureClassNameClass();
17pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;
18pFeatClassName.ShapeFieldName="shape";
19pFeatClassName.ShapeType=pInputFeatClass.ShapeType;
20
21//工作空间名称
22IWorkspaceNamepNewWSName=newWorkspaceNameClass();
23pNewWSName.WorkspaceFactoryProgID="esriDataSourcesFile.ShapefileWorkspaceFactory";
24pNewWSName.PathName=@"C:/temp";
25
26//数据集名称
27IDatasetNamepDatasetName=pFeatClassNameasIDatasetName;
28pDatasetName.Name="ss";
29pDatasetName.WorkspaceName=pNewWSName;
30
31//几何处理
32IBasicGeoprocessorpBGP=newBasicGeoprocessorClass();
33IFeatureClasspOutputFeatClass=pBGP.Intersect(pInputTable,false,0.01,pFeatClassName);
34
35//输出要素层设置
36IFeatureLayerpOutputFeatLayer=newFeatureLayerClass();
37pOutputFeatLayer.FeatureClass=pOutputFeatClass;
38pOutputFeatLayer.Name=pOutputFeatClass.AliasName;
39
40this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);
41axMapControl1.Update();
42}
43catch(Exceptionex)
44{
45MessageBox.Show(ex.Message);
46}
47}
来自:http://www.cnblogs.com/raymond19840709/archive/2007/01/12/618998.html2 {
3try
4{
5//分析层
6ILayerpLayer=this.axMapControl1.get_Layer(0);
7IFeatureLayerpInputFeatLayer=pLayerasIFeatureLayer;
8ITablepInputTable=pLayerasITable;
9IFeatureClasspInputFeatClass=pInputFeatLayer.FeatureClass;
10
11//叠加表
12pLayer=this.axMapControl1.get_Layer(1);
13ITablepOverlayTable=pLayerasITable;
14
15//叠加分析表
16IFeatureClassNamepFeatClassName=newFeatureClassNameClass();
17pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;
18pFeatClassName.ShapeFieldName="shape";
19pFeatClassName.ShapeType=pInputFeatClass.ShapeType;
20
21//工作空间名称
22IWorkspaceNamepNewWSName=newWorkspaceNameClass();
23pNewWSName.WorkspaceFactoryProgID="esriDataSourcesFile.ShapefileWorkspaceFactory";
24pNewWSName.PathName=@"C:/temp";
25
26//数据集名称
27IDatasetNamepDatasetName=pFeatClassNameasIDatasetName;
28pDatasetName.Name="ss";
29pDatasetName.WorkspaceName=pNewWSName;
30
31//几何处理
32IBasicGeoprocessorpBGP=newBasicGeoprocessorClass();
33IFeatureClasspOutputFeatClass=pBGP.Intersect(pInputTable,false,0.01,pFeatClassName);
34
35//输出要素层设置
36IFeatureLayerpOutputFeatLayer=newFeatureLayerClass();
37pOutputFeatLayer.FeatureClass=pOutputFeatClass;
38pOutputFeatLayer.Name=pOutputFeatClass.AliasName;
39
40this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);
41axMapControl1.Update();
42}
43catch(Exceptionex)
44{
45MessageBox.Show(ex.Message);
46}
47}