步骤

  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. 把url参数转化成一个对象返回
  2. iOS 9学习系列:打通 iOS 9 的通用链接(Universal Links)
  3. 理解WebService SOAP WSDL
  4. uva 11582
  5. Asp.Net 基础理论
  6. 我的WebService入门
  7. java 对象 Serializable注意事项
  8. python中的类变量、实例变量
  9. AMH4.2免费版手动编译升级Nginx1.8版本方法
  10. android获取文件getMimeType的两种方法
  11. Mac OSX操作系统安装和配置Zend Server 6教程(3)
  12. oracle 表查询(一)
  13. SQL知识点
  14. 2017-11-04 Sa OCT codecombat
  15. 洛谷 P1015 回文数
  16. DataSnap Server 客户端调用 异常
  17. 常用sql自定义函数
  18. PHP函数总结 (二)
  19. Python --Redis Hash操作
  20. wifidog 移植到MIPS平台

热门文章

  1. 跟我学android-搭建Android开发环境(一)
  2. 找不到请求的 .Net Framework Data Provider。可能没有安装。
  3. linux下一些很有用的命令
  4. linux文件合并,去重,分割
  5. c#—— Task.FromResult 的使用
  6. openwrt上wifi探针的实现
  7. 【细说Java】Java的重写与隐藏
  8. 黑马程序员_JavaIO流(一)
  9. poj3237 Tree
  10. windows wim