资源站上给你找了一段代码,这个肯定够你用的。
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)
}
安装时 发现vs2019与sdk 10.2 不兼容,10.2只能兼容vs2010或者vs02012,解决方式:
1 先安装 arcgis license 10.2.2 这个必须在C盘 其他程序可以安装在别的盘
2 安装 arcgis desktop 10.2.2
3 安装 arcgis engine 10.2.2
4 安装 arcobjects SDK时 报错 不与vs2019兼容
① 修改注册表
增加注册表InstallDir 路径选到vs2019安装目录下的IDE
增加注册表ShellFolder 路径选到vs2019安装目录下的Professional
② 然后在安装SDK 就可以安装了
5 打开vs2019 发现 还是不能读取arcengine 需要以下设置:
① 打开
分为ItemTemplates和ProjectTemplates
② 将其里面CSharp和VisualBasic中的ArcGIS文件夹 复制粘贴到文档中VS2019目录下
分别对应Visual C#和Visual Basic 复制粘贴
6 完成!
参考文件:
① https://www.bilibili.com/video/av584263241/
② https://www.bilibili.com/video/BV1C64y1c7eZ?p=2
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)