矢量图层叠加求交分析
AE开发中,矢量图层叠加分析需要用到的主要类为BasicGeoprocessor,其主要接口为IBasicGeoprocessor。IBasicGeoprocessor接口提供了基本的空间数据处理的方法和属性,其中包括叠加求交(Interset)和叠加求和(Union)。
下面提供两个叠加求交的开发实例:
一、  VB+AE9.1叠加求交示例代码:
 1 Private Sub M_OverLayer_Click()
Private Sub M_OverLayer_Click()
2 ' Get the input layer and feature class
' Get the input layer and feature class
3 Dim pLayer As ILayer
  Dim pLayer As ILayer
4 Set pLayer = MapControl1.Layer(0)
  Set pLayer = MapControl1.Layer(0)
5 Dim pInputFeatLayer As IFeatureLayer
  Dim pInputFeatLayer As IFeatureLayer
6 Set pInputFeatLayer = pLayer
  Set pInputFeatLayer = pLayer
7 ' Use the Itable interface from the Layer (not from the FeatureClass)
  ' Use the Itable interface from the Layer (not from the FeatureClass)
8 
  
9 Dim pInputTable As ITable
  Dim pInputTable As ITable
10 Set pInputTable = pLayer
  Set pInputTable = pLayer
11 ' Get the input feature class.
  ' Get the input feature class.
12 ' The Input feature class properties, such as shape type,
  ' The Input feature class properties, such as shape type,
13 ' will be needed for the output
  ' will be needed for the output
14 
  
15 Dim pInputFeatClass As IFeatureClass
  Dim pInputFeatClass As IFeatureClass
16 Set pInputFeatClass = pInputFeatLayer.FeatureClass
  Set pInputFeatClass = pInputFeatLayer.FeatureClass
17 ' Get the overlay layer
  ' Get the overlay layer
18 ' Use the Itable interface from the Layer (not from the FeatureClass)
  ' Use the Itable interface from the Layer (not from the FeatureClass)
19 Set pLayer = MapControl1.Layer(1)
  Set pLayer = MapControl1.Layer(1)
20 Dim pOverlayTable As ITable
  Dim pOverlayTable As ITable
21 Set pOverlayTable = pLayer
  Set pOverlayTable = pLayer
22 
  
23 ' Error checking
  ' Error checking
24 If pInputTable Is Nothing Then
  If pInputTable Is Nothing Then
25 MsgBox "Table QI failed"
    MsgBox "Table QI failed"
26 Exit Sub
    Exit Sub
27 End If
  End If
28 
  
29 If pOverlayTable Is Nothing Then
  If pOverlayTable Is Nothing Then
30 MsgBox "Table QI failed"
    MsgBox "Table QI failed"
31 Exit Sub
    Exit Sub
32 End If
  End If
33 
  
34 ' Define the output feature class name and shape type (taken from the
  ' Define the output feature class name and shape type (taken from the
35 ' properties of the input feature class)
  ' properties of the input feature class)
36 Dim pFeatClassName As IFeatureClassName
  Dim pFeatClassName As IFeatureClassName
37 Set pFeatClassName = New FeatureClassName
  Set pFeatClassName = New FeatureClassName
38 With pFeatClassName
  With pFeatClassName
39 .FeatureType = esriFTSimple
    .FeatureType = esriFTSimple
40 .ShapeFieldName = "Shape"
    .ShapeFieldName = "Shape"
41 .ShapeType = pInputFeatClass.ShapeType
    .ShapeType = pInputFeatClass.ShapeType
42 End With
  End With
43 
  
44 ' Set output location and feature class name
  ' Set output location and feature class name
45 Dim pNewWSName As IWorkspaceName
  Dim pNewWSName As IWorkspaceName
46 Set pNewWSName = New WorkspaceName
  Set pNewWSName = New WorkspaceName
47 pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory.1"
  pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory.1"
