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
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

A COM addin for quickly moving groups of points from dataset to dataset

This is a discussion on A COM addin for quickly moving groups of points from dataset to dataset within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi all, After reading through many forum posts on this topic I have come to the conclusion that no one ...

  1. #1
    Conor is offline Junior Member Yellow Belt
    Join Date
    Jun 2010
    Posts
    17

    A COM addin for quickly moving groups of points from dataset to dataset

    Hi all,

    After reading through many forum posts on this topic I have come to the conclusion that no one has yet made a freely available way to dynamically assign large groups of pushpins to different data sets in MapPoint. I have decided to write a COM addin that will serve this purpose. I am fairly new to VB6 and I am requesting anyone with experience in COM addin programming to assist me with a few questions regarding the syntax and logic of the program.

    Upon completion of the addin I will upload the source code and completed program and post a link up here to make the addin available for everyone.

    I will also make a forum posting to suggest that this feature is included in MapPoint 2011, as it seems that this feature is often requested on these forums.


    To use this COM addin, one will:

    1. Import a set of zip codes from Excel and plot them on the map, putting every zip code into a dataset named "Unassigned".
    2. Draw a freeform polygon around any number of zip code pushpins.
    3. Run the addin. The addin will have two functions:

    a. The first function will return and display the number of points inside the
    selected freeform polygon.

    b. The second function will open up a window that will ask if the user
    would like to move all pushpins inside the polygon from the
    current dataset (can be the "Unassigned" dataset or any other
    dataset) to any other previously created dataset.

    The basic logic of the addin will be as follows:

    i. Set the location of the selected freeform shape (drawn before running the addin) as a variable named something like objShape.

    ii. Use the queryPolygon method to retrieve all pushpin records within objShape and assign them to a temporary Recordset named something like PushpinsInShape.

    iii. Return and show in a message box the number of values in PushpinsInShape. Then prompt the user to assign all records in PushpinsInShape to a dataset of their choice (by hitting an OK button) or to cancel the action.

    iv. Upon hitting the OK button, the addin will loop over all of the records in PushpinsInShape and then loop over all datasets in MapPoint. The addin will store all matching records in a value named something like PushpinsToBeMoved.

    v. The addin will then loop over all current datasets again, this time matching records found in PushpinsToBeMoved with the current dataset. Then all the matching records will be deleted from current datasets. This purges the old dataset records.

    vi. The addin will then assign all records in PushpinsToBeMoved to an existing user specified dataset. This is the actual moving of the data from one(or many) dataset(s) to one dataset of the user's choosing. MoveTo(NewDataset) method will probably be used here.

    vii. After the pushpins have been moved to a new dataset, the addin will error-check. If the user specifies a bogus or bad dataset to move pushpins to, the addin will restore the the records found in PushpinsToBeMoved to their previous records.

    viii. After the entire process is complete, PushpinsToBeMoved will be purged so that the addin can be run again in the same session.


    Thanks to Michael R. Mattys for letting me know that this idea was possible.


    Conor Barber
    Student, Purdue University

    contact at

    cbarber@purdue.edu

  2. #2
    Conor is offline Junior Member Yellow Belt
    Join Date
    Jun 2010
    Posts
    17

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    So far I have managed to get the QueryPolygon coding down without a hitch, but I am having trouble setting an already drawn and selected freeform polygon to objShape.

    The sample code provided in MSDN creates a square for you with which you can modify:

    Code:
        '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 *
    But I just want it to find an already drawn freeform polygon, not create a new one. Any ideas?

  3. #3
    Mattys Consulting's Avatar
    Mattys Consulting is offline Senior Member Black Belt
    Join Date
    Dec 2002
    Posts
    1,040

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    Hi Conor,

    You're welcome.
    I think what you're looking for is Map.Selection and the Union of Vertices.
    Michael R Mattys
    Business Process Developers
    www.mattysconsulting.com

  4. #4
    Conor is offline Junior Member Yellow Belt
    Join Date
    Jun 2010
    Posts
    17

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    Hello and thanks for the help.

    I think I have successfully been able to get the freeform polygon by grabbing the shape and converting its vertices to an array of locations for QueryPolygon to use. However, upon running the program I am using to test the code, which simply returns the number of records in the polygon, I get an error message that states

    Object variable or With Block variable not set

    Here is the code:

    Code:
     Dim oMap As MapPoint.Map
        Set oMap = oApp.ActiveMap
        
        Dim objDataSet As MapPoint.DataSet
        Dim objRecords As MapPoint.Recordset
        Dim objLocs(1 To 10) As MapPoint.Location
        Dim objShape As MapPoint.Shape
        Dim lngCount As Long
        lngCount = 0
    
    
        objShape = oMap.Selection
        
       
        
        Set objLocs(1) = objShape.Vertices(1).Longitude
        Set objLocs(2) = objShape.Vertices(1).Latitude
        Set objLocs(3) = objShape.Vertices(2).Longitude
        Set objLocs(4) = objShape.Vertices(2).Latitude
        Set objLocs(5) = objShape.Vertices(3).Longitude
        Set objLocs(6) = objShape.Vertices(3).Latitude
        Set objLocs(7) = objShape.Vertices(4).Longitude
        Set objLocs(8) = objShape.Vertices(4).Latitude
        Set objLocs(9) = objShape.Vertices(5).Longitude
        Set objLocs(10) = objShape.Vertices(5).Latitude
     
       
    
    
        oApp.Visible = True
        oApp.UserControl = True
      
      
       
        
    
        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
    Any thoughts?

    Thanks for your time,

    Conor

  5. #5
    Mattys Consulting's Avatar
    Mattys Consulting is offline Senior Member Black Belt
    Join Date
    Dec 2002
    Posts
    1,040

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    Sure, Conor.

    You've forgotten to use the Set keyword
    You should have:
    Set objShape = oMap.Selection
    Michael R Mattys
    Business Process Developers
    www.mattysconsulting.com

  6. #6
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    You should also check that the selection is a shape, and that it is a usable shape (eg. a freeform shape).


    When you get to copy the pushpins, you will find that you will only be able to create/copy "manually created pushpins". Ie. those which were located by hand by a user, or with AddPushpin.

    You can copy other pushpins (eg. those imported with the Data Import Wizard), and you will be able to extract their data fields. However when you try to create copies, you will not be able to create matching data fields. If you want to preserve this data, you will need to format it into a text field and saving it to the pushpin "note".

    You will also find that demographic data cannot be extracted for copying in most versions of MapPoint; and you should be very careful to check all fields/records/etc are valid before accessing them.


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  7. #7
    Conor is offline Junior Member Yellow Belt
    Join Date
    Jun 2010
    Posts
    17

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    Thanks for the heads up Richard, the information you provided will probably save me a lot of time and headache in the future.

    Adding the Set keyword fixed my object variable not set error.

    However, now when I run the program (the only change I have made is adding the Set keyword) I am getting a different error message:

    Error: Object Required


    I might be wrong here, but I think my problem is that the QueryPolygon method requires an array of Location objects. The vertices I have retrieved might have to be typecast before being plugged into the objLocs array.

    Can anyone verify that this is true or if I am just shooting in the dark? Also, if I end up having to typecast, would the TCast() method be optimal?

  8. #8
    Mattys Consulting's Avatar
    Mattys Consulting is offline Senior Member Black Belt
    Join Date
    Dec 2002
    Posts
    1,040

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    Conor,

    Your declaration of objLocs says that it is expecting Locations objects,
    rather than Latitude and Longitude values of type Double.

    Therefore, you only need to correct that oversight and you'll provide
    the correct parameter for QueryPolygon.
    Michael R Mattys
    Business Process Developers
    www.mattysconsulting.com

  9. #9
    Conor is offline Junior Member Yellow Belt
    Join Date
    Jun 2010
    Posts
    17

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    Hello again,

    I am still struggling with passing the correct parameter into QueryPolygon. I am now using a for loop which traverses all of the selected shape's vertices, retrieves them in a Location object, and then stores them into the objLocs array. However, the Object variable or With Block variable not set error has returned.



    Here is the code:

    Code:
       Dim oMap As MapPoint.Map
        Set oMap = oApp.ActiveMap
        Dim iVertices As Integer
        Dim objDataSet As MapPoint.DataSet
        Dim objRecords As MapPoint.Recordset
        Dim objLocs(1 To 10) As MapPoint.Location
        Dim objShape As MapPoint.Shape
        Dim lngCount As Long
        lngCount = 0
    
    
        Set objShape = oMap.Selection
        
        objShape.Select
        
       
        For iVertices = 0 To UBound(objShape.Vertices)
         
        Set objLocs(iVertices + 1) = objShape.Vertices(iVertices).Location
        
        Next
    In all my previous programming experience (all in Java) I was able to troubleshoot problems like this by printing out the output of assigned values. For example, I could add in a

    System.out.println(objLocs) and see exactly what was being assigned to that specific array. Is there any way to do this in VB6?

    Thanks for your time,
    Conor

  10. #10
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60

    Re: A COM addin for quickly moving groups of points from dataset to dataset

    You would have to iterate through the array and print out the longitude,latitude properties.

    If you come from the Java world, you'll find VB6 a bit backwards. You could try C# and .NET. Personally I prefer C#, but both languages are in the same family and are big improvements over VB6. Or you could always find a COM bridge (there are commercial and open source ones around) and use Java!



    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. dataSet.zoomTo()
    By chpw in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 05-17-2006, 07:05 AM
  2. Dataset rendering
    By Gianmaria in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 06-09-2005, 02:22 PM
  3. How do you add records to a dataset
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 05-03-2005, 03:09 PM
  4. Moving groups of pushpins to front
    By lane in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 03-10-2005, 12:07 PM
  5. Delete Pushpin from PushpinSet (or DataSet) prior to moving
    By SeanMcGinty in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 12-20-2004, 10:37 AM

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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127