AE开发流程
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesFile;
using System.Collections;
namespace AE考核
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void dockPanel2_Click(object sender, EventArgs e)
        {
}
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            IMap pMap = axMapControl1.Map;
            IActiveView pActiveView = pMap as IActiveView;
            IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            IPoint point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            ITopologicalOperator pTOpo = point as ITopologicalOperator;
            double length;
            length = ConvertPixelsToMapUnits(pActiveView, 4);
            IGeometry pBuffer = pTOpo.Buffer(length);
            IGeometry pGeomentry = pBuffer.Envelope;
            ISelectionEnvironment pSelEnv = new SelectionEnvironment();//新建选择环境
            IRgbColor pColor = new RgbColor();
            pColor.Red = 255;
            pSelEnv.DefaultColor = pColor;//设置高亮颜色
            pMap.SelectByShape(pBuffer, pSelEnv, false);//选择图
            axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
List<IFeature> S = RecSelectFetures(pFeatureLayer);
            sFeature = S;
            if (S.Count > 0)
            {
                treeList1.ClearNodes();
                try
                {
                    treeList1.BeginUpdate();
                    int k = 0;
                    for (int i = 0; i < S.Count; i++)
                    {
                        for (int j = 0; j < S[i].Fields.FieldCount; j++)
                        {
                            IField pFiled = S[i].Fields.get_Field(j);
                            treeList1.Columns.Add();
                            treeList1.Columns[j].Caption = pFiled.Name;
                            treeList1.Columns[j].VisibleIndex = j;
                        }
                        string sFirseFidValue = S[i].get_Value(0).ToString();
                        treeList1.AppendNode(new object[] { sFirseFidValue }, null);
                        for (int m = 1; m < S[i].Fields.FieldCount; m++)
                        {
                            object FieldValue;
                            if (S[i].Class.Fields.get_Field(m).Name == "SHAPE")
                            {
                                FieldValue = S[i].Shape.GeometryType.ToString();
                            }
                            else
                            {
                                FieldValue = S[i].get_Value(m).ToString();
                            }
                            treeList1.Nodes[k][m] = FieldValue;
                        }
                        k = k + 1;
                    }
                }
catch (Exception exc)
                {
                    MessageBox.Show("错误" + exc.ToString());
                }
                finally
                {
                    treeList1.EndUpdate();
                }
            }
        }
private void dockPanel2_Container_Paint(object sender, PaintEventArgs e)
        {
}
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OpenFileDialog opd = new OpenFileDialog();
            opd.Title = "打开文件";
            opd.Filter = "(*.mdb)|*.mdb|All Files(*.*)|*.* ";
            opd.ShowDialog();
            string pPath = opd.FileName;
            IWorkspaceFactory pFactory = new FileGDBWorkspaceFactory();
            string pFileName = pPath;
            //打开工作空间
            IWorkspaceFactory pAccessWorkspaceFactory;
            pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
            IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(pPath, 0);
            //打开要素集
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
            pEnumDataset.Reset();
            IDataset pDataset = pEnumDataset.Next();
            pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(pPath, 0);
            IFeatureDataset pFeatureDataset;
            pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name
);
            IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
            IDataset pDataset1 = pEnumDataset1.Next();
            IFeatureClass pFC = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name
);
            //创建图层 
            IFeatureLayer pFLayer = new FeatureLayerClass();
            pFLayer.FeatureClass = pFC;
            //关联图层和要素图层 
            pFLayer.Name
= pFC.AliasName;
            ILayer pLayer = pFLayer as ILayer;
            IMap pMap = axMapControl1.Map;
            //添加到地图空间
            pMap.AddLayer(pLayer);
}
private void Form1_Load(object sender, EventArgs e)
        {
            this.axTOCControl1.SetBuddyControl(this.axMapControl1);
        }
List<IFeature> sFeature;
        private List<IFeature> RecSelectFetures(IFeatureLayer pFeatureLayer)
        {
            List<IFeature> pFeatures = new List<IFeature>();
            if (pFeatureLayer != null)
            {
                IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
                pFeatureSelection.Clear();
                axMapControl1.Refresh();
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                IGeometry pGeometry = axMapControl1.TrackRectangle();
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry = pGeometry;
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pSpatialFilter, false);
                IFeature pFeature = pFeatureCursor.NextFeature();
                pFeatureSelection.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew;
                while (pFeature != null)
                {
                    pFeatureSelection.Add(pFeature);
                    pFeatures.Add(pFeature);
                    pFeature = pFeatureCursor.NextFeature();
                }
                axMapControl1.ActiveView.Refresh();
            }
            return pFeatures;
        }
