物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 552|回复: 0

MAPX中SearchWithin 和 SelectByRegion 方法的使用

[复制链接]
发表于 2013-3-15 18:03:28 | 显示全部楼层 |阅读模式
下列代码演示了SearchWithin 和 SelectByRegion 方法的使用。

Private Sub cmdQuit_Click()
End
End Sub


Private Sub Command1_Click()
Dim ftr As Feature
Dim ftrs As Features
If Map1.Layers.Item("regions").Selection.Count = 0 Then
MsgBox "Select a yellow region 1st"
Exit Sub
End If
Set ftr = Map1.Layers.Item("regions").Selection.Item(1)
'SearchType: SearchType is miSearchTypeCentroidWithin, miSearchTypePartiallyWithin, or miSearchTypeEntirelyWithin.
Set ftrs = Map1.Layers.Item("pieces").SearchWithinFeature(ftr, miSearchTypePartiallyWithin)
Map1.Layers.Item("pieces").Selection.Add ftrs
Map1.Layers.Item("regions").Selection.ClearSelection
MsgBox ftrs.Count
End Sub


Private Sub Command2_Click()
Dim ftr As Feature
Dim ftrs As Features
Dim lyr As Layer
If Map1.Layers.Item("regions").Selection.Count = 0 Then
MsgBox "Select a yellow region 1st"
Exit Sub
End If
Set lyr = Map1.Layers.Item("regions")
Set ftr = lyr.Selection.Item(1)
'A feature is considered to be within "within" the region if and only if its centroid is within the radius. If more control is needed over selection criteria, use the Layer object's SearchWithinFeature method.
Map1.Layers.Item("pieces").Selection.SelectByRegion lyr, ftr.FeatureID, miSelectionNew
Map1.Layers.Item("regions").Selection.ClearSelection
MsgBox Map1.Layers.Item("pieces").Selection.Count
End Sub


Private Sub Form_Load()
'Add the layer
Map1.Layers.RemoveAll
Map1.Layers.Add App.Path & "\regions.tab"
Map1.Layers.Add App.Path & "\pieces.tab"
Map1.CurrentTool = miSelectTool
'make the map look nice for the sample data
Map1.DisplayCoordSys = Map1.NumericCoordSys
Map1.Title.Visible = False
Map1.Bounds = Map1.Layers.Item("regions").Bounds
End Sub

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-5-10 11:49 , Processed in 0.060857 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表