48 pNewWSName.PathName = "C:\temp"
  pNewWSName.PathName = "C:\temp"
49 
  
50 Dim pDatasetName As IDatasetName
  Dim pDatasetName As IDatasetName
51 Set pDatasetName = pFeatClassName
  Set pDatasetName = pFeatClassName
52 pDatasetName.Name = "Intersect_result"
  pDatasetName.Name = "Intersect_result"
53 Set pDatasetName.WorkspaceName = pNewWSName
  Set pDatasetName.WorkspaceName = pNewWSName
54 ' Set the tolerance. Passing 0.0 causes the default tolerance to be used.
  ' 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
  ' The default tolerance is 1/10,000 of the extent of the data frame's spatial domain
56 
  
57 Dim tol As Double
  Dim tol As Double
58 tol = 0#      ' Perform the intersect
  tol = 0#      ' Perform the intersect
59 Dim pBGP As IBasicGeoprocessor
  Dim pBGP As IBasicGeoprocessor
60 Set pBGP = New BasicGeoprocessor
  Set pBGP = New BasicGeoprocessor
61 
  
62 Dim pOutputFeatClass As IFeatureClass
  Dim pOutputFeatClass As IFeatureClass
63 Set pOutputFeatClass = pBGP.Intersect(pInputTable, False, pOverlayTable, False, _
  Set pOutputFeatClass = pBGP.Intersect(pInputTable, False, pOverlayTable, False, _
64 tol, pFeatClassName)
    tol, pFeatClassName)
65 
    
66 ' Add the output layer to the map
  ' Add the output layer to the map
67 Dim pOutputFeatLayer As IFeatureLayer
  Dim pOutputFeatLayer As IFeatureLayer
68 Set pOutputFeatLayer = New FeatureLayer
  Set pOutputFeatLayer = New FeatureLayer
69 Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
  Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
70 pOutputFeatLayer.Name = pOutputFeatClass.AliasName
  pOutputFeatLayer.Name = pOutputFeatClass.AliasName
71 MapControl1.AddLayer pOutputFeatLayer
  MapControl1.AddLayer pOutputFeatLayer
72 End Sub
End Sub
73
74
75
 Private Sub M_OverLayer_Click()
Private Sub M_OverLayer_Click()2
 ' Get the input layer and feature class
