ArcEngine中axMapControl1.AddShapeFile()怎么使用
2个回答
展开全部
/// <summary>
/// 打开shapefile文件
/// </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 = 0; i < pFeatClassContainer.ClassCount - 1; i++)
{
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();
}
/// 打开shapefile文件
/// </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 = 0; i < pFeatClassContainer.ClassCount - 1; i++)
{
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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询