步骤

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

 private ESRI.ArcGIS.Geometry.IEnvelope mainInvelope = null; //(主视图上)
public ESRI.ArcGIS.Geometry.IEnvelope MainInvelopeValue {
get {
return mainInvelope;
}
}

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

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

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

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

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

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

 /// <summary>
/// 画轮廓.
/// </summary>
/// <param name="sender"></param>
/// <param name="e">根据IEnvelope对象画轮廓.</param>
public static void DrawSymbol(ESRI.ArcGIS.Carto.IMap map, ESRI.ArcGIS.Geometry.IEnvelope e) {
ESRI.ArcGIS.Carto.IGraphicsContainer hawkGC = (ESRI.ArcGIS.Carto.IGraphicsContainer)map;
ESRI.ArcGIS.Carto.IActiveView aView = (ESRI.ArcGIS.Carto.IActiveView)hawkGC;
hawkGC.DeleteAllElements(); ESRI.ArcGIS.Carto.IElement recEle = (ESRI.ArcGIS.Carto.IElement)new ESRI.ArcGIS.Carto.RectangleElementClass();
recEle.Geometry = e;
ESRI.ArcGIS.Display.ISimpleLineSymbol outLine = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
outLine.Color = ColorPaint(, );
outLine.Width = ; //填充样式.
ESRI.ArcGIS.Display.ISimpleFillSymbol fillSym = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
fillSym.Color = ColorPaint(, );
fillSym.Outline = outLine; ESRI.ArcGIS.Carto.IFillShapeElement fillShape = (ESRI.ArcGIS.Carto.IFillShapeElement)recEle;
fillShape.Symbol = fillSym;
hawkGC.AddElement((ESRI.ArcGIS.Carto.IElement)fillShape, );
aView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, null, null);
}

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

 /// <summary>
