查询矩形范围内的"点"要素

步骤

  1,首先在含有主视图控件 ESRI.ArcGIS.Controls.AxMapControl mapCtrl_main 的主类中定义一个 IEnvelope 成员变量,用于记录鼠标在主视图控件画好的轮廓

1 private ESRI.ArcGIS.Geometry.IEnvelope mainInvelope = null; //(主视图上)
2 public ESRI.ArcGIS.Geometry.IEnvelope MainInvelopeValue {
3     get {
4     return mainInvelope;
5     }
6 }

并设置成外界可访问的属性.

  2,在该类中定义一bool变量,以控制查询

1 private bool startMainInvelope = false; //标识在主视图上画轮廓矩形,以进行该范围内点查询.

  3,在 mapCtrl_main 的 OnMouseDown 响应事件中,控制轮廓的顺畅画好

 1 if (1 == e.button && startMainInvelope) {   //在主视图上画轮廓.
 2     mainInvelope = mapCtrl_main.TrackRectangle();
 3     try {
 4         if (!mainInvelope.IsEmpty)
 5         Engine.App_Code.Draw.DrawSymbol(mapCtrl_main.Map, mainInvelope);
 6     }
 7     catch (System.Exception ex) {
 8         MessageBox.Show(ex.Message);
 9     }
10 }

其中用到画轮廓的辅助方法定义为:

 1 /// <summary>
 2         /// 画轮廓.
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e">根据IEnvelope对象画轮廓.</param>
 6         public static void DrawSymbol(ESRI.ArcGIS.Carto.IMap map, ESRI.ArcGIS.Geometry.IEnvelope e) {
 7             ESRI.ArcGIS.Carto.IGraphicsContainer hawkGC = (ESRI.ArcGIS.Carto.IGraphicsContainer)map;
 8             ESRI.ArcGIS.Carto.IActiveView aView = (ESRI.ArcGIS.Carto.IActiveView)hawkGC;
 9             hawkGC.DeleteAllElements();
10
11             ESRI.ArcGIS.Carto.IElement recEle = (ESRI.ArcGIS.Carto.IElement)new ESRI.ArcGIS.Carto.RectangleElementClass();
12             recEle.Geometry = e;
13             ESRI.ArcGIS.Display.ISimpleLineSymbol outLine = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
14             outLine.Color = ColorPaint(255, 255);
15             outLine.Width = 2;
16
17             //填充样式.
18             ESRI.ArcGIS.Display.ISimpleFillSymbol fillSym = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
19             fillSym.Color = ColorPaint(255, 0);
20             fillSym.Outline = outLine;
21
22             ESRI.ArcGIS.Carto.IFillShapeElement fillShape = (ESRI.ArcGIS.Carto.IFillShapeElement)recEle;
23             fillShape.Symbol = fillSym;
24             hawkGC.AddElement((ESRI.ArcGIS.Carto.IElement)fillShape, 0);
25             aView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, null, null);
26         }

  4,在查询窗口中,用 GetLayerByName 方法定位好待查询的点要素图层(方法定义为)

 1 /// <summary>
 2         /// 根据图层名获取图层.
 3         /// </summary>
 4         /// <param name="map"></param>
 5         /// <param name="layerName">图层名称.</param>
 6         /// <returns></returns>
 7         public static ESRI.ArcGIS.Carto.ILayer GetLayerByName(ESRI.ArcGIS.Carto.IMap map, string layerName) {
 8             ESRI.ArcGIS.Carto.IEnumLayer enunLayer = map.get_Layers(null, false);
 9             enunLayer.Reset();
10             ESRI.ArcGIS.Carto.ILayer resultLayer = null;
11             while ((resultLayer = enunLayer.Next()) != null) {
12                 if (resultLayer.Name.Equals(layerName)) {
13                     break;
14                 }
15             }
16             return resultLayer;
17         }

  5,查询窗口实现查询的所有代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9
