C#+Arcengine---创建内存图层

分类:技术文档
2009-12-11 14:43阅读(1498)评论(0)

#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创建内存图层(转载)的更多相关文章

  1. AE开发使用内存图层

    AE开发中,有时需要从磁盘中读取一些文件信息如坐标点转为图层并进行分析,此过程并不需要坐标点入库之类的操作,就可以创建一个内存图层解决问题.创建内存图层需要用到InMemoryWorkspaceFac ...

  2. ArcEngine 创建线要素图层

    在创建要素图层的时候,默认的几何类型是Polygon: Dim objectClassDescription As IObjectClassDescription = New FeatureClass ...

  3. ArcEngine临时数据存储 创建内存工作空间

    参考网址,这里 工作中有时候需要使用临时数据,以前都是创建一个默认的shapefile或者gdb,今天发现esri官方帮助文档给出了一个方法,可以创建内存工作空间,代码如下: public stati ...

  4. 使用ZwMapViewOfSection创建内存映射文件总结

    标 题: [原创]使用ZwMapViewOfSection创建内存映射文件总结 作 者: 小覃 时 间: 2012-06-15,02:28:36 链 接: http://bbs.pediy.com/s ...

  5. Java Object 对象创建的方式 [ 转载 ]

    Java Object 对象创建的方式 [ 转载 ] @author http://blog.csdn.net/mhmyqn/article/details/7943411 显式创建 有4种显式地创建 ...

  6. MAPINFO中利用GridMaker工具创建栅格图层

    在工作中需要使用栅格地图,以往都是由研发人员来创建,今天偶然发现Mapinfo中有GridMaker这样一个工具,结合网络搜索自己试了一下,居然做成功了,这里把步骤记录下来,方便以后查看. 1.首先在 ...

  7. 转:内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区[C++][内存管理][转载]

    内存区划分.内存分配.常量存储区.堆.栈.自由存储区.全局区[C++][内存管理][转载] 一. 在c中分为这几个存储区1.栈 - 由编译器自动分配释放2.堆 - 一般由程序员分配释放,若程序员不释放 ...

  8. [转] arcgis Engine创建shp图层

    小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...

  9. ArcGIS 网络分析[8.6] 资料6 创建网络分析图层及进行路径分析

    基于上篇所介绍的内容,就说说如何利用访问到的网络数据集,在Map中添加网络数据集图层.创建网络分析图层中的路径图层,并执行路径分析示例.

随机推荐

  1. JSP 标准标签库(JSTL)之最常用的JSTL标签总结

    JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. Apache Tomcat安装JSTL 库步骤如下: 从Apache的标准标签库中下载的二进包(jakarta-t ...

  2. 利用Keydown事件阻止用户输入

    先了解下各事件的区别 keydown:在控件有焦点的情况下按下键时发生 keypress:在控件有焦点的情况下按下键时发生 keyup:   在控件有焦点的情况下释放键时发生 意义 keypress主 ...

  3. xamarin.android之 Android 4.4+ 获取图片真实路径

    Android 4.4以下 选择图片是可以获取到图片路径的.高于Android 4.4获取图片路径只是获取到一个图片编号. 所以需要针对Android版本进行路径解析: #region 高于 v4.4 ...

  4. Android增加v7 appcompat源码

    1.File ---- Import---- Existing Android Code Into Workspace 2.选择 <sdk>/extras/android/support/ ...

  5. NYOJ--1237最大岛屿

    最大岛屿 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己的的 ...

  6. 怎样用Zbrush中的Curves Tubes创建手指

    之前我们已经能够初步完成了模型的人体躯干,今天的Zbrush教程将继续使用Curves Tubes创建手指,实现更细致的塑形.文章内容仅以fisker老师讲述为例,您也可以按照自己的想法,跟着老师的步 ...

  7. 给定一个整数N,找出一个比N大且最接近N,但二进制权值与该整数相同 的数

    1,问题描述 给定一个整数N,该整数的二进制权值定义如下:将该整数N转化成二进制表示法,其中 1 的个数即为它的二进制权值. 比如:十进制数1717 的二进制表示为:0000 0110 1011 01 ...

  8. URAL 2014 Zhenya moves from parents --线段树

    题意:儿子身无分文出去玩,只带了一张他爸的信用卡,当他自己现金不足的时候就会用信用卡支付,然后儿子还会挣钱,挣到的钱都是现金,也就是说他如果有现金就会先花现金,但是有了现金他不会还信用卡的钱.他每花一 ...

  9. two sum - leetcode

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  10. NVIDIA Physix Unity3D

    提升机器的3D性能 在公司用的台式机看配置不会很差,但是在处理3D方面特别地无奈!例如开个PS,3d MAX就会卡的半死,再多开一会儿就直接未响应,然后机器重启. 真无奈啊,公司暂时也不会给我换电脑或 ...