/// 根据图层名获取图层.
/// </summary>
/// <param name="map"></param>
/// <param name="layerName">图层名称.</param>
/// <returns></returns>
public static ESRI.ArcGIS.Carto.ILayer GetLayerByName(ESRI.ArcGIS.Carto.IMap map, string layerName) {
ESRI.ArcGIS.Carto.IEnumLayer enunLayer = map.get_Layers(null, false);
enunLayer.Reset();
ESRI.ArcGIS.Carto.ILayer resultLayer = null;
while ((resultLayer = enunLayer.Next()) != null) {
if (resultLayer.Name.Equals(layerName)) {
break;
}
}
return resultLayer;
}

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

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace Engine {
public partial class fQueryInvelopePoints : Form {
private ESRI.ArcGIS.Carto.IMap map = null;
private fMain fMain = null;
public fQueryInvelopePoints(fMain fMain, ESRI.ArcGIS.Carto.IMap map) {
this.fMain = fMain;
this.map = map;
InitializeComponent();
} /// <summary>
/// 查询指定矩形范围内的点要素.
/// </summary>
/// <param name="envelope">指定的矩形范围.</param>
/// <param name="featureClass">待查询的要素.</param>
/// <returns>返回结果的游标</returns>
public ESRI.ArcGIS.Geodatabase.IFeatureCursor GetAllFeaturesFromPointSearchInGeoFeatureLayer(ESRI.ArcGIS.Geometry.IEnvelope envelope, ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass) {
if (featureClass == null)
return null;
ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
spatialFilter.Geometry = envelope;
spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
spatialFilter.GeometryField = featureClass.ShapeFieldName;
return featureClass.Search(spatialFilter, false);
} private void fQueryInvelopePoints_Load(object sender, EventArgs e) {
Engine.App_Code.Layer_Assist.InitLayers(map, cbox_layer);
} private void btn_query_Click(object sender, EventArgs e) {
lsbox.Items.Clear(); //清空原始数据.
ESRI.ArcGIS.Carto.ILayer lyr = Engine.App_Code.Layer_Assist.GetLayerByName(map, cbox_layer.Text);
if (lyr is ESRI.ArcGIS.Carto.IFeatureLayer) { //矢量数据.
ESRI.ArcGIS.Carto.IFeatureLayer fLyr = (ESRI.ArcGIS.Carto.IFeatureLayer)lyr;
ESRI.ArcGIS.Geometry.IEnvelope selEnvelope = fMain.MainInvelopeValue;
//获取矩形范围内的要素.
ESRI.ArcGIS.Geodatabase.IFeatureCursor fCur = GetAllFeaturesFromPointSearchInGeoFeatureLayer(selEnvelope, fLyr.FeatureClass);
ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fLyr.FeatureClass;
ESRI.ArcGIS.Geodatabase.IFeature f = null;
string v = "";
string k = "";
k = "name";
fMain.mapCtrl_main.ActiveView.Refresh(); //高亮显示前.
try {
while ((f = fCur.NextFeature()) != null) {
map.SelectFeature(fLyr, f); //高亮显示.
v = Convert.ToString(f.get_Value(f.Fields.FindField("name")));
lsbox.Items.Add(k + " : " + v);
}
}
catch (System.Exception ex) {
MessageBox.Show(ex.Message + "不支持查询的图层或查询字段错误:NAME");
}
fMain.mapCtrl_main.ActiveView.Refresh(); //高亮显示后.
}
}
}
}

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

 if (mainInvelope == null || mainInvelope.IsEmpty) {
MessageBox.Show("画轮廓为空");
return;
}
if (fInvelopePoints == null)
fInvelopePoints = new fQueryInvelopePoints(this, mapCtrl_main.Map);
fInvelopePoints.FormClosed += (s, ea) => {
fInvelopePoints = null;
};
fInvelopePoints.Show(this);

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

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

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

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

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

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

    sql查询一天内的写法: 1. where createtime BETWEEN (select date_format(now(),'%Y-%m-%d 00:00:00')) and (select ...

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

    目前linux中没有直接根据组名查询组员的命令. 目前系统提供的查找组员和组之间的关系的方法有两种, 一种是:查找/etc/passwd和/etc/group目录,根据/etc/group目录里面的组 ...

  3. Android判断一个点是否在矩形区域内

    个人遇到的问题判断按钮的点击事件还是滑动事件 private boolean button1Down = false; private boolean button2Down = false; pri ...

  4. PHP中查询指定时间范围内的所有日期,月份,季度,年份

    /** * 查询指定时间范围内的所有日期,月份,季度,年份 * * @param $startDate 指定开始时间,Y-m-d格式 * @param $endDate 指定结束时间,Y-m-d格式 ...

  5. MongoDB查询或修改内嵌文档

    作为非关系型数据库中的佼佼者,MongoDB一大优势在于能够在一条文档中存储对象类型的数据,适当增加冗余来让数据库更好用.文档中一个对象类型的字段在MongoDB中被称为内嵌文档(Embedded) ...

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

    一.数据库的查询语句: 1.查询整个表: select * from 表名 例: 2.通过条件查询某一行数据: select * from 表名 where 字段名 例: 3.某一列数据去重查询: s ...

  7. SQLServer学习笔记<> 表连接查询----交叉连接、内连接、左连接、右连接

    (1)交叉连接(cross join)即我们所说的笛卡尔积.查询出满足两张表所有的记录数,A(3条记录),B(9条记录),A*B(27条记录). 比如:雇员表(HR.employees)和货运公司(S ...

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

    本周内:select * from wap_content where week(created_at) = week(now) 查询一天:select * from table where to_d ...

  9. SQL多表联合查询(交叉连接,内连接,外连接)

    连接查询:     交叉连接:   交叉连接返回的结果是被连接的两个表中所有数据行的笛卡尔积,也就是返回第一个表中符合查询条件的数据航数乘以第二个表中符合,查询条件的数据行数,例如department ...

随机推荐

  1. css样式-ime-mode text-transform

    今天遇到一个新的css样式: ime-mode   text-transform  有效小作用 取值:auto : 默认值.不影响ime的状态.与不指定 ime-mode 属性时相同 active : ...

  2. PHPCMSV9 更改后台地址

    修改PHPCMS v9默认后台登录地址 1.修改admin.php文件名,并修改跳转地址写上完整路径2.修改 /phpcms/modules/admin/classes/index.php,把 pub ...

  3. js 音乐

    define(function(require,exports,module){ var $music = document.getElementById('music'); var $music_m ...

  4. .net转php laraval框架学习系列(一) 环境搭建

    之前也没写过什么博客,可能文章结构比较混乱,想到那写到哪. 主要是把自己学习中的经验写下来. 为什么选择laravel框架,是因为laravel框架目前是Php最流行的框架,深入研究后发现和asp.n ...

  5. 百度SEO优化

    下面是一些SEO优化的基本步骤: 一.内部优化 (1)TITLE,KEYWORDS,DESCRIPTION等的优化 (2)内部链接的优化,包括相关性链接,锚文本链接,各导航等链接页 (3)每天保持站内 ...

  6. php实现网页HTML标签补全方法

    如果你的网页内容的html标签显示不全,有些表格标签不完整而导致页面混乱,或者把你的内容之外的局部html页面给包含进去了,我们可以写个函数方法来补全html标签以及过滤掉无用的html标签. php ...

  7. SQLite3简单入门及C++ API

    转载请注明出处:http://www.cnblogs.com/StartoverX/p/4660487.html 项目用到SQLite3,简单记录一下. MySQL不同,SQLite3的数据库基于文件 ...

  8. [转]100个经典C语言程序(益智类问题)

    目录: 1.绘制余弦曲线 2.绘制余弦曲线和直线 3.绘制圆 4.歌星大奖赛 5.求最大数 6.高次方数的尾数 8.借书方案知多少 9.杨辉三角形 10.数制转换 11.打鱼还是晒网 12.抓交通肇事 ...

  9. AngularJs 如何监视外部变量是否改变? 如何使用$cookieStore保存cookie?

    1. 如何监视外部变量是否改变? 如果我们要求:在$scope之外改变一个外部变量时,触发一些操作.我们可以将外部变量写进$watch中,如图中所示.返回的n表示newValue,即新的值.o表示ol ...

  10. ES6-2

    向ES6看齐,用更好的JavaScript(二)   上一篇 中介绍了关于变量部分的新特性,本篇将从现有对象的拓展来展开介绍 1 增加了模板字符串 先看一下,ES6之前我们是如何实现输出模板的: do ...