Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 6 of 6

Selected Area

This is a discussion on Selected Area within the MapPoint Desktop Discussion forums, part of the Map Forums category; Lets say i have selected an area and in the area that i selected there are pushpins. Is there anyway ...

  1. #1
    amanuel is offline Junior Member White Belt
    Join Date
    Aug 2002
    Posts
    11

    Selected Area

    Lets say i have selected an area and in the area that i selected there are pushpins. Is there anyway of finding out the pushpins that reside in that area through code.

  2. #2
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4
    No.. as you're probably aware, working interactively you can do it with right-click / Export to Excel.. MapPoint does not offer this programmatically. If you're ambitious, you could export the polygon and points ( http://www.mp2kmag.com/importersub01.asp ) for processing in a GIS or your own alghorithm ( search for the for "point-in-polygon alghorithm ).
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  3. #3
    John Meyer's Avatar
    John Meyer is offline Senior Member Blue Belt
    Join Date
    Jul 2002
    Posts
    478
    Give this a try, I think it will do what your asking. I'm just counting the number of pushpins in the selected area (the rectangle made when holding the left mouse button and dragging) but you could get there name/location or whatever you need.. BTW, If you did not select an area it will just exit sub.

    Private Sub Command1_Click()
    On Error GoTo error:
    Dim objmap As MapPointctl.Map
    Set objmap = MappointControl1.ActiveMap

    Dim sa As MapPointctl.SelectedArea
    Set sa = objmap.SelectedArea

    Dim objDataSet As MapPointctl.DataSet
    Dim objRecords As MapPointctl.Recordset


    Dim objLocs(1 To 5) As MapPoint.Location
    Set objLocs(1) = objmap.XYToLocation(sa.Left, sa.Top)
    Set objLocs(2) = objmap.XYToLocation(sa.Left + sa.Width, sa.Top)
    Set objLocs(3) = objmap.XYToLocation(sa.Left + sa.Width, sa.Top + sa.Height)
    Set objLocs(4) = objmap.XYToLocation(sa.Left, sa.Top + sa.Height)
    Set objLocs(5) = objmap.XYToLocation(sa.Left, sa.Top)

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

    lngCount = 0

    For Each objDataSet In objmap.DataSets
    Set objRecords = objDataSet.QueryPolygon(objLocs)
    objRecords.MoveFirst
    Do While Not objRecords.EOF
    lngCount = lngCount + 1
    objRecords.MoveNext
    Loop
    Next
    MsgBox "Number of records in polygon: " & lngCount

    Exit Sub
    error:
    MsgBox Err.Description
    End Sub

  4. #4
    amanuel is offline Junior Member White Belt
    Join Date
    Aug 2002
    Posts
    11
    John,
    I was playing with something like the code below and sometimes all the records fall in and sometimes i lose one or two points but your solution seems to work better so thank you.
    P.S.
    i wouldn't mind if you tell me why my code lost those points.
    Dim objshape As MapPoint.Shape

    Set objshape = objMap.Shapes.AddShape(geoShapeRectangle, objMap.SelectedArea.Location, objMap.SelectedArea.Width / 100, objMap.SelectedArea.Height / 100)
    objshape.Select
    For Each objDataSet In objMap.DataSets
    If InStr(objDataSet.Name, "My Pushpins") Then
    Set objRecordset = objDataSet.QueryShape(objshape)
    Do Until objRecordset.EOF
    objRecordset.Pushpin.Highlight = True
    objRecordset.MoveNext
    Loop
    End If
    Next
    objshape.Delete

  5. #5
    John Meyer's Avatar
    John Meyer is offline Senior Member Blue Belt
    Join Date
    Jul 2002
    Posts
    478
    Amanuel,

    Your welcome. One thing my code does it check every dataset. Your code has the if statment so only looks at the "My Pushpins" dataset. If you have more than one dataset, that could explain it.

    Another thing you could try is run both peices of code but don't delete the shapes, see if they are covering different locations?

  6. #6
    muspench is offline Junior Member White Belt
    Join Date
    Aug 2009
    Posts
    5

    Re: Selected Area

    Note: formatting is not displaying as I enter it. Replaced quote marks with [Quote mark here] and hard returns with lines of dashes.
    ----------------------------------------
    I had occasion to read this thread today, years later, and found it helpful. I worked around the export problem a little differently. Information a pushpin carries can be read & written to a text file as you iterate through the pushpins contained in the shape, as follows:
    ---------------------------------------- Set objFileSystem = CreateObject([Quote mark here]Scripting.FileSystemObject[Quote mark here])
    --------------------strPathName = [Quote mark here]C:\X drive alexa-win98\My Documents\Databases\Murders\OutFiles\SeventhWardMu rdersList[Quote mark here] & strToday & [Quote mark here].txt[Quote mark here]
    --------------------Set objOutFile = objFileSystem.CreateTextFile(strPathName, True)
    --------------------Set objRecordset = objMap.DataSets([Quote mark here]My Pushpins[Quote mark here]).QueryPolygon(objLocs)
    --------------------objRecordset.MoveFirst
    --------------------Do While Not objRecordset.EOF
    --------------------strNote = CStr(objRecordset.Pushpin.Note)
    --------------------strStreetAddress = CStr(objRecordset.Pushpin.Location.StreetAddress)
    --------------------strWriteLine = strNote & Chr(35) & strStreetAddress
    --------------------objOutFile.WriteLine strWriteLine
    --------------------objRecordset.MoveNext
    --------------------Loop
    --------------------objOutFile.Close
    ----------------------------------------What I end up with is a text file containing lines like this:
    ---------------------------------------- Name_Date [which is my pushpin note text]#StreetAddress, City, State, Zip [which is the objRecordset.Pushpin.Location.StreetAddress text]
    ---------------------------------------- and it's formatted like the .csv export file I ended up with when I did the process by hand. I used the pound sign as a delimiter, since there are commas in the address. It's not the same as being able to do the real export in code, of course, but you get almost the same result.
    Last edited by Eric Frost; 10-13-2010 at 06:25 AM. Reason: Hard returns not displayed

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. find streets in a selected area
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 01-11-2009, 07:05 PM
  2. CopyMap AND Keep Selected Area
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-15-2005, 02:58 PM
  3. How to get selected vertex in a polyline
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 07-11-2004, 10:10 AM
  4. reading each pinpoint with a selected area of the map
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-18-2003, 05:28 PM
  5. Determining what has been selected?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-06-2003, 08:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83