热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【ArcGIS】基于C#的带页面交互功能的AddIn开发

需求关联表记录了4个图层的关键字字段,在AddIn工具输入关联表每一行的OBJECTID,自动搜索4个图层中的相应要素,并缩放至寻找到的
需求

关联表记录了4个图层的关键字字段,在AddIn工具输入关联表每一行的OBJECTID,自动搜索4个图层中的相应要素,并缩放至寻找到的要素上,搜索到的要素高亮显示。

实现

核心代码

// Searcher.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.ArcMap;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;namespace SearchGeometry_addin
{public class Searcher{private IMapDocument pMapDocument &#61; null;private IMap pMap &#61; null;private IFeatureLayer layer_ydpzs &#61; null;private IFeatureLayer layer_ydghxk &#61; null;private IFeatureLayer layer_jsgcxk &#61; null;private IFeatureLayer layer_gctjhs &#61; null;private ITable table_relation &#61; null;private string tableFieldName_ydpzs &#61; "用地批准书号";private string tableFieldName_ydghxk &#61; "建设用地规划许可证证号";private string tableFieldName_jsgcxk &#61; "建设工程规划许可证证号";private string tableFieldName_gctjhs &#61; "建设工程竣工验收条件核实合格证号";private string layerFieldName_ydpzs &#61; "JSYDPZSH";private string layerFieldName_ydghxk &#61; "XKZZH";private string layerFieldName_jsgcxk &#61; "XKZZH";private string layerFieldName_gctjhs &#61; "HGZZH";public Searcher() {InitSearcher();}// 初始化搜索类&#xff0c;从ArcMap页面读取几个图层private void InitSearcher(){pMapDocument &#61; ArcMap.Document as IMapDocument;pMap &#61; pMapDocument.Map[0];for (int i &#61; 0; i < pMap.LayerCount; i&#43;&#43;){IFeatureLayer pFeatureLayer &#61; pMap.get_Layer(i) as IFeatureLayer;switch (pFeatureLayer.Name.ToString()){case "建设用地批准书":this.layer_ydpzs &#61; pFeatureLayer;break;case "建设用地规划许可证":this.layer_ydghxk &#61; pFeatureLayer;break;case "建设工程规划许可证":this.layer_jsgcxk &#61; pFeatureLayer;break;case "建设工程规划条件核实合格证":this.layer_gctjhs &#61; pFeatureLayer;break;}}ITableCollection pTableCollection &#61; pMap as ITableCollection;if (pTableCollection.TableCount > 0) {this.table_relation &#61; pTableCollection.get_Table(0) as ITable;}}// 搜索OBJECTIDpublic void SearchOID(int objectID) {if (layer_ydpzs &#61;&#61; null || layer_ydghxk &#61;&#61; null || layer_jsgcxk &#61;&#61; null || layer_gctjhs &#61;&#61; null || table_relation &#61;&#61; null){return;}IQueryFilter queryFilter &#61; new QueryFilterClass();queryFilter.SubFields &#61; tableFieldName_ydpzs &#43; "," &#43; tableFieldName_ydghxk &#43; ", " &#43; tableFieldName_jsgcxk &#43; ", " &#43; tableFieldName_gctjhs;queryFilter.WhereClause &#61; this.table_relation.OIDFieldName &#43; "&#61;" &#43; objectID.ToString();ICursor tableCursor &#61; this.table_relation.Search(queryFilter, true);int tableIndex_ydpzs &#61; this.table_relation.Fields.FindField(tableFieldName_ydpzs);int tableIndex_ydghxk &#61; this.table_relation.Fields.FindField(tableFieldName_ydghxk);int tableIndex_jsgcxk &#61; this.table_relation.Fields.FindField(tableFieldName_jsgcxk);int tableIndex_gctjhs &#61; this.table_relation.Fields.FindField(tableFieldName_gctjhs);IRow pRow &#61; null;// 清空上次查询高亮选项IActiveView pActiveView &#61; (IActiveView)pMap;pMap.ClearSelection();while ((pRow &#61; tableCursor.NextRow()) !&#61; null){string tableValue_ydpzs &#61; Convert.ToString(pRow.get_Value(tableIndex_ydpzs)).Trim();string tableValue_ydghxk &#61; Convert.ToString(pRow.get_Value(tableIndex_ydghxk)).Trim();string tableValue_jsgcxk &#61; Convert.ToString(pRow.get_Value(tableIndex_jsgcxk)).Trim();string tableValue_gctjhs &#61; Convert.ToString(pRow.get_Value(tableIndex_gctjhs)).Trim();// 用地批准书if (tableValue_ydpzs.Length > 0) {HighLightLayer(tableValue_ydpzs, layer_ydpzs, layerFieldName_ydpzs);ZoomToFeatureLayerSelection(layer_ydpzs);}// 建设用地规划许可if (tableValue_ydghxk.Length > 0){HighLightLayer(tableValue_ydghxk, layer_ydghxk, layerFieldName_ydghxk);ZoomToFeatureLayerSelection(layer_ydghxk);}// 建设工程许可if (tableValue_jsgcxk.Length > 0){HighLightLayer(tableValue_jsgcxk, layer_jsgcxk, layerFieldName_jsgcxk);ZoomToFeatureLayerSelection(layer_jsgcxk);}// 建设工程竣工验收条件核实if (tableValue_gctjhs.Length > 0){HighLightLayer(tableValue_gctjhs, layer_gctjhs, layerFieldName_gctjhs);ZoomToFeatureLayerSelection(layer_gctjhs);}break;}System.Runtime.InteropServices.Marshal.ReleaseComObject(tableCursor);}// 高亮显示public void HighLightLayer(string xkzhStr, IFeatureLayer pFeatureLayer, string layerFieldName) {IQueryFilter queryFilter &#61; new QueryFilterClass();queryFilter.WhereClause &#61; layerFieldName &#43; "&#61;&#39;" &#43; xkzhStr &#43;"&#39;";IFeatureCursor pFeatureCursor &#61; pFeatureLayer.FeatureClass.Search(queryFilter, false);IFeature pFeature &#61; null;while ((pFeature &#61; pFeatureCursor.NextFeature()) !&#61; null){pMap.SelectFeature(pFeatureLayer as ILayer, pFeature);IActiveView pActiveView &#61; (IActiveView)pMap;pActiveView.Refresh();}System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);}// 缩放至所选的要素private void ZoomToFeatureLayerSelection(IFeatureLayer pFeatureLayer){IFeatureSelection featureSelection &#61; pFeatureLayer as IFeatureSelection;if (featureSelection.SelectionSet.Count &#61;&#61; 0) return;IEnumGeometryBind tEnumGeometryBind &#61; new EnumFeatureGeometryClass();tEnumGeometryBind.BindGeometrySource(null, featureSelection.SelectionSet);IEnumGeometry tEnumGeometry &#61; (IEnumGeometry)tEnumGeometryBind;IGeometryFactory tGeometryFactory &#61; new GeometryEnvironmentClass();IGeometry tGeometry &#61; tGeometryFactory.CreateGeometryFromEnumerator(tEnumGeometry);//缓冲处理&#xff0c;使处于边界的元素在视图中能够完全显示ITopologicalOperator mTopologicalOperator &#61; (ITopologicalOperator)tGeometry;IGeometry mPolygonBuffer &#61; mTopologicalOperator.Buffer(0.1) as IGeometry;IActiveView pActiveView &#61; (IActiveView)pMap;pActiveView.Extent &#61; mPolygonBuffer.Envelope;pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, featureSelection, tGeometry.Envelope);}}
}


推荐阅读
author-avatar
手机用户2502929415
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有