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.DataSourcesGDB;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using System.Collections;
namespace 考试
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
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 barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "打开文件";
dlg.Filter = "(*.mdb)|*.mdb|All Files(*.*)|*.* ";
dlg.ShowDialog();
string path = dlg.FileName;
IWorkspaceFactory pAccessWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset;
pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(path, 0);
IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();
if (pDataset is IFeatureDataset)
{
pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(path, 0);
pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
pEnumDataset1.Reset();
IDataset pDataset1 = pEnumDataset1.Next();
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
{
pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
}
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 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);
}
}
}
{
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 barButtonItem4_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();
}
}
private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
}
private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
}
}
}
AE开发的更多相关文章
- AE开发使用内存图层
AE开发中,有时需要从磁盘中读取一些文件信息如坐标点转为图层并进行分析,此过程并不需要坐标点入库之类的操作,就可以创建一个内存图层解决问题.创建内存图层需要用到InMemoryWorkspaceFac ...
- AE开发能否实现TOC Control里添加多个Data Frame
问题: 在ArcMap中,菜单Insert下Data Frame,可以在TOC中增加Data Frame,在MapControl或者PageLayoutControl下都可以正常显示多个Data Fr ...
- 将AE开发的专题图制作功能发布为WPS
AE开发可以定制化实现ArcGIS的地理处理功能,并实际运用于其他方面的工作,有时候我们还希望将AE开发的功能发布为网络地理信息处理服务(WPS),从而能在Web端更自由便利地调用所需要的地学处理算法 ...
- 【转】.NET+AE开发中常见几种非托管对象的释放
尝试读取或写入受保护的内存.这通常指示其他内存已损坏. 今天在开发时遇到一个问题:" 未处理 System.AccessViolationException Message="尝试 ...
- AE开发技术文档--8种数据访问方法
转自原文 AE开发技术文档--8种数据访问方法 1.shapefile IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new Sha ...
- AE开发概念辨析
樱木 原文 AE开发之概念辨析2,AE开发涉及相关概念,AE开发相关概念 1 AE中的类库 AE总共包括了21个子库,分别是SYSTEM,SYSTEMUI,GEOMETRY,DISPLAY,SERVE ...
- c# 进行AE开发时,如何在地图上定位出一个点
一.文本形式的气泡提示框 由于本人是初学,所以具体的含义尚未弄清楚,直接给出代码吧!
- AE开发 入门教程
此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署应用的方法和步骤. 你可以在下面的目录下找到相应的样例程序: <安装目录>/DeveloperK ...
- WPF+AE开发小结--TOCControl右键菜单删除图层
1.WPF项目中添加toccontrol控件,如何添加,网上有很多方法,可自行搜索,这里不再赘述,代码如下 <Window x:Class="AE.MainWindow" x ...
- AE开发流程
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
随机推荐
- node.js fs,http
error: EventEmitter定义了一个特殊的时间error,它包含了‘错误’的语义,当error被发射时,EventEmitter规定如果没有 响应的监听器,Node.js会把它当做异常,退 ...
- mosh——Linux下基于UDP的SSH连接工具
一:TCP over UDP 1.安装mosh yum install epel-releaseyum install mosh 2.使用客户端连接 mosh user@ip -p 3.查看mosh的 ...
- ubuntu下nodejs源码安装
1.从github选择下载自己要安装的nodejs版本,https://github.com/nodejs/node/releases,我下载的版本是node-9.11.2.tar.gz 2.解压no ...
- [ActionScript 3.0] as3处理xml的功能和遍历节点
as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...
- Windows Service 项目中 Entity Framework 无法加载的问题
Windows Service 项目引用了别的类库项目,别的项目用到了 Entity Framework(通过Nuget引入),但是我的 Windows Service 无法开启,于是我修改了 App ...
- Redis---ZipList(压缩列表)
1.概述 压缩列表是一块连续的内存空间,元素之间紧挨着存储,没有任何冗余空间. Redis 为了节约内存空间使用,zset 和 hash 容器对象在元素个数较少的时候,采用压缩列表 (ziplist) ...
- 实验1 C语言开发环境使用和数据类型、运算符、表达式
♦ 实验结论 PART 1 验证性内容 问题: 1.结尾没有加“:”时回车到下一行的时候再输入下一行的语言首字对齐方式会发生变化,可以对上一行进行检查. (这一点需要在不同软件里面试一下,在机房里的软 ...
- 关于OC中的几种延迟执行方式
第一种: [UIView animateWithDuration: delay: options: animations:^{ self.btn.transform = CGAffineTransfo ...
- 检查iOS项目中是否使用了IDFA
(1)什么是IDFA 关于IDFA,在提交应用到App Store时,iTunes Connect有如下说明: 这里说到检查项目中是否包含IDFA,那如何来对iOS项目(包括第三方SDK)检查是否 ...
- django-suit报错解决-----from suit.apps import DjangoSuitConfig
(py27) [root@test SimpletourDevops]# python manage.py makemigrationsTraceback (most recent call last ...