ArcEngine加载图层的五个步…

转自: http://manwang.blog.sohu.com/130537431.html

1.创建一个类工厂

2.使用类工厂创建一个要使用的工作区

3.使用工作区打开并得到图层的dataset

4.把dataset装入到新建的图层实例

5.把图层加载到MapControl控件

 

示例代码:源自ArcGis help文件

1.添加rasterfile

[C#]
#region"Open Raster File As GeoDatset" 
public ESRI.ArcGIS.Geodatabase.IGeoDataset OpenRasterFileAsGeoDatset(System.String path, System.String name)
{
  try
    {

        ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass();
        ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace rasterWorkspace = (ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace)(workspaceFactory.OpenFromFile(path, 0));
        ESRI.ArcGIS.Geodatabase.IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(name);
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterDataset; // Explicit Cast

        return geoDataset;

    }
    catch (Exception ex)
    {

        //System.Diagnostics.Debug.WriteLine(ex.Message)
        return null;

    }

}
#endregion
[Visual Basic .NET]
#Region"Open Raster File As GeoDatset"
 
     
Public Function OpenRasterFileAsGeoDatset(ByVal path As System.String, ByVal name As System.String) As ESRI.ArcGIS.Geodatabase.IGeoDataset

  Try

    Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesRaster.RasterWorkspaceFactoryClass()
    Dim rasterWorkspace As ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace = CType(workspaceFactory.OpenFromFile(path, 0), ESRI.ArcGIS.DataSourcesRaster.IRasterWorkspace)
    Dim rasterDataset As ESRI.ArcGIS.Geodatabase.IRasterDataset = rasterWorkspace.OpenRasterDataset(name)
    Dim geoDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset = CType(rasterDataset, ESRI.ArcGIS.Geodatabase.IGeoDataset) ' Explicit Cast

    Return geoDataset

  Catch ex As Exception

    'System.Diagnostics.Debug.WriteLine(ex.Message)
    Return Nothing

  End Try

End Function
#End Region

2.添加shapefile
 
     
[C#]

#region"Add Shapefile Using OpenFileDialog"
 
     
public void AddShapefileUsingOpenFileDialog(ESRI.ArcGIS.Carto.IActiveView activeView)
{
  //parameter check
  if (activeView == null)
  {
    return;
  }

  // Use the OpenFileDialog Class to choose which shapefile to load.
  System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
  openFileDialog.InitialDirectory = "c:";
  openFileDialog.Filter = "Shapefiles (*.shp)|*.shp";
  openFileDialog.FilterIndex = 2;
  openFileDialog.RestoreDirectory = true;
  openFileDialog.Multiselect = false;


  if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
    // The user chose a particular shapefile.

    // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:testcities.shp"
    string shapefileLocation = openFileDialog.FileName;

    if (shapefileLocation != "")
    {
      // Ensure the user chooses a shapefile

 // Create a new ShapefileWorkspaceFactory CoClass to create a new workspace
      ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();

      // System.IO.Path.GetDirectoryName(shapefileLocation) returns the directory part of the string. Example: "C:test"
      ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(shapefileLocation), 0); // Explicit Cast

      // System.IO.Path.GetFileNameWithoutExtension(shapefileLocation) returns the base filename (without extension). Example: "cities"
      ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shapefileLocation));

      ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = new ESRI.ArcGIS.Carto.FeatureLayerClass();
      featureLayer.FeatureClass = featureClass;
      featureLayer.Name = featureClass.AliasName;
      featureLayer.Visible = true;
      activeView.FocusMap.AddLayer(featureLayer);

      // Zoom the display to the full extent of all layers in the map
      activeView.Extent = activeView.FullExtent;
      activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
    }
    else
    {
      // The user did not choose a shapefile.
      // Do whatever remedial actions as necessary
      // System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #1",
      //                                     System.Windows.Forms.MessageBoxButtons.OK,
      //                                     System.Windows.Forms.MessageBoxIcon.Exclamation);
    }
  }
 
      
 else
  {
    // The user did not choose a shapefile. They clicked Cancel or closed the dialog by the "X" button.
    // Do whatever remedial actions as necessary.
    // System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #2",
    //                                      System.Windows.Forms.MessageBoxButtons.OK,
    //                                      System.Windows.Forms.MessageBoxIcon.Exclamation);
  }
}
#endregion
[Visual Basic .NET]
#Region"Add Shapefile Using OpenFileDialog"
 
       
Public Sub AddShapefileUsingOpenFileDialog(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView)

  'parameter check
  If activeView Is Nothing Then

    Return

  End If

  ' Use the OpenFileDialog Class to choose which shapefile to load.
  Dim openFileDialog As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog
  openFileDialog.InitialDirectory = "c:"
  openFileDialog.Filter = "Shapefiles (*.shp)|*.shp"
  openFileDialog.FilterIndex = 2
  openFileDialog.RestoreDirectory = True
  openFileDialog.Multiselect = False

  If openFileDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then

    ' The user chose a particular shapefile.

    ' The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:testcities.shp"
    Dim shapefileLocation As String = openFileDialog.FileName

    If shapefileLocation <> "" Then