' Get the input layer and feature class3
 Dim pLayer As ILayer
  Dim pLayer As ILayer4
 Set pLayer = MapControl1.Layer(0)
  Set pLayer = MapControl1.Layer(0)5
 Dim pInputFeatLayer As IFeatureLayer
  Dim pInputFeatLayer As IFeatureLayer6
 Set pInputFeatLayer = pLayer
  Set pInputFeatLayer = pLayer7
 ' Use the Itable interface from the Layer (not from the FeatureClass)
  ' Use the Itable interface from the Layer (not from the FeatureClass)8
 
  9
 Dim pInputTable As ITable
  Dim pInputTable As ITable10
 Set pInputTable = pLayer
  Set pInputTable = pLayer11
 ' Get the input feature class.
  ' Get the input feature class.12
 ' The Input feature class properties, such as shape type,
  ' The Input feature class properties, such as shape type,13
 ' will be needed for the output
  ' will be needed for the output14
 
  15
 Dim pInputFeatClass As IFeatureClass
  Dim pInputFeatClass As IFeatureClass16
 Set pInputFeatClass = pInputFeatLayer.FeatureClass
  Set pInputFeatClass = pInputFeatLayer.FeatureClass17
 ' Get the overlay layer
  ' Get the overlay layer18
 ' Use the Itable interface from the Layer (not from the FeatureClass)
  ' Use the Itable interface from the Layer (not from the FeatureClass)19
 Set pLayer = MapControl1.Layer(1)
  Set pLayer = MapControl1.Layer(1)20
 Dim pOverlayTable As ITable
  Dim pOverlayTable As ITable21
 Set pOverlayTable = pLayer
  Set pOverlayTable = pLayer22
 
  23
 ' Error checking
  ' Error checking24
 If pInputTable Is Nothing Then
  If pInputTable Is Nothing Then25
 MsgBox "Table QI failed"
    MsgBox "Table QI failed"26
 Exit Sub
    Exit Sub27
 End If
  End If28
 
  29
 If pOverlayTable Is Nothing Then
  If pOverlayTable Is Nothing Then30
 MsgBox "Table QI failed"
    MsgBox "Table QI failed"31
 Exit Sub
    Exit Sub32
 End If
  End If33
 
  34
 ' Define the output feature class name and shape type (taken from the
  ' Define the output feature class name and shape type (taken from the35
 ' properties of the input feature class)
  ' properties of the input feature class)36
 Dim pFeatClassName As IFeatureClassName
  Dim pFeatClassName As IFeatureClassName37
 Set pFeatClassName = New FeatureClassName
  Set pFeatClassName = New FeatureClassName38
 With pFeatClassName
  With pFeatClassName39
 .FeatureType = esriFTSimple
    .FeatureType = esriFTSimple40
 .ShapeFieldName = "Shape"
    .ShapeFieldName = "Shape"41
 .ShapeType = pInputFeatClass.ShapeType
    .ShapeType = pInputFeatClass.ShapeType42
 End With
  End With43
 
  44
 ' Set output location and feature class name
  ' Set output location and feature class name45
 Dim pNewWSName As IWorkspaceName
  Dim pNewWSName As IWorkspaceName46
 Set pNewWSName = New WorkspaceName
  Set pNewWSName = New WorkspaceName47
 pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory.1"
  pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory.1"48
 pNewWSName.PathName = "C:\temp"
  pNewWSName.PathName = "C:\temp"49
 
  50
 Dim pDatasetName As IDatasetName
  Dim pDatasetName As IDatasetName51
 Set pDatasetName = pFeatClassName
  Set pDatasetName = pFeatClassName52
 pDatasetName.Name = "Intersect_result"
  pDatasetName.Name = "Intersect_result"53
 Set pDatasetName.WorkspaceName = pNewWSName
  Set pDatasetName.WorkspaceName = pNewWSName54
 ' Set the tolerance. Passing 0.0 causes the default tolerance to be used.
  ' 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
  ' The default tolerance is 1/10,000 of the extent of the data frame's spatial domain56
 
  57
 Dim tol As Double
  Dim tol As Double58
 tol = 0#      ' Perform the intersect
  tol = 0#      ' Perform the intersect59
 Dim pBGP As IBasicGeoprocessor
  Dim pBGP As IBasicGeoprocessor60
 Set pBGP = New BasicGeoprocessor
  Set pBGP = New BasicGeoprocessor61
 
  62
 Dim pOutputFeatClass As IFeatureClass
  Dim pOutputFeatClass As IFeatureClass63
 Set pOutputFeatClass = pBGP.Intersect(pInputTable, False, pOverlayTable, False, _
  Set pOutputFeatClass = pBGP.Intersect(pInputTable, False, pOverlayTable, False, _64
 tol, pFeatClassName)
    tol, pFeatClassName)65
 
    66
 ' Add the output layer to the map
  ' Add the output layer to the map67
 Dim pOutputFeatLayer As IFeatureLayer
  Dim pOutputFeatLayer As IFeatureLayer68
 Set pOutputFeatLayer = New FeatureLayer
  Set pOutputFeatLayer = New FeatureLayer69
 Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
  Set pOutputFeatLayer.FeatureClass = pOutputFeatClass70
 pOutputFeatLayer.Name = pOutputFeatClass.AliasName
  pOutputFeatLayer.Name = pOutputFeatClass.AliasName71
 MapControl1.AddLayer pOutputFeatLayer
  MapControl1.AddLayer pOutputFeatLayer72
 End Sub
