IName和Iworkspace的区别和说明

本文介绍了在ArcGIS中IWorkspace接口和IFeatureDataConverter类的应用。通过IFeatureDataConverter实现了图层数据源的转换,同时解释了工作空间在不同数据库中的类型,并展示了如何从图层获取数据源路径以及进行数据转换的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于两者的区别,在这篇文章上( 两者相关的区别)已经说得很好了,我就在补充一些内容:

   

若进行叠加求交分析时,如果要进行多个图层的叠加,而此时输入的参数是图层,那么我们可以利用示例二,通过图层对象获取其数据源的路径。

实际上在ArcMap中的 Table of Contents(如下图)应该就是这样实现的:(左:图层)(右:数据源)




数据转换:IFeatureDataConverter 接口




例子:

[csharp] view plain copy
  1.   IFeatureLayer featureLayer=pLayer as IFeatureLayer;  
  2.                  IFeatureClass inputFeatureClass = featureLayer.FeatureClass;  
  3.                  IDataset inputDataset = (IDataset)inputFeatureClass;  
  4.               //  IDatasetName inputDatasetName = (IDatasetName)inputDataset.FullName;  
  5.                 IFeatureClassName inputclassName = (IFeatureClassName)inputDataset.FullName ;  
  6.              // Get the layer's selection set.   
  7.              //利用属性打开  
  8.                IPropertySet ps = new PropertySetClass();  
  9.                 ps.SetProperty("DATABASE", fd.SelectedPath);  
  10.                 IWorkspaceFactory wsf = new FileGDBWorkspaceFactoryClass();  
  11.              IWorkspace ws = null;  
  12.               try  
  13.               {  
  14.                   ws = wsf.Open(ps, 0);  
  15.               }  
  16.               catch (Exception e)  
  17.               {  
  18.                     
  19.               }  
  20.                 //设置输出要素属性  
  21.               IDataset ds = (IDataset)ws;  
  22.               IWorkspaceName wsName = (IWorkspaceName)ds.FullName;  
  23.               IFeatureClassName featClsName = new FeatureClassNameClass();  
  24.               IDatasetName dsName = (IDatasetName)featClsName;  
  25.               dsName.WorkspaceName = wsName;  
  26.               dsName.Name = pLayer.Name;  
  27.                 
  28.               //// Use the IFieldChecker interface to make sure all of the field names are valid for a shapefile.   
  29.               IFieldChecker fieldChecker = new FieldCheckerClass();  
  30.               IFields shapefileFields = null;  
  31.               IEnumFieldError enumFieldError = null;  
  32.               fieldChecker.InputWorkspace = inputDataset.Workspace;  
  33.               fieldChecker.ValidateWorkspace = ws;  
  34.                 //out and ref  
  35. //////////////////用Ref型参数时,传入的参数必须先被初始化。而Out则不要要,对Out而言,就必须在方法中对其完成初始化。  
  36. // ///////////////用Ref和Out时都必须注意,在方法的参数和执行方法时,都要加Ref或Out关键字。以满足匹配。  
  37. /////////////////// Out更适合用在要要Return多个返回值的地方,而Ref则用在要要被调出使用的方法修改调出使用者的引用的时候。  
  38.               fieldChecker.Validate(inputFeatureClass.Fields, out enumFieldError, out shapefileFields);  
  39.     
  40.               // At this point, reporting/inspecting invalid fields would be useful, but for this example it's omitted.  
  41.     
  42.  // We also need to retrieve the GeometryDef from the input feature class.   
  43.               int shapeFieldPosition = inputFeatureClass.FindField(inputFeatureClass.ShapeFieldName);  
  44.               IFields inputFields = inputFeatureClass.Fields;  
  45.   
  46.               IField shapeField = inputFields.get_Field(shapeFieldPosition);  
  47.               IGeometryDef geometryDef = shapeField.GeometryDef;  
  48.   
  49.               IGeometryDef pGeometryDef = new GeometryDef();  
  50.               IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;  
  51.               pGeometryDefEdit.GeometryType_2 = inputFeatureClass.ShapeType;  
  52.               pGeometryDefEdit.SpatialReference_2 = mapcontrol3.Map.SpatialReference;  
  53.     
  54.               // Now we can create a feature data converter.   
  55.               IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();  
  56.   
  57.                 
  58.               IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass(inputclassName, null,   
  59.                   null, featClsName, pGeometryDef, shapefileFields, "", 1000, 0);  



IWorkspaceName.WorkspaceFactoryProgID 枚举的常量类型:


• esriDataSourcesGDB.AccessWorkspaceFactory

• esriDataSourcesFile.ArcInfoWorkspaceFactory

• esriDataSourcesFile.CadWorkspaceFactory

• esriDataSourcesGDB.FileGDBWorkspaceFactory

• esriDataSourcesOleDB.OLEDBWorkspaceFactory

• esriDataSourcesFile.PCCoverageWorkspaceFactory

• esriDataSourcesRaster.RasterWorkspaceFactory

• esriDataSourcesGDB.SdeWorkspaceFactory

        • esriDataSourcesFile.ShapefileWorkspaceFactory

        • esriDataSourcesOleDB.TextFileWorkspaceFactory
        • esriDataSourcesFile.TinWorkspaceFactory

        • esriDataSourcesFile.VpfWorkspaceFactory

Iworkspace接口的一些说明:

    

工作空间是空间和非空间数据集的容器,例如特征类、光栅数据集和表。它提供了实例化现有数据集和创建新数据集的方法。工作空间被分类为esriWorkspaceType枚举器指定的类型;FileSystemWorkspace、LocalDatabaseWorkspace RemoteDatabaseWorkspace。shapefile和ArcInfo工作区是文件系统工作空间的示例。存储在Access或文件地理数据库中的个人地理数据库是LocalDatabaseWorkspace的一个示例。存储在Oracle、DB2、SqlServer或Informix等RDBMS中的地理数据库,并通过ArcSDE访问是一个远程数据库工作区示例。

工作空间的工作空间可以被持久化,例如,在一个映射文档中。应用程序可以在将其从持久存储中载入之后调用Open方法,以便连接到工作区,并获得一个对象引用。WorkspaceName name对象可以通过使用IDataset.FullName来从工作空间返回。

IWorkspace接口提供了访问工作空间的各种属性的方法,例如它的连接属性,以及它所包含的数据集的集合。

WorkSpace类不能直接实例化,必须要由IWorkSpaceFactory的Create方法创建。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值