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开发流程的更多相关文章

  1. 2022年Web前端开发流程和学习路线(详尽版)

    前言 前端侧重于人机交互和用户体验,后端侧重于业务逻辑和大规模数据处理.理论上,面向用户的产品里,所有问题(包括产品.设计.后端.甚至看不见的问题)的表现形式,都会暴露在前端,而只有部分问题(数据问题 ...

  2. Linux下服务器端开发流程及相关工具介绍(C++)

    去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...

  3. 小谈Scrum敏捷开发流程

    一晃眼,有两年没有写博客了,回顾前两年,各种奔波,各种忙碌,也有不少的收获.从今天开始,我要把这些收获都分享在这里. 其实这两年,对我影响最大的是开发流程.总所周知,一个好的开发流程,对于项目的进行, ...

  4. 我理解的Sitecore开发流程

    Sitecore是一个强大的支持快速开发CMS建站的平台,进入sitecore后台可以看到 它主要有3个元素: 1.Templates模板 Data template:类似于面向对象编程中的类或结构体 ...

  5. C++的性能C#的产能?! - .Net Native 系列《二》:.NET Native开发流程详解

    之前一文<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATIVE初窥> 获得很多朋友支持和鼓励,也更让我坚定做这项技术的推广者,希望能让更多的朋友了解这项技术,于是先从官方 ...

  6. git开发流程、常用命令及工具、TortoiseGit使用及常见问题

    根据我最近使用git的一些经历,git是基于分支的版本控制工具,分支有远程分支和本地分支. 一.开发流程 - 从远程服务器的master,clone一份项目文件到本地,然后本地master的基础上br ...

  7. 软件开发流程 Software development process

    软件开发流程(Software development process)即软件设计思路和方法的一般过程,包括设计软件的功能和实现的算法和方法.软件的总体结构设计和模块设计.编程和调试.程序联调和测试以 ...

  8. AE开发使用内存图层

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

  9. AE开发能否实现TOC Control里添加多个Data Frame

    问题: 在ArcMap中,菜单Insert下Data Frame,可以在TOC中增加Data Frame,在MapControl或者PageLayoutControl下都可以正常显示多个Data Fr ...

随机推荐

  1. 基于MVC框架layui分页控件实现前端分页信息写法

    详细链接:https://shop499704308.taobao.com/?spm=a1z38n.10677092.card.11.594c1debsAGeak@{ ViewBag.Title = ...

  2. powerviot install in sharepoint 2013

    1.在app server安装powerviot for sharepoint,然后进行配置powerviot 2.powerviot配置之前需要设置security token service以及e ...

  3. LeetCode题解-147 对链表进行插入排序

    对链表进行插入排序. 插入排序的动画演示如上.从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示). 每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中. 插 ...

  4. 深入理解 js this 绑定机制

    函数调用位置 与词法作用域相反的是,this的指向由函数运行时决定,它是动态的,随着函数调用位置变化而变化. 要理解 this,首先要理解调用位置:调用位置就是函数在代码中被调用的位置(而 不是声明的 ...

  5. 转载,自己留着看eclipse 快捷键

    Eclipse中10个最有用的快捷键组合  一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升.    ...

  6. leetcode-165-比较版本号

    题目描述: 比较两个版本号 version1 和 version2.如果 version1 > version2 返回 1,如果 version1 < version2 返回 -1, 除此 ...

  7. 【learning】vim爆改记 (如何让vim用起来像devc++)

    由于本蒟蒻NOIP人品大爆发,能去冬令营,故准备开始练习使用linux下的IDE:vim 在dalao DTZ的帮助下,我装好了vim,并做了最初的配置. 然而........好难用啊,怎么和devc ...

  8. javascript数据结构与算法--二叉树遍历(先序)

    javascript数据结构与算法--二叉树遍历(先序) 先序遍历先访问根节点, 然后以同样方式访问左子树和右子树 代码如下: /* *二叉树中,相对较小的值保存在左节点上,较大的值保存在右节点中 * ...

  9. (转)Python数据分析之numpy学习

    原文:https://www.cnblogs.com/nxld/p/6058572.html https://morvanzhou.github.io/tutorials/data-manipulat ...

  10. Java之集合(二十五)ConcurrentHashMap

    转载请注明源出处:http://www.cnblogs.com/lighten/p/7520808.html 1.前言 本章介绍使用的最频繁的并发集合类之一ConcurrentHashMap,之前介绍 ...