10 namespace Engine {
11     public partial class fQueryInvelopePoints : Form {
12         private ESRI.ArcGIS.Carto.IMap map = null;
13         private fMain fMain = null;
14         public fQueryInvelopePoints(fMain fMain, ESRI.ArcGIS.Carto.IMap map) {
15             this.fMain = fMain;
16             this.map = map;
17             InitializeComponent();
18         }
19
20         /// <summary>
21         /// 查询指定矩形范围内的点要素.
22         /// </summary>
23         /// <param name="envelope">指定的矩形范围.</param>
24         /// <param name="featureClass">待查询的要素.</param>
25         /// <returns>返回结果的游标</returns>
26         public ESRI.ArcGIS.Geodatabase.IFeatureCursor GetAllFeaturesFromPointSearchInGeoFeatureLayer(ESRI.ArcGIS.Geometry.IEnvelope envelope, ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass) {
27             if (featureClass == null)
28                 return null;
29             ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
30             spatialFilter.Geometry = envelope;
31             spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
32             spatialFilter.GeometryField = featureClass.ShapeFieldName;
33             return featureClass.Search(spatialFilter, false);
34         }
35
36         private void fQueryInvelopePoints_Load(object sender, EventArgs e) {
37             Engine.App_Code.Layer_Assist.InitLayers(map, cbox_layer);
38         }
39
40         private void btn_query_Click(object sender, EventArgs e) {
41             lsbox.Items.Clear();    //清空原始数据.
42             ESRI.ArcGIS.Carto.ILayer lyr = Engine.App_Code.Layer_Assist.GetLayerByName(map, cbox_layer.Text);
43             if (lyr is ESRI.ArcGIS.Carto.IFeatureLayer) {   //矢量数据.
44                 ESRI.ArcGIS.Carto.IFeatureLayer fLyr = (ESRI.ArcGIS.Carto.IFeatureLayer)lyr;
45                 ESRI.ArcGIS.Geometry.IEnvelope selEnvelope = fMain.MainInvelopeValue;
46                 //获取矩形范围内的要素.
47                 ESRI.ArcGIS.Geodatabase.IFeatureCursor fCur = GetAllFeaturesFromPointSearchInGeoFeatureLayer(selEnvelope, fLyr.FeatureClass);
48                 ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fLyr.FeatureClass;
49                 ESRI.ArcGIS.Geodatabase.IFeature f = null;
50                 string v = "";
51                 string k = "";
52                 k = "name";
53                 fMain.mapCtrl_main.ActiveView.Refresh();    //高亮显示前.
54                 try {
55                     while ((f = fCur.NextFeature()) != null) {
56                         map.SelectFeature(fLyr, f); //高亮显示.
57                         v = Convert.ToString(f.get_Value(f.Fields.FindField("name")));
58                         lsbox.Items.Add(k + " : " + v);
59                     }
60                 }
61                 catch (System.Exception ex) {
62                     MessageBox.Show(ex.Message + "不支持查询的图层或查询字段错误:NAME");
63                 }
64                 fMain.mapCtrl_main.ActiveView.Refresh();    //高亮显示后.
65             }
66         }
67     }
68 }

  6,运行时,画好矩形轮廓后,在主视图控件类中调用即可:

 1 if (mainInvelope == null || mainInvelope.IsEmpty) {
 2     MessageBox.Show("画轮廓为空");
 3     return;
 4 }
 5 if (fInvelopePoints == null)
 6     fInvelopePoints = new fQueryInvelopePoints(this, mapCtrl_main.Map);
 7 fInvelopePoints.FormClosed += (s, ea) => {
 8     fInvelopePoints = null;
 9 };
10 fInvelopePoints.Show(this);

其中 fInvelopePoints 为定义在主视图类中的查询窗口的成员变量:

1 //查询窗口.
2 private fQueryInvelopePoints fInvelopePoints = null;

  在主视图中画矩形轮廓如图:

  查询后,弹出查询结果如图:

时间: 2024-10-03 14:45:25

查询矩形范围内的"点"要素的相关文章

HDU 4343 多查询求区间内的最大不相交区间个数-思维&amp;贪心-卡时间&amp;二分&amp;剪枝

