arcengine 怎么加载DEM数据呀 求C#代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了arcengine 怎么加载DEM数据呀 求C#代码相关的知识,希望对你有一定的参考价值。
http://www.pudn.com/downloads295/sourcecode/graph/detail1322386.html资源站上给你找了一段代码,这个肯定够你用的。
private void button1_Click(object sender, EventArgs e)
//dem数据一般读的是包含所有adf文件的文件夹的名称
OpenFileDialog openFile = new OpenFileDialog();
openFile.ShowDialog();
string path = openFile.FileName;
//判断后缀是否为adf,如果是则读取它路径的上一级作为文件名
string lastname = path.Substring(path.Length - 3, 3);
string frontname = null;//该字符串记录的事排除后缀为adf文件名的路径
if (lastname == "adf")
char[] split = new char[] '\\' ;
string[] array = path.Split(split);
string last = array[array.Length - 1];//XXX.adf
int n = last.Length + 1;
frontname = path.Substring(0, path.Length - n);
if (frontname != null)
ILayer pLayer = openDEMLayer(frontname);
this.axSceneControl1.Scene.AddLayer(pLayer, true);
public static ILayer openDEMLayer(string fullPath)
string pathToWorkspace = System.IO.Path.GetDirectoryName(fullPath);
string demName = System.IO.Path.GetFileName(fullPath);
IWorkspaceFactory pWSFact = new RasterWorkspaceFactoryClass();
IWorkspace pWS = pWSFact.OpenFromFile(pathToWorkspace, 0);
IRasterWorkspace pRasterWorkspace = pWS as IRasterWorkspace;
IRasterLayer pRasterLayer= new RasterLayerClass();
try
IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(demName);
pRasterLayer.CreateFromDataset(pRasterDataset);
catch (Exception err)
MessageBox.Show(err.Message);
return pRasterLayer;
private void button2_Click(object sender, EventArgs e)
IRasterLayer pRasterLayer = new RasterLayerClass();
pRasterLayer = (IRasterLayer)axSceneControl1.Scene.get_Layer(1);//Raster图层
IRaster pRaster = pRasterLayer.Raster;
ISurfaceOp pSurfaceOp = new RasterSurfaceOpClass();
ILayer pLayer = axSceneControl1.Scene.get_Layer(0); //点图层
IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
IGeoDataset pObservers = (IGeoDataset)pFeatureLayer.FeatureClass;
IGeoDataset pGeoDataset = pSurfaceOp.Visibility((IGeoDataset)pRaster, pObservers, esriGeoAnalysisVisibilityEnum.esriGeoAnalysisVisibilityFrequency);
IRasterLayer pNewRasterLayer = new RasterLayerClass();
IRaster pNewRaster = new ESRI.ArcGIS.DataSourcesRaster.Raster();
pNewRaster = (IRaster)pGeoDataset;
pNewRasterLayer.CreateFromRaster(pNewRaster);
pNewRasterLayer.Name = "透视图";
axSceneControl1.Scene.AddLayer(pNewRasterLayer, false);
private void button3_Click(object sender, EventArgs e)
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "shapefile文件(*.shp)|*.shp";
//获取或设置文件对话框显示的初始目录
//openFileDialog1.InitialDirectory = @"D:\Program Files\ArcGIS\Metadata\Data";
//获取或设置一个值,该值指示对话框是否允许选择多个文件
openFileDialog1.Multiselect = false;
// 运行具有指定所有者的通用对话框
DialogResult pDialogResult = openFileDialog1.ShowDialog();
//指定标识符以指示对话框的返回值
if (pDialogResult != DialogResult.OK)
return;
//获取或设置一个包含在文件对话框中选定的文件名的字符串
string pPath = openFileDialog1.FileName;
//返回指定路径字符串的目录信息
string pFolder = System.IO.Path.GetDirectoryName(pPath);
//返回指定路径字符串的文件名和扩展名
string pFileName = System.IO.Path.GetFileName(pPath);
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFC = pFeatureWorkspace.OpenFeatureClass(pFileName);
IFeatureLayer pFLayer = new FeatureLayerClass();
pFLayer.FeatureClass = pFC;
pFLayer.Name = pFC.AliasName;
ILayer pLayer = pFLayer as ILayer;
axSceneControl1.Scene.AddLayer(pLayer, true);
参考技术A //加载DEM数据
private void button1_Click(object sender, EventArgs e)
ISceneGraph pSceneGraph = this.axSceneControl1.SceneGraph;
IScene pScene = pSceneGraph.Scene;
IRasterLayer pRasterLayer =new RasterLayerClass ();
ILayer pLayer ;
this.openFileDialog1.Title ="Raster layer";
this.openFileDialog1.DefaultExt =".TIF";
this.openFileDialog1.Filter ="(*.tif)|*.tif";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
string pPathName = this.openFileDialog1.FileName;
string pPath = pPathName.Substring(0, pPathName.LastIndexOf('\\'));
string fileName = pPathName.Substring(pPath.Length+1, pPathName.Length - pPath.Length-1);
IWorkspaceFactory pwsf = new RasterWorkspaceFactoryClass();
IRasterWorkspace pRasterWorkspace;
if (pwsf.IsWorkspace(pPath))
pRasterWorkspace = pwsf.OpenFromFile(pPath, 0) as IRasterWorkspace;
IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(fileName);
//pRasterDataset.OpenFromFile(pPath);
pRasterLayer.CreateFromDataset(pRasterDataset);
pLayer = pRasterLayer as ILayer;
pScene.AddLayer(pLayer, true);
//pScene.ExaggerationFactor = 6;
pSceneGraph.RefreshViewers();
追问
这个不行呀 我的dem数据是一个文件夹下的几个后缀名是.adf的文件这个根本就打不开
追答这样你就修改成读.adf不就行了~
追问要是有这么简单就好了 不过还是谢谢你了
从DEM数据提取对应点的高程,使用ArcGIS
参考技术A 通过Extract Value to Points从DEM数据中提取所需点的高程。1、将DEM数据文件和一个shapefile点文件(分别命名为“DEM”和“Point”)加载到ArcMap中。
2、在“ArcToolbox”中找到“Extract Value to Points”,双击打开,按下图所示:
点图层选择Point,栅格选择DEM)选择对应层后点击OK开始提取高程。
3、 提取完成后会自动加载“Elevation”图层,在该图层名字上右击选择“Open Attribute Table”后就能从“RASTERVALU”字段中读取出对应点的高程。
以上是关于arcengine 怎么加载DEM数据呀 求C#代码的主要内容,如果未能解决你的问题,请参考以下文章
利用ArcEngine和C#做个小程序,想利用GDAL 提取遥感影像、、、、
C# ArcEngine,如何根据已有的两点的XY坐标,把这条线在地图上显示出来?