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)
{
//稍后贴出
}

}
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值