IDataSet接口的使用和矢量图层复制

转载自:http://www.wangchao.net.cn/bbsdetail_72223.html

在ArcGIS的体系内,IDataset是一个非常重要的接口,从这个接口出发,可以访问各个层的数据源,包括矢量和栅格等。在IDataset接口的内部还提供了Workspace的属性,用于访问数据源的Workspace,继而可以从Workspace来得到WorkspaceFactory对象,这一点是非常重要的,因为在一些情况下,需要分辨数据源的类型,比如是Shapefile格式还是Coverage等问题,就可以通过WorkspaceFactory对象的类型类判断了。需要说明的是:在IFeatureLayer接口内还有提供了一个属性(DataSourceType),也可以用于判断数据源的类型,但缺点是类型简单,而且仅限于矢量数据层。
  虽然FeatureClass支持IDataset接口,但为null,因此,如果需要IDataset接口对象,需要从FeatureLayer、RasterLayer等层对象上直接检索。
  ArcGIS似乎没有支持矢量的层的Copy(IDataset虽然有该成员函数,但没有的实现),需要自己写代码,以下是从已有矢量层Copy数据集的代码:
  

/// <summary>
        /// 复制要素图层
        /// </summary>
        /// <param name="pFeatureWorkspace">要素工作空间</param>
        /// <param name="pFeatureLayer">被复制要素图层</param>
        /// <param name="newLayerName">新图层名称</param>
        /// <returns></returns>
        private IFeatureClass copyFeatureClass(IFeatureWorkspace pFeatureWorkspace, IFeatureLayer pFeatureLayer, string newLayerName)
        {
            IFeatureWorkspace _featureWorkspace = pFeatureWorkspace;
            IFeatureLayer _featureLayer = pFeatureLayer;
            if (_featureLayer != null)
            {
                ESRI.ArcGIS.Geodatabase.IWorkspaceEdit _workspaceEdit = _featureWorkspace as ESRI.ArcGIS.Geodatabase.IWorkspaceEdit;
                _workspaceEdit.StartEditing(true);
                _workspaceEdit.StartEditOperation();
                try
                {
                    IFeatureClass _featureClass = _featureWorkspace.CreateFeatureClass(newLayerName, _featureLayer.FeatureClass.Fields, _featureLayer.FeatureClass.CLSID, _featureLayer.FeatureClass.EXTCLSID, _featureLayer.FeatureClass.FeatureType, _featureLayer.FeatureClass.ShapeFieldName, "");

                    ESRI.ArcGIS.Geodatabase.IFeatureCursor _featureCursor = _featureLayer.Search(null, false);
                    ESRI.ArcGIS.Geodatabase.IFeature _feature = _featureCursor.NextFeature();
                    while (_feature != null)
                    {
                        ESRI.ArcGIS.Geodatabase.IFeature _featureNew = _featureClass.CreateFeature();
                        for (int i = 0; i < _featureClass.Fields.FieldCount; i++)
                        {
                            ESRI.ArcGIS.Geodatabase.IField _field = _featureNew.Fields.get_Field(i);
                            if (_field.Editable == true)
                            {
                                _featureNew.set_Value(i, _feature.get_Value(i));
                            }
                        }
                        _featureNew.Store();
                        _feature = _featureCursor.NextFeature();
                    }
                    _workspaceEdit.StopEditOperation();
                    _workspaceEdit.StopEditing(true);
                    return _featureClass;
                }
                catch (System.Exception err)
                {
                    _workspaceEdit.UndoEditOperation();
                    _workspaceEdit.StopEditing(false);
                    throw err;

                }
            }
            return null;
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值