End Sub73

74

75

二、C#+AE9.1叠加求交示例代码:
 1 private void M_OverLayer_Click(object sender, System.EventArgs e)
        private void M_OverLayer_Click(object sender, System.EventArgs e)
2 {
        {
3 try
            try
4 {
            {
5 //分析层
                //分析层
6 ILayer pLayer=this.axMapControl1.get_Layer(0);
                ILayer pLayer=this.axMapControl1.get_Layer(0);
7 IFeatureLayer pInputFeatLayer=pLayer as IFeatureLayer;
                IFeatureLayer pInputFeatLayer=pLayer as IFeatureLayer;    
8 ITable pInputTable=pLayer as ITable;
                ITable pInputTable=pLayer as ITable;
9 IFeatureClass pInputFeatClass=pInputFeatLayer.FeatureClass;
                IFeatureClass pInputFeatClass=pInputFeatLayer.FeatureClass;
10
11 //叠加表
                //叠加表
12 pLayer=this.axMapControl1.get_Layer(1);
                pLayer=this.axMapControl1.get_Layer(1);
13 ITable pOverlayTable=pLayer as ITable;
                ITable pOverlayTable=pLayer as ITable;
14
15 //叠加分析表
                //叠加分析表
16 IFeatureClassName pFeatClassName=new FeatureClassNameClass();
                IFeatureClassName pFeatClassName=new FeatureClassNameClass();
17 pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;
                pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;
18 pFeatClassName.ShapeFieldName="shape";
                pFeatClassName.ShapeFieldName="shape";
19 pFeatClassName.ShapeType=pInputFeatClass.ShapeType;
                pFeatClassName.ShapeType=pInputFeatClass.ShapeType;
20
21 //工作空间名称
                //工作空间名称
22 IWorkspaceName pNewWSName=new WorkspaceNameClass();
                IWorkspaceName pNewWSName=new WorkspaceNameClass();
23 pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
                pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
24 pNewWSName.PathName = @"C:\temp";
                pNewWSName.PathName = @"C:\temp";
25
26 //数据集名称
                //数据集名称
27 IDatasetName pDatasetName=pFeatClassName as IDatasetName;
                IDatasetName pDatasetName=pFeatClassName as IDatasetName;
28 pDatasetName.Name="ss";
                pDatasetName.Name="ss";
29 pDatasetName.WorkspaceName=pNewWSName;
                pDatasetName.WorkspaceName=pNewWSName; 
30
31 //几何处理
                //几何处理
32 IBasicGeoprocessor pBGP=new BasicGeoprocessorClass();
                IBasicGeoprocessor pBGP=new BasicGeoprocessorClass();
33 IFeatureClass pOutputFeatClass=pBGP.Intersect(pInputTable,false,pOverlayTable,false,0.01,pFeatClassName);
                IFeatureClass pOutputFeatClass=pBGP.Intersect(pInputTable,false,pOverlayTable,false,0.01,pFeatClassName);  
34 
   
35 //输出要素层设置
                //输出要素层设置
36 IFeatureLayer pOutputFeatLayer=new FeatureLayerClass();
                IFeatureLayer pOutputFeatLayer=new FeatureLayerClass();
37 pOutputFeatLayer.FeatureClass=pOutputFeatClass;
                pOutputFeatLayer.FeatureClass=pOutputFeatClass;
38 pOutputFeatLayer.Name=pOutputFeatClass.AliasName;
                pOutputFeatLayer.Name=pOutputFeatClass.AliasName;
39
40 this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);
                this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);
41 axMapControl1.Update();
                axMapControl1.Update();
42 }
            }
43 catch(Exception ex)
            catch(Exception ex)
44 {
            {
45 MessageBox.Show(ex.Message);
                MessageBox.Show(ex.Message);
46 }
            }
