Share via


QueryPolygon method

Returns as a Recordset object a record set containing the records located within a polygon. Returns an error for DataSet objects with a HowCreated property of geoDataSetDemographic.

Applies to

Objects:  DataSet

Syntax

object.QueryPolygon(ArrayOfLocations)

Parameters

Part Description
object Required. An expression that returns a DataSet object.
ArrayOfLocations Required Variant. An array of Location objects that form a polygon.

Example

  
    Sub QueryRecordsInBoxAtCenterOfMap()
    Dim objApp As New MapPoint.Application
    Dim objMap As MapPoint.Map
    Dim objDataSet As MapPoint.DataSet
    Dim objRecords As MapPoint.Recordset
    Dim objLocs(1 To 5) As MapPoint.Location
    Dim lngCount As Long

    'Set up application and objects to use
    Set objMap = objApp.ActiveMap
    lngCount = 0
    'create a "square" of locations in the middle of the map
    objMap.Altitude = objMap.Altitude / 2
    Set objLocs(1) = objMap.XYToLocation(0, 0)
    Set objLocs(2) = objMap.XYToLocation(objMap.Width, 0)
    Set objLocs(3) = objMap.XYToLocation(objMap.Width, objMap.Height)
    Set objLocs(4) = objMap.XYToLocation(0, objMap.Height)
    Set objLocs(5) = objMap.XYToLocation(0, 0)
    objMap.Altitude = objMap.Altitude * 2

    objApp.Visible = True
    objApp.UserControl = True

    'Remove the comment from the next line to see the polygon being queried
    'objMap.Shapes.AddPolyline objLocs

    'Let user create a data map
    Set objDataSet = objApp.ActiveMap.DataSets.ShowImportWizard

    'Find records in polygon
    Set objRecords = objDataSet.QueryPolygon(objLocs)
    objRecords.MoveFirst
    Do While Not objRecords.EOF
        lngCount = lngCount + 1
        objRecords.MoveNext
    Loop
    MsgBox "Number of records in polygon: " & lngCount
End Sub