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 7 of 7

select contents of shape

This is a discussion on select contents of shape within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hello community. Any ideas on how to draw a polygon on a geodatamap of zip codes, have the user select ...

  1. #1
    mmartin is offline Member Yellow Belt
    Join Date
    Apr 2007
    Posts
    30

    Red face select contents of shape

    Hello community.

    Any ideas on how to draw a polygon on a geodatamap of zip codes, have
    the user select the area,trap the zips in the shape and export to a dataset? Particularly not sure how to activate and use the toolbar drawing functions...programmactialy

    I am using mappoint 2006 in visual studio 2005 via activex, VB.net

    Best
    M. Martin

  2. #2
    Paul Larson is offline Senior Member Green Belt
    Join Date
    Sep 2005
    Location
    Battle Creek, Michigan
    Posts
    136

    Smile Re: select contents of shape

    First off, you'll need to change the zipcode map to a pushpin map. This is because the QueryShape() method does not work on demographic or area maps.

    Programmatically triggering the DrawFreeformShape tool can be done by adding this class to your application:

    Code:
    Public Class xMapPointGUI
       Private hwMPC As IntPtr = IntPtr.Zero
       Private hwMessageFrame As IntPtr
    
       Private Const WM_COMMAND As Int32 = &H111
       Private Const WM_MAPPOINT_BEGIN_SCRIBBLE As Int32 = 58205
       Private Const WM_MAPPOINT_BEGIN_LINE As Int32 = 58206
       Private Const WM_MAPPOINT_BEGIN_ARROW As Int32 = 58207
       Private Const WM_MAPPOINT_BEGIN_FREEFORM As Int32 = 58208
       Private Const WM_MAPPOINT_BEGIN_RECTANGLE As Int32 = 58209
       Private Const WM_MAPPOINT_BEGIN_OVAL As Int32 = 58210
       Private Const WM_MAPPOINT_BEGIN_MEASURE As Int32 = &HE370
       Private Const WM_MAPPOINT_BEGIN_RADIUS As Int32 = &HE372
       Private Const WM_MAPPOINT_BEGIN_TEXTBOX As Int32 = 58211
       Private Const WM_MAPPOINT_DRAW_PUSHPIN As Int32 = 58202
    
       Private Declare Auto Function FindWindowEx Lib "user32" Alias "FindWindowEx" (ByVal hwParent As IntPtr, ByVal hwChildAfter As IntPtr, ByVal strClassName As String, ByVal strWindowCaption As String) As IntPtr
       Private Declare Auto Function GetParentWindow Lib "user32" Alias "GetParent" (ByVal hwChild As IntPtr) As IntPtr
       Private Declare Auto Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
    
       Public Event MPCError(ByVal strErrorMsg As String)
    
       Public Sub New(ByRef MPC As AxMapPoint.AxMappointControl)
          If MPC.Handle.ToInt32 = 0 Then
             RaiseEvent MPCError("MapPointControl was not initialized before calling xMapPointGui.New()")
             Exit Sub
          End If
          hwMPC = GetParentWindow(FindWindowEx(MPC.Handle, IntPtr.Zero, vbNullString, vbNullString))
          Dim hwTemp = FindWindowEx(hwMPC, IntPtr.Zero, vbNullString, "")
          hwMessageFrame = FindWindowEx(hwTemp, IntPtr.Zero, vbNullString, "")
       End Sub
    
       Public Sub BeginScribbleTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_SCRIBBLE, 0)
       End Sub
    
       Public Sub BeginLineTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_LINE, 0)
       End Sub
    
       Public Sub BeginArrowTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_ARROW, 0)
       End Sub
    
       Public Sub BeginFreeFormTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_FREEFORM, 0)
       End Sub
    
       Public Sub BeginRectangleTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_RECTANGLE, 0)
       End Sub
    
       Public Sub BeginOvalTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_OVAL, 0)
       End Sub
    
       Public Sub BeginRadiusTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_RADIUS, 0)
       End Sub
    
       Public Sub BeginTextBoxTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_TEXTBOX, 0)
       End Sub
    
       Public Sub BeginMeasureTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_MEASURE, 0)
       End Sub
    
       Public Sub BeginDrawPushPinTool()
          SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_DRAW_PUSHPIN, 0)
       End Sub
    End Class
    You can instantiate the class object by calling
    Code:
    Dim mpGUI As xMapPointGUI
    ...
    mpGUI = New xMapPointGUI(Me.AxMapPointControl1)
    To trigger the freeform tool, call
    Code:
    mpGui.BeginFreeFormTool()

    After the user draws the shape, use the mappoint api QueryShape() method to find all pushpins within the shape and return them as a recordset. Then iterate through the recordset and use your favorite ADO.Net method to export the recordset items to a dataset.

    HTH
    Paul

  3. #3
    mmartin is offline Member Yellow Belt
    Join Date
    Apr 2007
    Posts
    30

    Cool Re: select contents of shape

    Hi Paul,

    Thanks very much for your reply. So, I understand then that a
    GeoMapRegion.geoMapNorthAmerica could be used with Push pins put in for all the zip codes, to then query and put into the dataset?

    Also, I implemented the class and executed it, but I'm not sure what's supposed to happen? Does this activate the toolbar freeform shape or some other function?. Not sure what it's doing once it executes the SendMessage(hwMessageFrame, WM_COMMAND, WM_MAPPOINT_BEGIN_FREEFORM, 0) ....? I simply brough up a map, and executed a button firing the mpGUI.BeginFreeFormTool() (I guess I'm not quite sure what the difference is between using this and the tool bar freeform command?)

    Thanks again..michael

  4. #4
    Paul Larson is offline Senior Member Green Belt
    Join Date
    Sep 2005
    Location
    Battle Creek, Michigan
    Posts
    136

    Re: select contents of shape

    Yes - your understanding is correct.

    And, yes, the method activates the freeform tool. Just as if the user had clicked the freeform toolbar button. This was to answer your question about activating the drawing toolbar items programmatically.

    Were you instead looking for how to programmatically actually draw a shape?

  5. #5
    Dazzer is offline Senior Member Green Belt
    Join Date
    Sep 2003
    Posts
    103

    Re: select contents of shape

    The adding of the pushpins can slow this process down quite considerably, Particularly if you shape is quite large.

    One method i've implemented for this in the past is to plot all zip codes (post codes in my case in the uk) on a map with pushpins, then using the well documented CalcPos function, retrieve and store, in a database of choice, the latitude and longitude of those pushpins along with there zip code.

    Once you have this data you don't need to use the pushpins in future. You can plot your shape and using any number of point in polygon algorithms ( Point in Polygon Strategies ) work out which postcodes are within your polygon, (personally i go for a 'Ray' algorithm where I project a line from outside the shape to infinity counting the number of times the line crosses a boundary).

  6. #6
    mmartin is offline Member Yellow Belt
    Join Date
    Apr 2007
    Posts
    30

    Thumbs up Re: select contents of shape

    Thanks Paul,

    Yes, this is exactly what I needed. I fixed something (I didn't have an active map in the sub I was calling the beginfreeform sub from) and now it works just as required. Thanks again..Michael (The code below is just and example of my test that worked)

    PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim objmap As MapPoint.Map
    AxMappointControl1.NewMap(MapPoint.GeoMapRegion.ge oMapNorthAmerica)
    objmap = AxMappointControl1.ActiveMap
    AxMappointControl1.Toolbars.Item(1).Visible =
    True
    AxMappointControl1.Toolbars.Item(2).Visible = True
    AxMappointControl1.Toolbars.Item(3).Visible = True
    AxMappointControl1.Toolbars.Item(4).Visible = True
    mpGUI = New xmappointGUI(AxMappointControl1)
    mpGUI.BeginFreeFormTool()
    EndSub

  7. #7
    Paul Larson is offline Senior Member Green Belt
    Join Date
    Sep 2005
    Location
    Battle Creek, Michigan
    Posts
    136

    Re: select contents of shape

    Great - glad it works for ya.

    Just an FYI, the toolbars don't need to be visible in order for the xMappointGUI class to work. It's fine to leave them visible, though.

    -Paul

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Draw shape, select zip codes and export to SQL
    By mmartin in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 04-02-2007, 05:24 PM
  2. I need to select from more than eight colors
    By BobFromBoston in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 03-01-2006, 06:58 PM
  3. Does an object reside in my Shape or Shape boundaries?
    By hotrdd in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 08-04-2005, 10:51 PM
  4. Select a place
    By jimsirv in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 07-29-2004, 09:04 PM
  5. Is this possible to SELECT ALL the pushpins ?
    By Vincent BENNER in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 12-04-2002, 08:51 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 84 85 86 87 88 89 90 91 92 93 94 95 96