C# ArcEngine创建内存图层(转载)
#region 在内存中创建图层
/// <summary>
/// 在内存中创建图层
/// </summary>
/// <param name="DataSetName">数据集名称</param>
/// <param name="AliaseName">别名</param>
/// <param name="SpatialRef">空间参考</param>
/// <param name="GeometryType">几何类型</param>
/// <param name="PropertyFields">属性字段集合</param>
/// <returns>IfeatureLayer</returns>
public static IFeatureLayer CreateFeatureLayerInmemeory(string DataSetName, string AliaseName, ISpatialReference SpatialRef, esriGeometryType GeometryType, IFields PropertyFields)
{
IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;
ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open();
IField oField = new FieldClass();
IFields oFields = new FieldsClass();
IFieldsEdit oFieldsEdit = null;
IFieldEdit oFieldEdit = null;
IFeatureClass oFeatureClass = null;
IFeatureLayer oFeatureLayer = null;
try
{
oFieldsEdit = oFields as IFieldsEdit;
oFieldEdit = oField as IFieldEdit;
for (int i = 0; i < PropertyFields.FieldCount; i++)
{
oFieldsEdit.AddField(PropertyFields.get_Field(i));
}
IGeometryDef geometryDef = new GeometryDefClass();
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.AvgNumPoints_2 = 5;
geometryDefEdit.GeometryType_2 = GeometryType;
geometryDefEdit.GridCount_2 = 1;
geometryDefEdit.HasM_2 = false;
geometryDefEdit.HasZ_2 = false;
geometryDefEdit.SpatialReference_2 = SpatialRef;
geometryDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();//没有这一句就报错,说尝试读取或写入受保护的内存。
geometryDefEdit.SpatialReference.SetDomain(-200, 200, -200, 200);//没有这句就抛异常来自HRESULT:0x8004120E。
oFieldEdit.Name_2 = "SHAPE";
oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
oFieldEdit.GeometryDef_2 = geometryDef;
oFieldEdit.IsNullable_2 = true;
oFieldEdit.Required_2 = true;
oFieldsEdit.AddField(oField);
oFeatureClass = (inmemWor as IFeatureWorkspace).CreateFeatureClass(DataSetName, oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
(oFeatureClass as IDataset).BrowseName = DataSetName;
oFeatureLayer = new FeatureLayerClass();
oFeatureLayer.Name = AliaseName;
oFeatureLayer.FeatureClass = oFeatureClass;
}
catch
{
}
return oFeatureLayer;
}
#endregion
下面就是根据采集的坐标点创建点内存图层:
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
IFieldsEdit curFileds = new FieldsClass();
IFieldEdit curField = new FieldClass();
curField = new FieldClass();
curField.Name_2 = "名称";
curField.Type_2 = esriFieldType.esriFieldTypeString;
curFileds.AddField(curField);
curField = new FieldClass();
curField.Name_2 = "经度";
curField.Type_2 = esriFieldType.esriFieldTypeDouble;
curFileds.AddField(curField);
curField = new FieldClass();
curField.Name_2 = "纬度";
curField.Type_2 = esriFieldType.esriFieldTypeDouble;
curFileds.AddField(curField);
pFeatureLayer = CreateFeatureLayerInmemeory("Position", "采集点", new UnknownCoordinateSystemClass(), esriGeometryType.esriGeometryPoint, curFileds as IFields);
p_axMap.AddLayer(pFeatureLayer as ILayer);
IFeatureCursor FeatureCursor;
IFeature pFeature;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
pFeature = pFeatureClass.CreateFeature();
IQueryFilter pQueryFilter = new QueryFilterClass();
FeatureCursor = pFeatureClass.Search(pQueryFilter, true);
pQueryFilter.WhereClause = null;
pFeature = FeatureCursor.NextFeature();
pFeature.set_Value(0, str1);
pFeature.set_Value(1, x);
pFeature.set_Value(2, y);
IEnvelope pEnvelope = new EnvelopeClass();
//如果双击的对象是一个点,这样子才能够缩放到该点
pEnvelope.PutCoords(0, 0, 0.3, 0.3);//确定envelope大小
IPoint xpoint = new PointClass();
xpoint.PutCoords(x, y);
pFeature.Shape = xpoint;
pFeature.Store();
//设置颜色
IRgbColor pcolor = new RgbColorClass();
pcolor.Red = 255;
pcolor.Green = 0;
pcolor.Blue = 0;
//设置图形
ISimpleMarkerSymbol psm = new SimpleMarkerSymbolClass();
psm.Style = esriSimpleMarkerStyle.esriSMSCircle;
psm.Size = 10;
psm.Color = pcolor;
(pFeatureLayer as IFeatureSelection).SelectionSymbol = (ISymbol)psm;
(pFeatureLayer as IFeatureSelection).SetSelectionSymbol = true;
(pFeatureLayer as IFeatureSelection).SelectionSet.Add(pFeature.OID);
pEnvelope.CenterAt(xpoint);//地图缩放到该点
p_axMap.Extent = pEnvelope;
p_axMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pFeatureLayer, null);
p_axMap.ActiveView.ScreenDisplay.UpdateWindow();
C# ArcEngine创建内存图层(转载)的更多相关文章
- AE开发使用内存图层
AE开发中,有时需要从磁盘中读取一些文件信息如坐标点转为图层并进行分析,此过程并不需要坐标点入库之类的操作,就可以创建一个内存图层解决问题.创建内存图层需要用到InMemoryWorkspaceFac ...
- ArcEngine 创建线要素图层
在创建要素图层的时候,默认的几何类型是Polygon: Dim objectClassDescription As IObjectClassDescription = New FeatureClass ...
- ArcEngine临时数据存储 创建内存工作空间
参考网址,这里 工作中有时候需要使用临时数据,以前都是创建一个默认的shapefile或者gdb,今天发现esri官方帮助文档给出了一个方法,可以创建内存工作空间,代码如下: public stati ...
- 使用ZwMapViewOfSection创建内存映射文件总结
标 题: [原创]使用ZwMapViewOfSection创建内存映射文件总结 作 者: 小覃 时 间: 2012-06-15,02:28:36 链 接: http://bbs.pediy.com/s ...
- Java Object 对象创建的方式 [ 转载 ]
Java Object 对象创建的方式 [ 转载 ] @author http://blog.csdn.net/mhmyqn/article/details/7943411 显式创建 有4种显式地创建 ...
- MAPINFO中利用GridMaker工具创建栅格图层
在工作中需要使用栅格地图,以往都是由研发人员来创建,今天偶然发现Mapinfo中有GridMaker这样一个工具,结合网络搜索自己试了一下,居然做成功了,这里把步骤记录下来,方便以后查看. 1.首先在 ...
- 转:内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区[C++][内存管理][转载]
内存区划分.内存分配.常量存储区.堆.栈.自由存储区.全局区[C++][内存管理][转载] 一. 在c中分为这几个存储区1.栈 - 由编译器自动分配释放2.堆 - 一般由程序员分配释放,若程序员不释放 ...
- [转] arcgis Engine创建shp图层
小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...
- ArcGIS 网络分析[8.6] 资料6 创建网络分析图层及进行路径分析
基于上篇所介绍的内容,就说说如何利用访问到的网络数据集,在Map中添加网络数据集图层.创建网络分析图层中的路径图层,并执行路径分析示例.
随机推荐
- 在MVC3中使用code first生成数据局库并操作数据库
1.建立Users和UserInfos两个实体类 对应的是数据库中的表 public class User { //类名+Id(User+Id)组成的字符串在数据库表中会设置该字段是主键且是按1的增量 ...
- SSH服务器拒绝了密码,xshell连不上虚拟机怎么办
用Xshell链接虚拟机的时候,出现下面情况: 这是sshd的设置不允许root用户用密码远程登录 解决方案: 修改 vim /etc/ssh/sshd_config 找到# Authenticati ...
- Codeforces Round #254 DZY Loves Colors
题意:输入n, m ; 有n给位置, 初始时第i个位置的color为i, colorfulness为0. 有m次操作,一种是把成段的区域color更新为x, 对于更新的区域,每个位置(令第i ...
- 打造属于自己的vim利器
毋庸置疑vim很强大,然而没有插件的话对于大多数人来说他的界面是很不友好的.下面简单写一下我对vim的配置 这是我的vim配置,装的插件不是很多,对我来说已经够用.左边的侧边栏是NERD插件提供的,还 ...
- gre网络细节
一.OpenStack网络设备的命名规律: 1.TenantA的router和Linux网络命名空间qrouter名称 root@controller:~# neutron --os-tenant-n ...
- codeforces 442B B. Andrey and Problem(贪心)
题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...
- HDU 2082 找单词 --生成函数
跟上题是一个思路:http://www.cnblogs.com/whatbeg/p/3728545.html 只不过是上一题的扩展. 代码: #include <iostream> #in ...
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- android应用中去掉标题栏的方法
现在我坚定的认为写技术博客对自己有很大的帮助,写博客给自己一个学而思的机会. 在Android中去掉标题栏有三种方法,它们也有各自的特点. 1.在代码里实现 this.requestWindowFea ...
- smarty中三种变量的访问方式
在模板中smarty有三种变量,第一种,php分配的变量,第二种配置文件里的变量,第三种,PHP全局数组里的变量,配置文件里变量的访问方式可以是{#bgcolor#},"#"必须紧 ...