矢量图层叠加求交分析
AE开发中,矢量图层叠加分析需要用到的主要类为BasicGeoprocessor,其主要接口为IBasicGeoprocessor。IBasicGeoprocessor接口提供了基本的空间数据处理的方法和属性,其中包括叠加求交(Interset)和叠加求和(Union)。
下面提供两个叠加求交的开发实例:
一、 VB+AE9.1叠加求交示例代码:
1Private Sub M_OverLayer_Click()
2' Get the input layer and feature class
3 Dim pLayer As ILayer
4 Set pLayer = MapControl1.Layer(0)
5 Dim pInputFeatLayer As IFeatureLayer
6 Set pInputFeatLayer = pLayer
7 ' Use the Itable interface from the Layer (not from the FeatureClass)
8
9 Dim pInputTable As ITable
10 Set pInputTable = pLayer
11 ' Get the input feature class.
12 ' The Input feature class properties, such as shape type,
13 ' will be needed for the output
14
15 Dim pInputFeatClass As IFeatureClass
16 Set pInputFeatClass = pInputFeatLayer.FeatureClass
17 ' Get the overlay layer
18 ' Use the Itable interface from the Layer (not from the FeatureClass)
19 Set pLayer = MapControl1.Layer(1)
20 Dim pOverlayTable As ITable
21 Set pOverlayTable = pLayer
22
23 ' Error checking
24 If pInputTable Is Nothing Then
25 MsgBox "Table QI failed"
26 Exit Sub
27 End If
28
29 If pOverlayTable Is Nothing Then
30 MsgBox "Table QI failed"
31 Exit Sub
32 End If
33
34 ' Define the output feature class name and shape type (taken from the
35 ' properties of the input feature class)
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 ' Set output location and feature class name
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 ' Set the tolerance. Passing 0.0 causes the default tolerance to be used.
55 ' The default tolerance is 1/10,000 of the extent of the data frame's spatial domain
56
57 Dim tol As Double
58 tol = 0# ' Perform the intersect
59 Dim pBGP As IBasicGeoprocessor
60 Set pBGP = New BasicGeoprocessor
61
62 Dim pOutputFeatClass As IFeatureClass
63 Set pOutputFeatClass = pBGP.Intersect(pInputTable, False, pOverlayTable, False, _
64 tol, pFeatClassName)
65
66 ' Add the output layer to the map
67 Dim pOutputFeatLayer As IFeatureLayer
68 Set pOutputFeatLayer = New FeatureLayer
69 Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
70 pOutputFeatLayer.Name = pOutputFeatClass.AliasName
71 MapControl1.AddLayer pOutputFeatLayer
72End Sub
73
74
75
2' Get the input layer and feature class
3 Dim pLayer As ILayer
4 Set pLayer = MapControl1.Layer(0)
5 Dim pInputFeatLayer As IFeatureLayer
6 Set pInputFeatLayer = pLayer
7 ' Use the Itable interface from the Layer (not from the FeatureClass)
8
9 Dim pInputTable As ITable
10 Set pInputTable = pLayer
11 ' Get the input feature class.
12 ' The Input feature class properties, such as shape type,
13 ' will be needed for the output
14
15 Dim pInputFeatClass As IFeatureClass
16 Set pInputFeatClass = pInputFeatLayer.FeatureClass
17 ' Get the overlay layer
18 ' Use the Itable interface from the Layer (not from the FeatureClass)
19 Set pLayer = MapControl1.Layer(1)
20 Dim pOverlayTable As ITable
21 Set pOverlayTable = pLayer
22
23 ' Error checking
24 If pInputTable Is Nothing Then
25 MsgBox "Table QI failed"
26 Exit Sub
27 End If
28
29 If pOverlayTable Is Nothing Then
30 MsgBox "Table QI failed"
31 Exit Sub
32 End If
33
34 ' Define the output feature class name and shape type (taken from the
35 ' properties of the input feature class)
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 ' Set output location and feature class name
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 ' Set the tolerance. Passing 0.0 causes the default tolerance to be used.
55 ' The default tolerance is 1/10,000 of the extent of the data frame's spatial domain
56
57 Dim tol As Double
58 tol = 0# ' Perform the intersect
59 Dim pBGP As IBasicGeoprocessor
60 Set pBGP = New BasicGeoprocessor
61
62 Dim pOutputFeatClass As IFeatureClass
63 Set pOutputFeatClass = pBGP.Intersect(pInputTable, False, pOverlayTable, False, _
64 tol, pFeatClassName)
65
66 ' Add the output layer to the map
67 Dim pOutputFeatLayer As IFeatureLayer
68 Set pOutputFeatLayer = New FeatureLayer
69 Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
70 pOutputFeatLayer.Name = pOutputFeatClass.AliasName
71 MapControl1.AddLayer pOutputFeatLayer
72End Sub
73
74
75
二、C#+AE9.1叠加求交示例代码:
1 private void M_OverLayer_Click(object sender, System.EventArgs e)
2 {
3 try
4 {
5 //分析层
6 ILayer pLayer=this.axMapControl1.get_Layer(0);
7 IFeatureLayer pInputFeatLayer=pLayer as IFeatureLayer;
8 ITable pInputTable=pLayer as ITable;
9 IFeatureClass pInputFeatClass=pInputFeatLayer.FeatureClass;
10
11 //叠加表
12 pLayer=this.axMapControl1.get_Layer(1);
13 ITable pOverlayTable=pLayer as ITable;
14
15 //叠加分析表
16 IFeatureClassName pFeatClassName=new FeatureClassNameClass();
17 pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;
18 pFeatClassName.ShapeFieldName="shape";
19 pFeatClassName.ShapeType=pInputFeatClass.ShapeType;
20
21 //工作空间名称
22 IWorkspaceName pNewWSName=new WorkspaceNameClass();
23 pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
24 pNewWSName.PathName = @"C:\temp";
25
26 //数据集名称
27 IDatasetName pDatasetName=pFeatClassName as IDatasetName;
28 pDatasetName.Name="ss";
29 pDatasetName.WorkspaceName=pNewWSName;
30
31 //几何处理
32 IBasicGeoprocessor pBGP=new BasicGeoprocessorClass();
33 IFeatureClass pOutputFeatClass=pBGP.Intersect(pInputTable,false,pOverlayTable,false,0.01,pFeatClassName);
34
35 //输出要素层设置
36 IFeatureLayer pOutputFeatLayer=new FeatureLayerClass();
37 pOutputFeatLayer.FeatureClass=pOutputFeatClass;
38 pOutputFeatLayer.Name=pOutputFeatClass.AliasName;
39
40 this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);
41 axMapControl1.Update();
42 }
43 catch(Exception ex)
44 {
45 MessageBox.Show(ex.Message);
46 }
47 }
2 {
3 try
4 {
5 //分析层
6 ILayer pLayer=this.axMapControl1.get_Layer(0);
7 IFeatureLayer pInputFeatLayer=pLayer as IFeatureLayer;
8 ITable pInputTable=pLayer as ITable;
9 IFeatureClass pInputFeatClass=pInputFeatLayer.FeatureClass;
10
11 //叠加表
12 pLayer=this.axMapControl1.get_Layer(1);
13 ITable pOverlayTable=pLayer as ITable;
14
15 //叠加分析表
16 IFeatureClassName pFeatClassName=new FeatureClassNameClass();
17 pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;
18 pFeatClassName.ShapeFieldName="shape";
19 pFeatClassName.ShapeType=pInputFeatClass.ShapeType;
20
21 //工作空间名称
22 IWorkspaceName pNewWSName=new WorkspaceNameClass();
23 pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
24 pNewWSName.PathName = @"C:\temp";
25
26 //数据集名称
27 IDatasetName pDatasetName=pFeatClassName as IDatasetName;
28 pDatasetName.Name="ss";
29 pDatasetName.WorkspaceName=pNewWSName;
30
31 //几何处理
32 IBasicGeoprocessor pBGP=new BasicGeoprocessorClass();
33 IFeatureClass pOutputFeatClass=pBGP.Intersect(pInputTable,false,pOverlayTable,false,0.01,pFeatClassName);
34
35 //输出要素层设置
36 IFeatureLayer pOutputFeatLayer=new FeatureLayerClass();
37 pOutputFeatLayer.FeatureClass=pOutputFeatClass;
38 pOutputFeatLayer.Name=pOutputFeatClass.AliasName;
39
40 this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);
41 axMapControl1.Update();
42 }
43 catch(Exception ex)
44 {
45 MessageBox.Show(ex.Message);
46 }
47 }