private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
        {
            IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft;
            IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;
            int x1, x2, y1, y2;
            pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);
            pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);
            double pixelExtent = x2 - x1;
            double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
            double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
            return pixelUnits * sizeOfOnePixel;
        }
private void CopyAttribute(IFeature pSourceFea, IFeature pTargetFea)
        {
            IFields pSourceFlds = pSourceFea.Fields;
            for (int i = 0; i < pSourceFlds.FieldCount; i++)
            {
                IField pSourceFld = pSourceFlds.get_Field(i);
                if ((pSourceFld.Type == esriFieldType.esriFieldTypeOID) ||
                    (pSourceFld.Type == esriFieldType.esriFieldTypeGeometry) ||
                    (pSourceFld.Type == esriFieldType.esriFieldTypeBlob))
continue;
string sSourceVal = pSourceFea.get_Value(i).ToString();
                if (string.IsNullOrEmpty(sSourceVal))
                    continue;
int iTargetFldIndex = pTargetFea.Fields.FindField(pSourceFld.Name);
                if (iTargetFldIndex >= 0)
                    pTargetFea.set_Value(iTargetFldIndex, sSourceVal);
            }
        }
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string serror = "";
            for (int i = 0; i < sFeature.Count; i++)
            {
                IFeature pFeature = sFeature[i];
                IFeatureClass pSourceFeaCls = pFeature.Class as IFeatureClass;
                if (pSourceFeaCls == null)
                    return;
                IWorkspace pSourceWks = (pSourceFeaCls as IDataset).Workspace;
                ISpatialReference pSourceSpr = ((pSourceFeaCls as IDataset) as IGeoDataset).SpatialReference;
//string localFilePath, fileNameExt, newFileName, FilePath; 
                SaveFileDialog sfd = new SaveFileDialog();
                //设置文件类型 
                sfd.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*";
                sfd.CreatePrompt = false;
                if (sfd.ShowDialog() != DialogResult.OK)
                    return;
//得到文件名和路径
                string strShppath = System.IO.Path.GetDirectoryName(sfd.FileName);
                string strShpFile = System.IO.Path.GetFileNameWithoutExtension(sfd.FileName);
//创建shp工作空间
                IWorkspaceFactory pWksFac = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeaWks = (IFeatureWorkspace)pWksFac.OpenFromFile(strShppath, 0);
//创建字段集
                IFields pFlds = new FieldsClass();
                IFieldsEdit pFldsEdt = (IFieldsEdit)pFlds;
                //创建基础字段
                IField pFld = new FieldClass();
                IFieldEdit pFldEdt = (IFieldEdit)pFld;
                string strShapeFieldName = "shape";
                pFldEdt.Name_2 = strShapeFieldName;
                pFldEdt.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //为esriFieldTypeGeometry类型的字段创建几何定义
                IGeometryDef pGeoDef = new GeometryDefClass();
                IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
                pGeoDefEdit.GeometryType_2 = pSourceFeaCls.Fields.get_Field(1).GeometryDef.GeometryType;//设置shp文件的几何类型
                pGeoDefEdit.SpatialReference_2 = pSourceSpr;//设置shp文件的空间参考
                pFldEdt.GeometryDef_2 = pGeoDef;
                pFldsEdt.AddField(pFld);
                //创建其他字段
                for (int j = 2; j < pSourceFeaCls.Fields.FieldCount; j++)
                {
                    pFld = new FieldClass();
                    pFldEdt = (IFieldEdit)pFld;
                    pFldEdt.Name_2 = pSourceFeaCls.Fields.get_Field(j).Name;
                    pFldEdt.Type_2 = pSourceFeaCls.Fields.get_Field(j).Type;
                    pFldsEdt.AddField(pFld);
                }
                //创建空白shp文件
                pFeaWks.CreateFeatureClass(strShpFile, pFlds, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");
                //打开Shapefile,获取FeaCls
                IWorkspace pTargetWks = pWksFac.OpenFromFile(strShppath, 0);
                if (pTargetWks == null)
                    return;
                IFeatureClass pTargetFeaCls = (pTargetWks as IFeatureWorkspace).OpenFeatureClass(strShpFile);
int ifeaCount = pSourceFeaCls.FeatureCount(null);
                IFeatureCursor pFeaCur = pSourceFeaCls.Search(null, false);
                IFeature pSourceFea = pFeaCur.NextFeature();
                if (pSourceFea == null)
                    return;
                bool blok = false;
IWorkspaceEdit pWksEdt = pTargetWks as IWorkspaceEdit;
                pWksEdt.StartEditing(false);
                pWksEdt.RedoEditOperation();
                try
                {
                    while (pSourceFea != null)
                    {
                        IFeature pTargetFea = pTargetFeaCls.CreateFeature();
                        if (pTargetFea != null)
                        {
                            pTargetFea.Shape = pSourceFea.Shape;
                            CopyAttribute(pSourceFea, pTargetFea);
                            pTargetFea.Store();
                        }
                        pSourceFea = pFeaCur.NextFeature();
                    }
                    blok = true;
                }
                catch (Exception exc)
                {
                    serror = exc.Message;
                }
                finally
                {
                    if (blok)
                        pWksEdt.StopEditOperation();
                    else
                        pWksEdt.AbortEditOperation();
                    pWksEdt.StopEditing(blok);
                    if (blok)
                        MessageBox.Show("导出成功,共计导出" + ifeaCount + "条记录");
                    else
                        MessageBox.Show("导出失败" + serror);
                }
            }
        }
        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)//保存
        {
            try
            {
                string sMxdFileName = axMapControl1.DocumentFilename;
                IMapDocument pMapDocument = new MapDocumentClass();
                if (sMxdFileName != null && axMapControl1.CheckMxFile(sMxdFileName))
                {
                    if (pMapDocument.get_IsReadOnly(sMxdFileName))
                    {
                        MessageBox.Show("本地图文档是只读,不能保存");
                        pMapDocument.Close();
                        return;
                    }
                }
                else
                {
                    SaveFileDialog pSaveFileDialog = new SaveFileDialog();
                    pSaveFileDialog.Title = "选择保存路径";
                    pSaveFileDialog.OverwritePrompt = true;
                    pSaveFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt";
                    pSaveFileDialog.RestoreDirectory = true;
                    if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        sMxdFileName = pSaveFileDialog.FileName;
                    }
                    else
                    {
                        return;
                    }
                }
                pMapDocument.New(sMxdFileName);
                pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents);
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                pMapDocument.Close();
                MessageBox.Show("保存文档成功");
}
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private ISymbol GetSymbol(IColor pColor)
        {
            ISymbol pSymbol;
            ISimpleFillSymbol pSymbolFillSymbol = new SimpleFillSymbolClass();
            pSymbolFillSymbol.Color = pColor;
            pSymbolFillSymbol.Outline.Width = 0.4;
            pSymbol = pSymbolFillSymbol as ISymbol;
            return pSymbol;
        }
