📄 搜索指定点的最近图元.txt
字号:
搜索指定点的最近图元
// 这里默认搜索离地图中心点最近的图元
Dim map As Map = MapInfo.Engine.Session.Current.MapFactory(MapControl1.MapAlias)
Dim ppt As DPoint = Map.Center
Dim session As ISession = MapInfo.Engine.Session.Current
' 半径设置为5象素
Dim d As MapInfo.Geometry.Distance = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, 5)
Dim si As SearchInfo = MapInfo.Data.SearchInfoFactory.SearchNearest(ppt, map.GetDisplayCoordSys(), d)
' 搜索所有列
si.QueryDefinition.Columns = Nothing
' 搜到一个就停止搜索
CType(si.SearchResultProcessor, ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch
' 搜索到的图元放入DefaultSelection中
session.Catalog.Search("Citys", si, session.Selections.DefaultSelection, ResultSetCombineMode.Replace)
' 得到FeatureCollection
Dim table As Table = session.Catalog("Citys")
Dim fc As IResultSetFeatureCollection = session.Selections.DefaultSelection(table)
If (fc.Count = 0) Then
'Response.Write("没有搜索到任何图元!")
TextBox1.Text = "没有搜索到任何图元!"
End If
' 需要注意的是该图层必须设置为可以选择的 这样在地图上才能看出效果
Dim fn As IFeatureEnumerator = fc.GetFeatureEnumerator
While (fn.MoveNext)
ListBox1.Items.Add(fn.Current.Item("Name")) '添加地理位置
End While
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -