|
技术资料:SearchWithin 和 SelectByRegion 方法的使用:
下列代码演示了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 |
|