47 }
        }
 private void M_OverLayer_Click(object sender, System.EventArgs e)
        private void M_OverLayer_Click(object sender, System.EventArgs e)2
 {
        {3
 try
            try4
 {
            {5
 //分析层
                //分析层6
 ILayer pLayer=this.axMapControl1.get_Layer(0);
                ILayer pLayer=this.axMapControl1.get_Layer(0);7
 IFeatureLayer pInputFeatLayer=pLayer as IFeatureLayer;
                IFeatureLayer pInputFeatLayer=pLayer as IFeatureLayer;    8
 ITable pInputTable=pLayer as ITable;
                ITable pInputTable=pLayer as ITable;9
 IFeatureClass pInputFeatClass=pInputFeatLayer.FeatureClass;
                IFeatureClass pInputFeatClass=pInputFeatLayer.FeatureClass;10

11
 //叠加表
                //叠加表12
 pLayer=this.axMapControl1.get_Layer(1);
                pLayer=this.axMapControl1.get_Layer(1);13
 ITable pOverlayTable=pLayer as ITable;
                ITable pOverlayTable=pLayer as ITable;14

15
 //叠加分析表
                //叠加分析表16
 IFeatureClassName pFeatClassName=new FeatureClassNameClass();
                IFeatureClassName pFeatClassName=new FeatureClassNameClass();17
 pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;
                pFeatClassName.FeatureType=esriFeatureType.esriFTSimple;18
 pFeatClassName.ShapeFieldName="shape";
                pFeatClassName.ShapeFieldName="shape";19
 pFeatClassName.ShapeType=pInputFeatClass.ShapeType;
                pFeatClassName.ShapeType=pInputFeatClass.ShapeType;20

21
 //工作空间名称
                //工作空间名称22
 IWorkspaceName pNewWSName=new WorkspaceNameClass();
                IWorkspaceName pNewWSName=new WorkspaceNameClass();23
 pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
                pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";24
 pNewWSName.PathName = @"C:\temp";
                pNewWSName.PathName = @"C:\temp";25

26
 //数据集名称
                //数据集名称27
 IDatasetName pDatasetName=pFeatClassName as IDatasetName;
                IDatasetName pDatasetName=pFeatClassName as IDatasetName;28
 pDatasetName.Name="ss";
                pDatasetName.Name="ss";29
 pDatasetName.WorkspaceName=pNewWSName;
                pDatasetName.WorkspaceName=pNewWSName; 30

31
 //几何处理
                //几何处理32
 IBasicGeoprocessor pBGP=new BasicGeoprocessorClass();
                IBasicGeoprocessor pBGP=new BasicGeoprocessorClass();33
 IFeatureClass pOutputFeatClass=pBGP.Intersect(pInputTable,false,pOverlayTable,false,0.01,pFeatClassName);
                IFeatureClass pOutputFeatClass=pBGP.Intersect(pInputTable,false,pOverlayTable,false,0.01,pFeatClassName);  34
 
   35
 //输出要素层设置
                //输出要素层设置36
 IFeatureLayer pOutputFeatLayer=new FeatureLayerClass();
                IFeatureLayer pOutputFeatLayer=new FeatureLayerClass();37
 pOutputFeatLayer.FeatureClass=pOutputFeatClass;
                pOutputFeatLayer.FeatureClass=pOutputFeatClass;38
 pOutputFeatLayer.Name=pOutputFeatClass.AliasName;
                pOutputFeatLayer.Name=pOutputFeatClass.AliasName;39

40
 this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);
                this.axMapControl1.AddLayer((ILayer)pOutputFeatClass,0);41
 axMapControl1.Update();
                axMapControl1.Update();42
 }
            }43
 catch(Exception ex)
            catch(Exception ex)44
 {
            {45
 MessageBox.Show(ex.Message);
                MessageBox.Show(ex.Message);46
 }
            }47
 }
        } 
                    
                 
 
        
 
             
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号