arcengine 怎么加载DEM数据呀 求C#代码 5

 我来答
百度网友d15fd33
2013-03-29 · TA获得超过672个赞
知道小有建树答主
回答量:407
采纳率:50%
帮助的人:239万
展开全部
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);
}
匿名用户
2013-03-20
展开全部
//加载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不就行了~
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式