面朝大海,春暖华开

focus on scientific computue, 3dgis, spatial database
专注于科学计算、GIS空间分析

 

arcengine 经典代码(转) 空间查询 在一个图层上画一个polygon,根据该polygon查询出图层上与之相交的polygon并高亮显示出来

如何进行空间查询

本例实现的是在一个图层上画一个polygon,根据该polygon查询出图层上与之相交的polygon并高亮显示出来。

要点

通过RubberPolygon类来实现接口IRubberBand接口对象,用IRubberBand.TrackNew方法在图层上画出polygon,然后定义IGeometry获得该polygon,创建ISpatialFilter接口对象实现过滤功能,通过ILayer接口实例获得IFeatureSelection接口,调用IFeatureSelection.SelectFeatures方法将结果高亮显示。

程序说明

过程UIToolControl1_MouseDown是实现模块。

代码

Option Explicit

Private Function UIToolControl1_Deactivate() As Boolean

UIToolControl1_Deactivate = True

End Function

Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, _

ByVal x As Long, ByVal y As Long)

Dim pMxDoc As IMxDocument

Dim pActiveView As IActiveView

Dim pScreenDisplay As IScreenDisplay

Dim pRubberPolygon As IRubberBand

Dim pFillSymbol As ISimpleFillSymbol

Dim pRgbColor As IRgbColor

Dim pPolygon As IPolygon

Dim pGeometry As IGeometry

Dim pFeatselect As IFeatureSelection

Dim pSpatialFilter As ISpatialFilter

On Error GoTo ErrorHandler:

Set pMxDoc = ThisDocument

Set pActiveView = pMxDoc.FocusMap

'Draw Polygon

Set pScreenDisplay = pActiveView.ScreenDisplay

Set pRubberPolygon = New RubberPolygon

Set pFillSymbol = New SimpleFillSymbol

Set pRgbColor = New RgbColor

pRgbColor.NullColor = True

pFillSymbol.Color = pRgbColor

Set pPolygon = pRubberPolygon.TrackNew(pScreenDisplay, pFillSymbol)

With pScreenDisplay

.StartDrawing pScreenDisplay.hDC, esriNoScreenCache

.SetSymbol pFillSymbol

.DrawPolygon pPolygon

.FinishDrawing

End With

'set up pFilter

Set pGeometry = pPolygon

Set pSpatialFilter = New SpatialFilter

With pSpatialFilter

Set .Geometry = pGeometry

.SpatialRel = esriSpatialRelIntersects

End With

'select

Set pFeatselect = pMxDoc.FocusMap.Layer(0)

pFeatselect.SelectFeatures pSpatialFilter, esriSelectionResultNew, False

pFeatselect.SelectionSet.**

pMxDoc.ActiveView.**

Exit Sub

ErrorHandler:

MsgBox Err.Description

End Sub

posted on   风过 无痕  阅读(3393)  评论(0编辑  收藏  举报

(评论功能已被禁用)
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?

导航

统计

向日葵支付宝收钱码
点击右上角即可分享
微信分享提示