ArcEngine中axMapControl1.AddShapeFile()怎么使用

 我来答
后来的_后来
推荐于2016-08-05 · TA获得超过442个赞
知道小有建树答主
回答量:101
采纳率:0%
帮助的人:105万
展开全部
/// <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();
}
Higer爱Susan
2011-03-16 · TA获得超过917个赞
知道小有建树答主
回答量:508
采纳率:0%
帮助的人:441万
展开全部
axMapControl1.AddShapeFile("C:\arcgis\ArcTutor\Spatial","roads.shp");
axMapControl1.AddShapeFile("路径","文件名")
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式