zoukankan      html  css  js  c++  java
  • C#实现CAD数据转shape或mdb

    jojojojo2002 原文C#实现CAD数据转shape或mdb

      本文所指的CAD数据为不带空间参考和扩展数据的数据。如果CAD带了空间参考或是扩展属性数据的话,就要采用图形和属性分离的方法转CAD数据,即图形转完后需要挂接属性数据库。这里就不详细说明了. ArcGIS和CAD对空间数据的归纳有所不同,在AutoCad中,点线面可以在同一个图层中,但是在ArcGIS中,点线面被严格的区分为了point、polyline和polygon三种类型的图层,所以直接用ArcCatalog查看CAD数据时会看到五个图层(点线面、注记和Multipatch) 话不多说了,进入主题吧。

      下面的方法实现了点线面图层转成Shape文件:

    public bool CadDataToShape(string _cadFilePath)
    {        
    //工作空间         
    IWorkspaceFactory pWorkspaceFactory;
    IFeatureWorkspace pFeatureWorkspace;
    IFeatureLayer pFeatureLayer;
    IFeatureDataset pFeatureDataset;//图层对应数据集
    
    ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass feaTofea = new FeatureClassToFeatureClass();
    ESRI.ArcGIS.Geoprocessor.Geoprocessor pGeoPro = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
    
    
    try
    {
    string strFullPath = _cadFilePath;
    int index = strFullPath.LastIndexOf("\");
    string filePath = strFullPath.Substring(0, index);
    string fileName = strFullPath.Substring(index + 1);
    string DataSaveFilePath=@"D:CADToShape";
    
    
    cadGISInfo = new stMdbInfo();
    cadGISInfo.mdbFeaturesName = new List<string>();
    cadGISInfo.mdbname = fileName;
    
    
    //打开cad数据集
    pWorkspaceFactory = new CadWorkspaceFactoryClass();
    pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
    
    
    if (Directory.Exists(DataSaveFilePath + @"\" + fileName))
    {  
        DirectoryInfo dirInfo = new DirectoryInfo(DataSaveFilePath + @"\" + fileName);
        foreach (FileInfo file in dirInfo.GetFiles())
        {
            file.Delete();
        }
        Directory.Delete(DataSaveFilePath + @"\" + fileName);
    }
    Directory.CreateDirectory(DataSaveFilePath + @"\" + fileName);
    cadGISInfo.mdbfilepath = DataSaveFilePath + @"\" + fileName;
    //打开一个要素集
    pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(fileName);

    }
  • 相关阅读:
    yolo_to_onnx ValueError: need more tan 1 value to unpack
    yolo_to_onnx killed
    C++ 实现二维矩阵的加减乘等运算
    Leetcode 1013. Partition Array Into Three Parts With Equal Sum
    Leetcode 1014. Best Sightseeing Pair
    Leetcode 121. Best Time to Buy and Sell Stock
    Leetcode 219. Contains Duplicate II
    Leetcode 890. Find and Replace Pattern
    Leetcode 965. Univalued Binary Tree
    Leetcode 700. Search in a Binary Search Tree
  • 原文地址:https://www.cnblogs.com/arxive/p/6017373.html
Copyright © 2011-2022 走看看