创建要素数据集就是创建FeatureDataset,创建线要素和面要素就是创建FeatureClass,只是其Geometry不同而已。
多看看AE开发的书籍吧。
/// <summary>/// </summary>
/// <param name="aFileName">Shape文件的全路径</param>
/// <param name="axMapControl"></param>
public void OpenFile_ShapeFile(string aFileName, AxMapControl axMapControl)//打开shapefile文件
{
string fullPath
string path//路径
string fileName//文件名
fullPath = aFileName
path = System.IO.Path.GetDirectoryName(fullPath)//路径
fileName = System.IO.Path.GetFileName(fullPath)//文件名
//int fileName_Length = fileName.Length//FileName长
//int lastIndex = fileName.LastIndexOf('\\')//最后一个 \ 的索引
//int fPath_Length = lastIndex//路径长
//int fPath_IndexStart = 0//路径在 fileName 开始处 索引
//int fName_Length = fileName_Length - (fPath_Length + 1)//文件名长(包含后缀名)
//int fName_IndexStart = fileName.LastIndexOf('\\') + 1//文件名在 fileName 开始处 索引
//string fPath = fileName.Substring(fPath_IndexStart, fPath_Length)//路径
//string fName = fileName.Substring(fName_IndexStart, fName_Length)//文件名
axMapControl.AddShapeFile(path, fileName)
axMapControl.ActiveView.Refresh()
}
下面是一些常用的加载数据的函数 可直接 使用,希望对你有帮助!
/// <summary>
/// 打开*.lyr文件
/// </summary>
/// <param name="fileNames">打开lyr文件的全路径</param>
/// <param name="axMapControl"></param>
public void OpenFile_lyrFile(string aFileName, AxMapControl axMapControl)//打开*.lyr文件
{
axMapControl.AddLayerFromFile(aFileName)
axMapControl.ActiveView.Refresh()
}
/// <summary>
/// 打开 CAD 文件
/// </summary>
/// <param name="aFileName">打开CAD文件的全路径</param>
/// <param name="axMapControl"></param>
public void OpenFile_CADFile(string aFileName, AxMapControl axMapControl)//打开CAD文件
{
string fullPath
string path//路径
string fileName//文件名
fullPath = aFileName
path = System.IO.Path.GetDirectoryName(fullPath)//路径
fileName = System.IO.Path.GetFileName(fullPath)//文件名
//打开CAD数据集
IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactoryClass()
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(path, 0)
//打开一个要素集
IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(fileName)
//IFeaturClassContainer可以管理IFeatureDataset中的每个要素类
IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset
//对CAD文件中的要素进行遍历处理
IFeatureLayer pFeatureLayer
for (int i = 0i <pFeatClassContainer.ClassCount - 1i++)
{
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
axMapControl.Map.AddLayer(pFeatureLayer)
}
axMapControl.ActiveView.Refresh()
}
/// <summary>
/// 打开 栅格文件
/// </summary>
/// <param name="aFileNames">打开 栅格文件 文件的全路径</param>
/// <param name="axMapControl"></param>
public void OpenFile_RasterFile(string aFileName, AxMapControl axMapControl)//打开 栅格文件
{
string fullPath
string path//路径
string fileName//文件名
fullPath = aFileName
path = System.IO.Path.GetDirectoryName(fullPath)//路径
fileName = System.IO.Path.GetFileName(fullPath)//文件名
IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass()
IRasterWorkspace pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(path, 0)
IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName)
IRasterLayer pRasterLayer = new RasterLayerClass()
pRasterLayer.CreateFromDataset(pRasterDataset)
axMapControl.Map.AddLayer(pRasterLayer)
axMapControl.ActiveView.Refresh()
}
/// <summary>
/// 打开*.mxd文件
/// </summary>
/// <param name="aFileName">打开mxd文件的全路径</param>
/// <param name="axMapControl"></param>
public void OpenFile_mxdFile(string aFileName, AxMapControl axMapControl)//打开*.mxd文件
{
axMapControl.LoadMxFile(aFileName)
axMapControl.ActiveView.Refresh()
}
/// <summary>
/// 打开 TIN 文件
/// </summary>
/// <param name="aFolderName">TIN文件夹</param>
/// <param name="axMapControl">axMapControl</param>
/// <returns></returns>
public void OpenFile_TINFolder(string aFolderName, AxMapControl axMapControl)//打开TIN文件
{
string pathToWorkspace = System.IO.Path.GetDirectoryName(aFolderName)
string tinName = System.IO.Path.GetFileName(aFolderName)
IWorkspaceFactory pWorkspaceFactory = new TinWorkspaceFactoryClass()
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pathToWorkspace, 0)
ITinWorkspace pTinWorkspace = pWorkspace as ITinWorkspace
ITinLayer pTinLayer = new TinLayerClass()
if (pTinWorkspace.get_IsTin(tinName))
{
ITin pTin = pTinWorkspace.OpenTin(tinName)
pTinLayer.Dataset = pTin
pTinLayer.ClearRenderers()
pTinLayer.Name = tinName
}
axMapControl.AddLayer(pTinLayer)
axMapControl.ActiveView.Refresh()
}
ArcEngine是一种用于开发GIS应用程序的软件开发工具包。它提供了一系列的API,可以帮助开发者快速开发出功能强大的GIS应用程序。ArcEngine可以帮助开发者实现地图绘制、地理数据处理、地理信息系统管理等功能。ArcEngine可以帮助开发者在地图上添加文本,并且可以指定文本的位置。开发者可以使用ArcEngine的API来指定文本的位置,以及文本的大小、颜色等属性。此外,ArcEngine还提供了一些预定义的文本样式,可以帮助开发者快速添加文本。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)