加载arcgis中图层的方法
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesRaster;
namespace Book
{
public class MapLoad
{
private IMap pMap = null;
public IMap Map
{
set
{
pMap = value;
}
}
/// <summary>
/// 添加Shape文件
/// </summary>
/// <param name="ShapeFilePath">Shape文件所在的目录</param>
/// <param name="ShapeFileName">Shape文件名城,不要后缀,不要目录</param>
public void LoadShapeFile(string ShapeFilePath, string ShapeFileName)
{
Debug.Assert(pMap != null, "Map is null");
IWorkspaceFactory pWorkFactory = new ShapefileWorkspaceFactoryClass();
IPropertySet pSet = new PropertySetClass();
pSet.SetProperty("DATABASE", ShapeFilePath);
IWorkspace pWorkSpace = pWorkFactory.Open(pSet, 0);
IFeatureWorkspace pFeatWorkSpace = pWorkSpace as IFeatureWorkspace;
IFeatureClass pFeatClass = pFeatWorkSpace.OpenFeatureClass(ShapeFileName);
ILayer pLayer = new FeatureLayerClass();
(pLayer as IFeatureLayer).FeatureClass = pFeatClass;
pMap.AddLayer(pLayer);
}
/// <summary>
/// 装载Access数据库数据
/// </summary>
/// <param name="AccessFileName">Access数据库文件名称</param>
/// <param name="FeatClassName">需要装载的图层名称</param>
public void LoadAccessLayer(string AccessFileName, string FeatClassName)
{
Debug.Assert(pMap != null, "Map is null");
IWorkspaceFactory pWorkFactory = new AccessWorkspaceFactoryClass();
IPropertySet pSet = new PropertySetClass();
pSet.SetProperty("DATABASE", AccessFileName);
IWorkspace pWorkSpace = pWorkFactory.Open(pSet, 0);
IFeatureWorkspace pFeatWorkSpace = pWorkSpace as IFeatureWorkspace;
IFeatureClass pFeatClass = pFeatWorkSpace.OpenFeatureClass(FeatClassName);
ILayer pLayer = new FeatureLayerClass();
(pLayer as IFeatureLayer).FeatureClass = pFeatClass;
pMap.AddLayer(pLayer);
}
/// <summary>
/// 装载Coverage数据
/// </summary>
/// <param name="CoverageFilePath">Coverage数据所在的目录名称</param>
/// <param name="FeatClassName">Coverage图层名称,不包含后缀</param>
public void LoadCoverageLayer(string CoverageFilePath, string FeatClassName)
{
Debug.Assert(pMap != null, "Map is null");
IWorkspaceFactory pWorkFactory = new ArcInfoWorkspaceFactoryClass();
IPropertySet pSet = new PropertySetClass();
pSet.SetProperty("DATABASE", CoverageFilePath);
IWorkspace pWorkSpace = pWorkFactory.Open(pSet, 0);
IFeatureWorkspace pFeatWorkSpace = pWorkSpace as IFeatureWorkspace;
IFeatureClass pFeatClass = pFeatWorkSpace.OpenFeatureClass(FeatClassName);
ILayer pLayer = new FeatureLayerClass();
(pLayer as IFeatureLayer).FeatureClass = pFeatClass;
pMap.AddLayer(pLayer);
}
/// <summary>
/// 装载图片文件
/// </summary>
/// <param name="ImageFilePath">图片所在的目录名称</param>
/// <param name="ImageFileName">图片文件名称</param>
public void LoadImageLayer(string ImageFilePath, string ImageFileName)
{
Debug.Assert(pMap != null, "Map is null");
IWorkspaceFactory pWorkFactory = new RasterWorkspaceFactoryClass();
IPropertySet pSet = new PropertySetClass();
pSet.SetProperty("DATABASE", ImageFilePath);
IRasterWorkspace rasterWorkspace = pWorkFactory.Open(pSet, 0) as IRasterWorkspace;
IRasterDataset rasterDS = rasterWorkspace.OpenRasterDataset(ImageFileName);
ILayer pLayer = new RasterLayerClass();
(pLayer as IRasterLayer).CreateFromDataset(rasterDS);
pMap.AddLayer(pLayer);
}
/// <summary>
/// 装载SDE图层
/// </summary>
/// <param name="ServerName">服务器名称</param>
/// <param name="InstanceName">SDE实例名称</param>
/// <param name="DbName">数据库名称</param>
/// <param name="UserName">用户名称</param>
/// <param name="Password">用户口令</param>
/// <param name="SdeVersion">SDE版本</param>
/// <param name="FeatClassName">需要装载的FeatuerClass的名称</param>
/// <param name="Filter">图层过滤条件</param>
public void LoadSDELayer(string ServerName, string InstanceName, string DbName,
string UserName, string Password,string SdeVersion,
string FeatClassName,string Filter)
{
Debug.Assert(pMap != null, "Map is null");
IPropertySet pSet = new PropertySetClass();
pSet.SetProperty("Server", ServerName);
pSet.SetProperty("Instance", InstanceName);
pSet.SetProperty("Database", DbName);
pSet.SetProperty("user", UserName);
pSet.SetProperty("password", Password);
pSet.SetProperty("version", SdeVersion);
LoadSDELayer(pSet, FeatClassName,Filter);
}
public void LoadSDELayer(IPropertySet pSet, string FeatClassName, string Filter)
{
Debug.Assert(pMap != null, "Map is null");
IWorkspaceFactory pWorkFactory = new SdeWorkspaceFactoryClass();
IWorkspace pWorkSpace = pWorkFactory.Open(pSet, 0);
IFeatureWorkspace pFeatWorkSpace = pWorkSpace as IFeatureWorkspace;
IFeatureClass pFeatClass = pFeatWorkSpace.OpenFeatureClass(FeatClassName);
ILayer pLayer = new FeatureLayerClass();
(pLayer as IFeatureLayer).FeatureClass = pFeatClass;
IFeatureLayerDefinition pLayerDef =pLayer as IFeatureLayerDefinition;
pLayerDef.DefinitionExpression = Filter;
pMap.AddLayer(pLayer);
}
public void LoadCadLayer(string CadFileName)
{
}
}
}
本文地址:http://www.45fan.com/dnjc/72764.html