• 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);
  • 相关阅读:
    python的with语句
    flask如何实现https以及自定义证书的制作
    flask及扩展源码解读
    加密的那些事
    SQLALchemy如何查询mysql某个区间内的数据
    集群设备之间的资源共享
    pycryptodom的源码安装
    github创建项目,并提交本地文件
    响应头里的"Last-Modified"值是怎么来的?
    SQL2005 数据库——查看索引
  • 原文地址:https://www.cnblogs.com/jhlong/p/5394477.html
Copyright © 2020-2023  润新知