zoukankan      html  css  js  c++  java
  • C#+AE读取Shapefile,raster,gdb,mdb,CAD图,自定义格式坐标数据

     

    C#+AE读取Shapefile,raster,gdb,mdb,CAD图,自定义格式坐标数据

     7人阅读 评论(0) 收藏 举报
    [csharp] view plaincopy
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Text;  
    4. using ESRI.ArcGIS.Carto;  
    5. using ESRI.ArcGIS.DataSourcesGDB;  
    6. using ESRI.ArcGIS.Display;  
    7. using ESRI.ArcGIS.esriSystem;  
    8. using ESRI.ArcGIS.Geodatabase;  
    9. using ESRI.ArcGIS.Geometry;  
    10. using ESRI.ArcGIS.Controls;  
    11. using ESRI.ArcGIS.DataSourcesFile;  
    12. using ESRI.ArcGIS.DataSourcesRaster;  
    13.   
    14. namespace PLOS.ClassLibrary  
    15. {  
    16. public class ReadData  
    17. {  
    18. public static List<ILayer> ReadShapLayer(List<string> filePathList)  
    19. {  
    20. List<ILayer> layerList = new List<ILayer>();  
    21.   
    22. if (filePathList.Count == 0) return null;  
    23. else  
    24. {  
    25. foreach (string path in filePathList)  
    26. {  
    27. IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();  
    28. IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(path), 0);  
    29. IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;  
    30.   
    31. IFeatureClass pFeatureClass=pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(path));  
    32. IFeatureLayer pFeatureLayer = new FeatureLayerClass();  
    33. pFeatureLayer.FeatureClass = pFeatureClass;  
    34. pFeatureLayer.Name = System.IO.Path.GetFileNameWithoutExtension(path);  
    35. layerList.Add(pFeatureLayer as ILayer);  
    36. }  
    37. return layerList;  
    38. }  
    39. }  
    40.   
    41. public static List<ILayer> ReadLayerFromAccess(List<string> filePathList)  
    42. {  
    43. List<ILayer> layerList = new List<ILayer>();  
    44.   
    45. if (filePathList.Count == 0) return null;  
    46. else  
    47. {  
    48. foreach (string path in filePathList)  
    49. {  
    50. IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();  
    51. IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0);  
    52. IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;  
    53.   
    54. IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset;  
    55. pEnumDataset.Reset();  
    56. IDataset pDataset = pEnumDataset.Next();  
    57.   
    58. while (pDataset is IFeatureClass)  
    59. {  
    60. IFeatureLayer pFeatureLayer = new FeatureLayerClass();  
    61. pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);  
    62. pFeatureLayer.Name = pDataset.Name;  
    63. ILayer pLayer = pFeatureLayer as ILayer;  
    64. layerList.Add(pFeatureLayer as ILayer);  
    65. pDataset = pEnumDataset.Next();  
    66. }  
    67. }  
    68. return layerList;  
    69. }  
    70. }  
    71.   
    72. public static List<ILayer> ReadLayerFromGDB(List<string> filePathList)  
    73. {  
    74. List<ILayer> layerList = new List<ILayer>();  
    75.   
    76. if (filePathList.Count == 0) return null;  
    77. else  
    78. {  
    79. foreach (string path in filePathList)  
    80. {  
    81. IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass();  
    82. IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0);  
    83. IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;  
    84.   
    85. IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset;  
    86. pEnumDataset.Reset();  
    87. IDataset pDataset = pEnumDataset.Next();  
    88.   
    89. while (pDataset is IFeatureClass)  
    90. {  
    91. IFeatureLayer pFeatureLayer = new FeatureLayerClass();  
    92. pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);  
    93. pFeatureLayer.Name = pDataset.Name;  
    94. ILayer pLayer = pFeatureLayer as ILayer;  
    95. layerList.Add(pFeatureLayer as ILayer);  
    96. pDataset = pEnumDataset.Next();  
    97. }  
    98. }  
    99. return layerList;  
    100. }  
    101. }  
    102.   
    103. public static List<ILayer> ReadRasterLayer(List<string> filePathList)  
    104. {  
    105. List<ILayer> layerList = new List<ILayer>();  
    106.   
    107. if (filePathList.Count == 0) return null;  
    108. else  
    109. {  
    110. foreach (string path in filePathList)  
    111. {  
    112. IRasterLayer pRasterLayer = new RasterLayerClass();  
    113. pRasterLayer.CreateFromFilePath(path);  
    114. layerList.Add(pRasterLayer as ILayer);  
    115. }  
    116.   
    117. return layerList;  
    118. }  
    119. }  
    120.   
    121. public static List<ILayer> ReadCADLayer(List<string> filePathList)  
    122. {  
    123. List<ILayer> layerList = new List<ILayer>();  
    124.   
    125. if (filePathList.Count == 0) return null;  
    126. else  
    127. {  
    128. foreach (string path in filePathList)  
    129. {  
    130. IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactoryClass();  
    131. IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName( path), 0) as IFeatureWorkspace;  
    132. IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName(path));   
    133. IFeatureClassContainer pFeatClassContainer = pFeatureDataset as IFeatureClassContainer;  
    134.   
    135. for (int i = 0; i < pFeatClassContainer.ClassCount - 1; i++)  
    136. {  
    137. IFeatureLayer pFeatureLayer;  
    138. IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);  
    139. if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation) pFeatureLayer = new CadAnnotationLayerClass();  
    140. else pFeatureLayer = new FeatureLayerClass();  
    141.   
    142. pFeatureLayer.Name = pFeatClass.AliasName;  
    143. pFeatureLayer.FeatureClass = pFeatClass;  
    144. layerList.Add(pFeatureLayer as ILayer);  
    145. }  
    146. }  
    147. return layerList;  
    148. }  
    149. }  
    150.   
    151. public static List<ILayer> ReadXYZfile(List<string> filePathLis)  
    152. {  
    153. //稍后贴出  
    154. }  
    155.   
    156. }  
    157. }  
  • 相关阅读:
    06.章节页面接口开发
    05.课程主页面三个接口开发
    python高级(六)——用一等函数实现设计模式
    python高级(五)—— python函数(一等对象)
    python高级(四)—— 文本和字节序列(编码问题)
    python高级(三)—— 字典和集合(泛映射类型)
    python高级——目录
    python高级(二)—— python内置序列类型
    python高级(一)—— python数据模型(特殊方法)
    python实现百度地图API获取某地址的经纬度
  • 原文地址:https://www.cnblogs.com/xianyin05/p/3086561.html
Copyright © 2011-2022 走看看