Arc Engine下数据的加载处理
1.加载Shapefile数据
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer; //获取当前路径和文件名
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*";
dlg.Title = "Open Shapefile data";
dlg.ShowDialog();
string strFullPath = dlg.FileName;
if (strFullPath == "") return;
int Index = strFullPath.LastIndexOf("\\");
string filePath = strFullPath.Substring(, Index);
string fileName = strFullPath.Substring(Index + ); //打开工作空间并添加shp文件
pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, );
pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
2.加载栅格数据
IWorkspaceFactory pWorkspaceFactory;
IRasterWorkspace pRasterWorkspace; OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Layer File(*.lyr)|*.jpg;*.bmp;*.tiff";
dlg.Title = "Open Raster Data File";
dlg.ShowDialog();
//获取当前路径和文件名
string strFullPath = dlg.FileName;
if (strFullPath == "") return;
int Index = strFullPath.LastIndexOf("\\");
string fileName = strFullPath.Substring(Index + );
string filePath = strFullPath.Substring(, Index); pWorkspaceFactory = new RasterWorkspaceFactoryClass();
pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(filePath, );
IRasterDataset pRasterDataset = (IRasterDataset)pRasterWorkspace.OpenRasterDataset(fileName);
IRasterLayer pRasterLayer = new RasterLayerClass();
pRasterLayer.CreateFromDataset(pRasterDataset);
axMapControl1.Map.AddLayer(pRasterLayer);
axMapControl1.ActiveView.Refresh();
3.加载CAD数据
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset;
//获取当前路径和文件名
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "CAD(*.dwg)|*.dwg|All Files(*.*)|*.*";
dlg.Title = "Open CAD Data file";
dlg.ShowDialog();
string strFullPath = dlg.FileName;
if (strFullPath == "") return;
int Index = strFullPath.LastIndexOf("\\");
string filePath = strFullPath.Substring(, Index);
string fileName = strFullPath.Substring(Index + );
//打开CAD数据集
pWorkspaceFactory = new CadWorkspaceFactoryClass();
pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, );
//打开一个要素集
pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(fileName);
//IFeaturClassContainer可以管理IFeatureDataset中的每个要素类
IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset;
//对CAD文件中的要素进行遍历处理
for (int i = ; i < pFeatClassContainer.ClassCount - ; 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;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
}
4.加载PersonGeodatabase数据
IWorkspaceFactory pAccessWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset; //获取当前路径和文件名
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Personal Geodatabase(*.mdb)|*.mdb|All Files(*.*)|*.*";
dlg.Title = "Open PersonGeodatabase file";
dlg.ShowDialog();
string strFullPath = dlg.FileName;
if (strFullPath == "") return; //打开personGeodatabase,并添加图层
pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
//打开工作空间并遍历数据集
IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(strFullPath, );
IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();
//如果数据集是IFeatureDataset,则遍历它下面的子类
if (pDataset is IFeatureDataset)
{
pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(strFullPath, );
pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
pEnumDataset1.Reset();
IDataset pDataset1 = pEnumDataset1.Next();
//如果子类是FeatureClass,则添加到axMapControl1中
if (pDataset1 is IFeatureClass)
{
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
else
{
MessageBox.Show("No FeatureLayer!");
}
}
else
{
pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass("图层名");
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
5.加载SDE数据库数据
public ESRI.ArcGIS.Geodatabase.IWorkspace arcSDEWorkspaceOpen(String server, String instance, String user, String password, String database, String version)
{
try
{
// Create and populate the property set
ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
propertySet.SetProperty("SERVER", server);
propertySet.SetProperty("INSTANCE", instance);
propertySet.SetProperty("DATABASE", database);
propertySet.SetProperty("USER", user);
propertySet.SetProperty("PASSWORD", password);
propertySet.SetProperty("VERSION", version); ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 workspaceFactory;
workspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2)new SdeWorkspaceFactoryClass();
return workspaceFactory.Open(propertySet, );
}
catch (Exception e)
{
throw new Exception(String.Format("arcSDEWorkspaceOpen: {0}", e.Message), e);
}
} IWorkspace pWorkspace = arcSDEWorkspaceOpen("计算机名", "", "数据库用户", "密码", "", "sde.DEFAULT"); IFeatureWorkspace pFeattureWS = (IFeatureWorkspace)pWorkspace;
IFeatureClass pFeatureClass = pFeattureWS.OpenFeatureClass("图层名");
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureClass; axMapControl1.AddLayer(pFeatureLayer);
axMapControl1.Refresh();
6、文件地理数据库加载
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset;
string filePath = @"D:\My Documents\ArcGIS\新建文件地理数据库.gdb";
string filename = "haha";
//打开personGeodatabase,并添加图层
IWorkspaceFactory pAccessWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
//打开工作空间并遍历数据集
IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(filePath, );
IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();
//如果数据集是IFeatureDataset,则遍历它下面的子类
if (pDataset is IFeatureDataset)
{
pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(filePath, );
pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
pEnumDataset1.Reset();
IDataset pDataset1 = pEnumDataset1.Next();
//如果子类是FeatureClass,则添加到axMapControl1中
if (pDataset1 is IFeatureClass)
{
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(filename);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Red = ;
pRgbColor.Green = ;
pRgbColor.Blue = ;
pRgbColor.Transparency = ;
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pRgbColor;
pRgbColor.Transparency = ;
pLineSymbol.Color = pRgbColor;
pLineSymbol.Width = ;
pFillSymbol.Outline = pLineSymbol;
ISimpleRenderer pSimpleRender = new SimpleRendererClass();
pSimpleRender.Symbol = pFillSymbol as ISymbol;
IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
pGeoFeatureLayer.Renderer = pSimpleRender as IFeatureRenderer;
pFeatureLayer = pGeoFeatureLayer as IFeatureLayer;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
}
Arc Engine下数据的加载处理的更多相关文章
- ArcGIS Engine中数据的加载 (转)
1.加载Shapefile数据 1 IWorkspaceFactory pWorkspaceFactory; 2 IFeatureWorkspace pFeatureWorkspace; 3 IFea ...
- 分页插件思想:pc加载更多功能和移动端下拉刷新加载数据
感觉一个人玩lol也没意思了,玩会手机,看到这个下拉刷新功能就写了这个demo! 这个demo写的比较随意,咱不能当做插件使用,基本思想是没问题的,要用就自己封装吧! 直接上代码分析下吧! 布局: & ...
- 页面滚动动态加载数据,页面下拉自动加载内容 jquery
<!DOCTYPE=html> <html> <head> < script src="js/jquery.js" type=" ...
- Jquery页面滚动动态加载数据,页面下拉自动加载内容
<!DOCTYPE=html> <html> <head> <script src="js/jquery.js" type="t ...
- JS实现-页面数据无限加载
在手机端浏览网页时,经常使用一个功能,当我们浏览京东或者淘宝时,页面滑动到底部,我们看到数据自动加载到列表.之前并不知道这些功能是怎么实现的,于是自己在PC浏览器上模拟实现这样的功能.先看看浏览效果: ...
- EF如何操作内存中的数据以及加载相关联表的数据:延迟加载、贪婪加载、显示加载
之前的EF Code First系列讲了那么多如何配置实体和数据库表的关系,显然配置只是辅助,使用EF操作数据库才是每天开发中都需要用的,这个系列讲讲如何使用EF操作数据库.老版本的EF主要是通过Ob ...
- 省市数据递归加载到TreeView
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- WinForm ListView虚拟模式加载数据 提高加载速度
将VirtualMode 属性设置为 true 会将 ListView 置于虚拟模式.控件不再使用Collection.Add()这种方式来添加数据,取而代之的是使用RetrieveVirtualIt ...
- Echarts使用及动态加载图表数据 折线图X轴数据动态加载
Echarts简介 echarts,缩写来自Enterprise Charts,商业级数据图表,一个纯JavaScript的图表库,来自百度...我想应该够简洁了 使用Echarts 目前,就官网的文 ...
随机推荐
- ie,火狐,谷歌 select清除默认样式 设置新的样式
select { border: solid 1px #000; /*Chrome和Firefox里面的边框是不一样的,所以复写了一下*/ appearance:none; -moz-appearan ...
- 类的序列化和反序列化(ObjectOutputStream和ObjectInputStream)
1.需要序列化的类 import java.io.Serializable; /** * 必须继承 Serializable 接口才能实现序列化 */ public class Employee im ...
- Visual Studio 2010 插件之Resharper
这一系列不是对每个功能的中文帮助,而是我对开发中可能涉及的功能需求,利用Resharper来完成.有些是Visual Studio有的,但是做的不好,有些是没有而Resharper发明的.总的目的都只 ...
- php版本引起的const问题
刚刚遇到一个问题,类中定义了一个常量: const USER = ['aa', 'bb', 'cc']; 在类中的静态函数中调用以上常量不会出错.网站中所有的网页均能正常打开. 而当push到线上后, ...
- In和Out指令
In和Out OUT 0FAH,AL(它是指从AL中输出一个字节到0FAH的一个端口吗?) OUT DX,AL OUT 0FAH,AX(AX是一个字为什么也能输出到0FAH所指的8位端口中呢?) ...
- 我 && yii2(日志埋点,邮件提醒)
今天试着把yii2 的日志,如果发送邮件的形式实现,具体实现如下 1.环境介绍 lnmp php5.6, mysql5.5, lnmp1.2 yii2-advanced 2.配置文件的编写 在fron ...
- html5 图片上传,支持图片预览、压缩、及进度显示,兼容IE6+及标准浏览器
以前写过上传组件,见 打造 html5 文件上传组件,实现进度显示及拖拽上传,兼容IE6+及其它标准浏览器,对付一般的上传没有问题,不过如果是上传图片,且需要预览的话,就力有不逮了,趁着闲暇时间,给上 ...
- 安装swoole 扩展,在phpinfo中显示,但是php -m 中不显示的问题
步骤如下: 1 首先找到php.ini的目录:linux命令:find / -name php.ini 我的路径如下:
- Git之VS2010实践
对于我们经常在VS2010下编程的开发人员来说,强大的SCM工具Git貌似对我们很陌生.对于Git,我在我的另一篇博客<Git学习笔记>中已做过介绍,下面我再简单介绍一下Git在VS201 ...
- UNIX 系统调用函数errno返回值搜集(in updating )
当Unix系统级函数遇到错误时,它们会典型地返回-1,并设置全局整数变量errno来表示什么出错了 阅读redis源码的时候,发现如果对系统级函数出错时的errno比较熟悉,写起程序来会游刃有余不少. ...