private IRandomColorRamp GetColorRamp(int size)
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();
            pRandomColorRamp.StartHue = 10;
            pRandomColorRamp.EndHue = 300;
            pRandomColorRamp.MaxSaturation = 100;
            pRandomColorRamp.MinSaturation = 0;
            pRandomColorRamp.MaxValue = 100;
            pRandomColorRamp.MinValue = 0;
            pRandomColorRamp.Size = size;
            bool ok = true;
            pRandomColorRamp.CreateRamp(out ok);
            return pRandomColorRamp;
        }
private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
              IMap pMap = this.axMapControl1.ActiveView.FocusMap;
            if (pMap.LayerCount == 0)
            {
                MessageBox.Show("地图为空,请加载地图!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            IGeoFeatureLayer pGeoLayer = this.axMapControl1.get_Layer(0) as IGeoFeatureLayer;
            ITable pTable = pGeoLayer.FeatureClass as ITable;
            ICursor pCursor;
            IQueryFilter pQueryFilter = new QueryFilter();
            pQueryFilter.AddField("OBJECTID");
            pCursor = pTable.Search(pQueryFilter, true);//获取字段
            IEnumerator pEnumreator;
//获取字段中各要素属性唯一值
            IDataStatistics pDataStatistics = new DataStatisticsClass();
            pDataStatistics.Field = "OBJECTID";//获取统计字段
            pDataStatistics.Cursor = pCursor;
            pEnumreator = pDataStatistics.UniqueValues;
            int fieldcount = pDataStatistics.UniqueValueCount;//唯一值个数,以此确定颜色带范围
IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass();
            pUniqueValueR.FieldCount = 1;//单值渲染
            pUniqueValueR.set_Field(0, "OBJECTID");//渲染字段
            IEnumColors pEnumColor = GetColorRamp(fieldcount).Colors;
            pEnumColor.Reset();
while (pEnumreator.MoveNext())
            {
                string value = pEnumreator.Current.ToString();
                if (value != null)
                {
                    IColor pColor = pEnumColor.Next();
                    ISymbol pSymbol = GetSymbol(pColor);
                    pUniqueValueR.AddValue(value, "OBJECTID", pSymbol);
                    //pUniqueValueR.set_Symbol(value, pSymbol);
}
}
            pGeoLayer.Renderer = pUniqueValueR as IFeatureRenderer;
            this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            this.axTOCControl1.Update();
        }
    }
}
AE开发流程的更多相关文章
- 2022年Web前端开发流程和学习路线(详尽版)
		前言 前端侧重于人机交互和用户体验,后端侧重于业务逻辑和大规模数据处理.理论上,面向用户的产品里,所有问题(包括产品.设计.后端.甚至看不见的问题)的表现形式,都会暴露在前端,而只有部分问题(数据问题 ... 
- Linux下服务器端开发流程及相关工具介绍(C++)
		去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ... 
- 小谈Scrum敏捷开发流程
		一晃眼,有两年没有写博客了,回顾前两年,各种奔波,各种忙碌,也有不少的收获.从今天开始,我要把这些收获都分享在这里. 其实这两年,对我影响最大的是开发流程.总所周知,一个好的开发流程,对于项目的进行, ... 
- 我理解的Sitecore开发流程
		Sitecore是一个强大的支持快速开发CMS建站的平台,进入sitecore后台可以看到 它主要有3个元素: 1.Templates模板 Data template:类似于面向对象编程中的类或结构体 ... 
- C++的性能C#的产能?! - .Net Native 系列《二》:.NET Native开发流程详解
		之前一文<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATIVE初窥> 获得很多朋友支持和鼓励,也更让我坚定做这项技术的推广者,希望能让更多的朋友了解这项技术,于是先从官方 ... 
- git开发流程、常用命令及工具、TortoiseGit使用及常见问题
		根据我最近使用git的一些经历,git是基于分支的版本控制工具,分支有远程分支和本地分支. 一.开发流程 - 从远程服务器的master,clone一份项目文件到本地,然后本地master的基础上br ... 
- 软件开发流程 Software development process
		软件开发流程(Software development process)即软件设计思路和方法的一般过程,包括设计软件的功能和实现的算法和方法.软件的总体结构设计和模块设计.编程和调试.程序联调和测试以 ... 
- AE开发使用内存图层
		AE开发中,有时需要从磁盘中读取一些文件信息如坐标点转为图层并进行分析,此过程并不需要坐标点入库之类的操作,就可以创建一个内存图层解决问题.创建内存图层需要用到InMemoryWorkspaceFac ... 
- AE开发能否实现TOC Control里添加多个Data Frame
		问题: 在ArcMap中,菜单Insert下Data Frame,可以在TOC中增加Data Frame,在MapControl或者PageLayoutControl下都可以正常显示多个Data Fr ... 
随机推荐
- .netcore与vue的学习笔记001
			1.dnc的js引用 需要引用的js文件要放在解决方案下的wwwroot目录下.否则将无法获取到指定js文件,出现404错误 2.vue的相关运用 0)通过new Vue并传入object来实例化一个 ... 