题意:给你一些区间,现在有m个查询,求出每个查询的区间内的最大的不相交区间个数 分析: 几天前那道说谎问题时用dp的摞箱子模型求的最大的不相交区间个数,但是这题不能用这个方法,因为这题是动态的查询,不可能每个查询dp一次,超时. 这题用贪心策略.求区间[l~r]里的最大不相交区间,贪心策略就应该先选该区间内右端点最小的,这样给以后待选的区间留下更大的空间,所以我们的做法就是先按照区间的右端点排序,然后每次查询依次挑出查询区间里右端点最小的,并且把查询区间的左端点更新为刚才挑出的区间的右端点(这个

sql查询一天内的where写法,sql写法

sql查询一天内的写法: 1. where createtime BETWEEN (select date_format(now(),'%Y-%m-%d 00:00:00')) and (select date_format(now(),'%Y-%m-%d 23:59:59')) 2. SELECT TO_DAYS(now());SELECT TO_DAYS('2016-07-02 20:50:06'); ========================================附录===

sql语句查询同一表内多字段同时重复的记录 sql数据库重复记录删除

分享下用sql语句删除数据库中重复记录的方法.比如现在有一人员表 (表名:peosons) 若想将姓名.身份证号.住址这三个字段完全相同的记录查询出来select p1.* from persons p1,persons p2 where p1.id<>p2.id and p1.cardid = p2.cardid and p1.pname = p2.pname and p1.address = p2.address可以实现上述效果.几个删除重复记录的SQL语句 1.用rowid方法2.用gr

Linux 根据组名查询出该组内所有成员

目前linux中没有直接根据组名查询组员的命令. 目前系统提供的查找组员和组之间的关系的方法有两种, 一种是:查找/etc/passwd和/etc/group目录,根据/etc/group目录里面的组的id,在/etc/passwd中查找到组内成员. 另一种是:通过groups命令,根据组员查找该组员所属组 我用grep和cut命令实现了通过组名查找出其内组员的功能,命令如下 # gid=`grep '组名' /etc/group | cut -d ':' -f 3` && grep &q

Oracle查询某个时间段内第天的统计数

1:Oracle查询某个时间段内,每天发送短信的总条数 select tab.tday,       (select count(1) from t_msgsendrecode m where trunc(m.sendtime) = to_date(tab.tday,'yyyy-mm-dd'))from ( select * from (select to_char(add_months(last_day(to_date('2015-6-2','yyyy-mm-dd'))+1,-1),'YYYY

己知矩形两对角点坐标,计算矩形区域内所有坐标

时不时要用到求坐标,原来写过又忘了,重写一次备忘 private string getAllPoint(Point p1, Point p2)        {            string info = "";            int minNumX = 0;            int minNumY = 0;            for (int i = 0; i < Math.Abs(p2.X - p1.X) + 1; i++)            { 

Oracle数据库,查询语句、内置函数

一.数据库的查询语句: 1.查询整个表: select * from 表名 例: 2.通过条件查询某一行数据: select * from 表名 where 字段名 例: 3.某一列数据去重查询: select distinct 字段名 from 表名 例: 4.查询的结果按某个字段升序或倒序排列:  select * from 表名 order by 字段名;                  在字段名的后面加desc为降序顺序排列 例: 5.查询某一列在某个范围内的数据: select *

MongoDB 如何查询和修改内嵌文档

MongoDB是文档型的数据库系统,doc是MongoDB的数据单位,每个doc相当于关系型数据库的数据行(row),doc和row的区别在于field的原子性:row中的column是不和分割的原子对象,而doc中的field可以是原子对象,也可以是内嵌doc(embedded doc),数组等数据类型.内嵌doc中所有field的Key不允许重复. 例如以下doc,contact 字段是内嵌doc. oneDoc= { name:"t1", age:21, contact: { p

MySql 查询一周内最近7天记录

本周内:select * from wap_content where week(created_at) = week(now) 查询一天:select * from table where to_days(column_time) = to_days(now());select * from table where date(column_time) = curdate(); 查询7天:select * from table  where DATE_SUB(CURDATE(), INTERVA