' Ensure the user chooses a shapefile

      ' Create a new ShapefileWorkspaceFactory CoClass to create a new workspace
      Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass

      ' System.IO.Path.GetDirectoryName(shapefileLocation) returns the directory part of the string. Example: "C:test"
      Dim featureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = CType(workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(shapefileLocation), 0), ESRI.ArcGIS.Geodatabase.IFeatureWorkspace) ' Explicit Cast

      ' System.IO.Path.GetFileNameWithoutExtension(shapefileLocation) returns the base filename (without extension). Example: "cities"
      Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass = featureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shapefileLocation))

      Dim featureLayer As ESRI.ArcGIS.Carto.IFeatureLayer = New ESRI.ArcGIS.Carto.FeatureLayerClass
      featureLayer.FeatureClass = featureClass
      featureLayer.Name = featureClass.AliasName
      featureLayer.Visible = True
      activeView.FocusMap.AddLayer(featureLayer)

      ' Zoom the display to the full extent of all layers in the map
      activeView.Extent = activeView.FullExtent
      activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, Nothing, Nothing)

    Else

      ' The user did not choose a shapefile.
      ' Do whatever remedial actions as necessary
      ' System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #1", System.Windows.Forms.MessageBoxButtons.OK,  System.Windows.Forms.MessageBoxIcon.Exclamation)

    End If

Else

    ' The user did not choose a shapefile. They clicked Cancel or closed the dialog by the "X" button.
    ' Do whatever remedial actions as necessary.
    ' System.Windows.Forms.MessageBox.Show("No shapefile chosen", "No Choice #2", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation)

  End If

End Sub
#End Region
,需要对输入数据进行有效性和无效性边界值测试,以保证测试的全面性和有效性。 要在 ArcEngine加载 SDE 图层,需要进行以下骤: 1. 创建一个 SdeWorkspaceFactory 对象,用3. 决策表 决策表是一种常用的黑盒测试方法,其基本思想是将软件于连接 SDE 数据库。 2. 使用 SdeWorkspaceFactory 打开 SDE 数据库,并获取 IWorkspace 接口。 3.的输入和输出之间的关系表示为一个决策表,根据决策表进行测试,以保证测试的 使用 IWorkspace 打开 SDE 数据库中的指定版本,并获取 IVersion 接口。 4. 使用 IVersion 打开 S全面性和有效性。在决策表中,需要考虑软件的各种情况和可能性,对输入DE 数据库中的指定数据集,并获取 IFeatureClass 接口。 5. 使用 IFeatureClass 对象创建一个 FeatureLayer数据进行分类和组合,以保证测试的全面性和有效性。 4. 因果图 因果图是 对象。 6. 将 FeatureLayer 对象添加到 MapControl 或 SceneControl 中,即可显示 SDE 数据库中的图一种常用的黑盒测试方法,其基本思想是通过绘制软件的因果图,分析软层。 示例代码如下: ```csharp // 创建 SDE 工作空间工厂 Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance件的输入和输出之间的关系,以保证测试的全面性和有效性。在因果图中,需要考虑软件的各种情况和可能性,对输入数据进行分类和组合,以保证测试的全(factoryType); // 连接 SDE 数据库 IPropertySet connectionProperties = new PropertySet(); connectionProperties.SetProperty("SERVER", "面性和有效性。 5. 代码覆盖率 代码覆盖率是一种常用的白盒测试方法,sde_server_name"); connectionProperties.SetProperty("INSTANCE", "sde_instance_name"); connectionProperties.SetProperty("DATABASE", "sde_database_name"); connectionProperties.SetProperty("USER", "sde_username"); connectionProperties.SetProperty("PASSWORD", "sde_password"); connectionProperties其基本思想是通过对软件的代码进行分析和覆盖测试,以保证测试的全面性和.SetProperty("VERSION", "sde_version_name"); IWorkspace workspace = workspaceFactory.Open(connectionProperties, 0); // 获取 SDE 数据有效性。在代码覆盖率中,需要考虑软件的各种情况和可能性,对代码进行覆盖集 IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("sde测试,以保证测试的全面性和有效性。 6. 路径覆盖率 路径覆盖率是一种_feature_class_name"); // 创建 FeatureLayer 对象 ILayer layer = new FeatureLayerClass(); layer.Name = "SDE Layer"; layer常用的白盒测试方法,其基本思想是通过对软件的路径进行分析和覆盖测试,以.Visible = true; ((IFeatureLayer)layer).FeatureClass = featureClass; // 添加图层MapControl 或 SceneControl 中 axMapControl1.AddLayer(layer); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值