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

using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesRaster;

namespace PLOS.ClassLibrary
{
public class ReadData
{
public static List<ILayer> ReadShapLayer(List<string> filePathList)
{
List<ILayer> layerList = new List<ILayer>();

if (filePathList.Count == 0) return null;
else
{
foreach (string path in filePathList)
{
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(path), 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

IFeatureClass pFeatureClass=pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(path));
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureClass;
pFeatureLayer.Name = System.IO.Path.GetFileNameWithoutExtension(path);
layerList.Add(pFeatureLayer as ILayer);
}
return layerList;
}
}

public static List<ILayer> ReadLayerFromAccess(List<string> filePathList)
{
List<ILayer> layerList = new List<ILayer>();

if (filePathList.Count == 0) return null;
else
{
foreach (string path in filePathList)
{
IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset;
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();

while (pDataset is IFeatureClass)
{
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);
pFeatureLayer.Name = pDataset.Name;
ILayer pLayer = pFeatureLayer as ILayer;
layerList.Add(pFeatureLayer as ILayer);
pDataset = pEnumDataset.Next();
}
}
return layerList;
}
}

public static List<ILayer> ReadLayerFromGDB(List<string> filePathList)
{
List<ILayer> layerList = new List<ILayer>();

if (filePathList.Count == 0) return null;
else
{
foreach (string path in filePathList)
{
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(path, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

IEnumDataset pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset;
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();

while (pDataset is IFeatureClass)
{
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);
pFeatureLayer.Name = pDataset.Name;
ILayer pLayer = pFeatureLayer as ILayer;
layerList.Add(pFeatureLayer as ILayer);
pDataset = pEnumDataset.Next();
}
}
return layerList;
}
}

public static List<ILayer> ReadRasterLayer(List<string> filePathList)
{
List<ILayer> layerList = new List<ILayer>();

if (filePathList.Count == 0) return null;
else
{
foreach (string path in filePathList)
{
IRasterLayer pRasterLayer = new RasterLayerClass();
pRasterLayer.CreateFromFilePath(path);
layerList.Add(pRasterLayer as ILayer);
}

return layerList;
}
}

public static List<ILayer> ReadCADLayer(List<string> filePathList)
{
List<ILayer> layerList = new List<ILayer>();

if (filePathList.Count == 0) return null;
else
{
foreach (string path in filePathList)
{
IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactoryClass();
IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName( path), 0) as IFeatureWorkspace;
IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName(path)); 
IFeatureClassContainer pFeatClassContainer = pFeatureDataset as IFeatureClassContainer;

for (int i = 0; i < pFeatClassContainer.ClassCount - 1; i++)
{
IFeatureLayer pFeatureLayer;
IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation) pFeatureLayer = new CadAnnotationLayerClass();
else pFeatureLayer = new FeatureLayerClass();

pFeatureLayer.Name = pFeatClass.AliasName;
pFeatureLayer.FeatureClass = pFeatClass;
layerList.Add(pFeatureLayer as ILayer);
}
}
return layerList;
}
}

public static List<ILayer> ReadXYZfile(List<string> filePathLis)
{
//稍后贴出
}

}
}

你可能感兴趣的:(C#+AE读取Shapefile,raster,gdb,mdb,CAD图,自定义格式坐标数据)