mwmcneil
10-07-2007, 09:10 PM
I have several polygons displayed on a MapPoint map. I am creating pushpins for various locations that are displayed on the map. Is there a way to get information back (preferably into Access) as to what polygon a particular address is within? Or even a list of pushpins that are within a particular polygon.
Thanks
Eric Frost
10-07-2007, 09:17 PM
Hi! Welcome to the forum. I hope you find it useful and stick around.
You can select a polygon and then right click on it and "Export To Excel" the list of pushpins within it... you could then import the lists to Access.
If you are programming it, you can use the QueryShape or QueryPolygon method to get a recordset and loop through it and write back to Access.. see the Help File for more info on the Query methods and example code.
e.g. for QueryPolygon
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
Eric
mwmcneil
10-08-2007, 08:52 AM
Thanks for the reply. I am currently doing the export to Excel and have the Excel file linked to the Access database but that is a little cumbersome for the end user. Also, the data exported to Excel does not contain the polygon information, so I have to manually export to Excel for each polygon.
I have used the help file and the sample code and I can query a polygon to get a count of how many records are within that polygon, but I want to know exactly what records they are. Here is what I want to do:
I have an Access table that has addresses where crime shave occurred. I have a MapPoint map that has polygons that represent political boundaries. I can plot the crime locations on the map and query the map to see how many crimes occurred in a specific polygon. I want to be able to create code that will query the polygons to get a list of the crimes that are in that polygon so I can store the polygon information with the crime data in Access. This will allow me to prepare crime statistics for each polygon.
Thanks
Eric Frost
10-08-2007, 09:13 AM
This is the part that loops through each one..
objRecords.MoveFirst
Do While Not objRecords.EOF
lngCount = lngCount + 1
objRecords.MoveNext
Loop
As written all the code does is get the count, but you could access the location information from the objRecords recordset object.. I think use the Pushpin property e.g.
'Access the first Pushpin
MsgBox objRS.Pushpin.Name
objRS.Pushpin.Location.GoTo
If you want help with the coding, there are probably some people in here who would be happy to do some consulting..
Eric