视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

gis数据格式转换(数据导入)ConvertFeaCls

本文主要对数据导入等里 常用的不同格式数据创建、转换等 进行代码示例。主要用到IFeatureDataConverter.ConvertFeatureClass方法。

 

代码如下,难度不大,只是个技巧问题:

 

函数:

private void ConvertFeaCls(IWorkspace workspaceSource, IWorkspace workspaceTar, stringsSorceFeaClsName, string sTarFeaClsName, string sFeaDTName)

        {

            IFeatureClass feaCls = (workspaceSource asIFeatureWorkspace).OpenFeatureClass(sSorceFeaClsName);

            String shapeFieldName = feaCls.ShapeFieldName;

            int shapeFieldIndex = feaCls.FindField(shapeFieldName);

            IField shapeField = feaCls.Fields.get_Field(shapeFieldIndex);

            IGeometryDef geometryDef = shapeField.GeometryDef;

 

            //create source workspace name  

            IDataset sourceWorkspaceDataset = (IDataset)workspaceSource;

            IWorkspaceName sourceWorkspaceName = (IWorkspaceName)sourceWorkspaceDataset.FullName;

            //create source dataset name  

            IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();

            IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName;

            sourceDatasetName.WorkspaceName = sourceWorkspaceName;

            sourceDatasetName.Name = sSorceFeaClsName;

 

            //create target workspace name  

            IDataset tarWorkspaceDataset = (IDataset)workspaceTar;

            IWorkspaceName tarWorkspaceName = (IWorkspaceName)tarWorkspaceDataset.FullName;

            //create target dataset name  

            IFeatureClassName tarFeatureClassName = new FeatureClassNameClass();

            IDatasetName tarDatasetName = (IDatasetName)tarFeatureClassName;

            tarDatasetName.WorkspaceName = tarWorkspaceName;

            tarDatasetName.Name = sTarFeaClsName;

 

            IFeatureDatasetName tarFeatureDatasetName = new FeatureDatasetNameClass();

            (tarFeatureDatasetName as IDatasetName).WorkspaceName = tarWorkspaceName;

            (tarFeatureDatasetName as IDatasetName).Name = sFeaDTName;

 

            if (string.IsNullOrEmpty(sFeaDTName))

            {

                tarFeatureDatasetName = null;

            }

 

            IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();

            featureDataConverter.ConvertFeatureClass(sourceFeatureClassName, null, tarFeatureDatasetName, tarFeatureClassName, geometryDef, feaCls.Fields, "", 1000, 0);    // Check for errors.

        }

 

 

调用:

           

 IWorkspaceFactory2 workspaceFactory = new ShapefileWorkspaceFactoryClass() asIWorkspaceFactory2;

            IWorkspace workspace = workspaceFactory.OpenFromFile(@"E:\jhl", 0);

            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(Functions.g_ROAD);

           

            IWorkspace workspace2 = workspaceFactory.OpenFromFile(@"E:\", 0);

            DeleteShapeFileIFExist(@"E:\", "test6");

            ConvertFeaCls(workspace, workspace2, Functions.g_ROAD,  "test6",string.Empty);

 

posted @ 2016-04-15 10:48  jhlong  阅读(616)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用