SearchWithin 和 SelectByRegion 方法的使用(VB+MapX)

下列代码演示了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<-- viewthread_post_sig -->
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值