- C# RSA加解密和MD5加密
			1.RSA加密 /// <summary> /// 加密处理 /// </summary> /// <param name="content"> ... 
- 第五章 ReentrantLock源码解析1--获得非公平锁与公平锁lock()
			最常用的方式: int a = 12; //注意:通常情况下,这个会设置成一个类变量,比如说Segement中的段锁与copyOnWriteArrayList中的全局锁 final Reentrant ... 
- pageadmin CMS网站制作教程:栏目单页内容如何修改
			pageadmin CMS网站制作教程:栏目单页内容如何修改 一般情况下,如公司介绍,联系方式等介绍内页面都属于单页,单页内容可以直接在栏目设置界面进行修改,如下 1.对栏目单页内容进行设置,登录后台 ... 
- go get golang.org/x/net 安装失败的解决方法!
			GO语言在github.com上建立了自己的项目,对应的包如果不能下载,那么可以到这里去下载,比如:"go get golang.org/x/net"不能下载这个包,那么我们可以访 ... 
- python os.path 的使用
			import os #该文件所在位置:D:\第1层\第2层\第3层\第4层\第5层\test11.py path1 = os.path.dirname(__file__) print(path1)#获 ... 
- 微信小程序 Unexpected end of JSON input/Unexpected token o in JSON at position 1
			原因JSON.parse无法识别某些url中的特殊字符,所以报错 mistakes.js中 nextBtn:function(){ var nextData = this.data.dataNextI ... 
- MySQL(外键变种)
			day58 外键的变种 a. 用户表和部门表 用户: 不唯一 1 alex ... 
- docker镜像基本操作一
			获取镜像 首先说明一下如何从Docker hub中获取高质量的镜像,从Docker镜像库获取镜像的命令是docker pull .其命令格式为: docker pull [选项] [Docker Re ... 
- 在vue项目中使用swiper2.7.6
			$ npm install swiper@2.7.6 --save-dev npm WARN rollback Rolling back node-pre-gyp@0.10.0 failed (thi ... 
