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

Looping through Vertices of PolyLine?

This is a discussion on Looping through Vertices of PolyLine? within the MapPoint Desktop Discussion forums, part of the Map Forums category; Well, this is my first post of what I am sure will be many. I've just started using Mappoint and ...

  1. #1
    OOT
    OOT is offline Junior Member Yellow Belt
    Join Date
    Dec 2006
    Posts
    19

    Question Looping through Vertices of PolyLine?

    Well, this is my first post of what I am sure will be many. I've just started using Mappoint and thanks to the many good examples here I've been able to get a couple of polygons drawn programmatically onto the screen. Much Excedrin has been taken

    I am attempting to loop through the vertices of the polygon and output their coordinates to the Immediate Window. Oh, sorry. I'm using Visual Basic 2005 and Mappoint 2006. I am also VERY new to VB 2005 and OOP ... needless to say there is lots of trial and error and sometimes code works and I don't know why.

    Right now there is only 1 polygon on the screen. It has 10 vertices. So, to output those to the console I use this loop:
    Code:
        '    loop through polygon and output the lat and lng for each of it's points
        Dim arrSys As System.Array
        Dim ienumSysColl As System.Collections.IEnumerator
        Dim intPointCount As Long
        Dim objLoc As MapPoint.Location
        Dim objShape As MapPoint.Shape
    
        For Each objShape In objMap.Shapes
    
            arrSys = objShape.Vertices
            ienumSysColl = arrSys.GetEnumerator
            intPointCount = UBound(objShape.Vertices)
    
            For i = 0 To intPointCount
    
                ienumSysColl.MoveNext()
                objLoc = ienumSysColl.Current
    
                Console.WriteLine("Point " & i & _
                        ":       lat: " & objLoc.Latitude & _
                        "       lng:" & objLoc.Longitude)
    
            Next
    
        Next
    This works but I can't help but think there has to be a cleaner, more efficient way of accomplishing this task. A For Loop inside of a For Loop? One thing I think would help clean it up would be if I could just say "use that polygon" ... instead of looping through each Polygon (which right now isn't a problem because there is only one).

    Is there a better, more efficient way of doing this? Please remember that I am very new to both VB 2005, OOP and Mappoint so if you can help please explain things to me like I'm 10 years old . Any and all help is greatly appreciated.

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Looping through Vertices of PolyLine?

    Hi,

    Your approach seems fine
    You have a for loop in a for loop because foreach is like a loop. Only consider that foreach does not garantie the sequence (depending how the interface is written). So you code seems fine !

    As for OOP you have to think an object as a black box. An object has inputs (properties, methods), and outputs (events, properties). An well written object does not now about objects it does not belong to or way around. Whit that in mind you are thinking OOP

  3. #3
    OOT
    OOT is offline Junior Member Yellow Belt
    Join Date
    Dec 2006
    Posts
    19

    Re: Looping through Vertices of PolyLine?

    Quote Originally Posted by Wilfried View Post
    Hi,

    Your approach seems fine
    You have a for loop in a for loop because foreach is like a loop. Only consider that foreach does not garantie the sequence (depending how the interface is written). So you code seems fine !

    As for OOP you have to think an object as a black box. An object has inputs (properties, methods), and outputs (events, properties). An well written object does not now about objects it does not belong to or way around. Whit that in mind you are thinking OOP
    Wow. Thank you for the answer. I was expecting laughter and ridicule about my code. It does seem to be working. I will have to figure out some way of letting the user select the polygon before retrieving the vertices (don't need all of them if they only want the one's from one polygon).

    Thank you also for the explanation on how to approach OOP. I keep reading different tutorials but most seem to think that you're reading the tutorial because you already understand OOP - definitely not the case with me.

    Thank you again for the help and the advice on how to approach it. It is very much appreciated.

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Looping through Vertices of PolyLine?

    Hi,

    You can use SelectionChange event to check what is selected.

    About the OOP I dont know a good tutorial.

    1 advantage of using objects that have multiple instances is: The code is only 1 time in memory, only the data is there multiple times. That is because the first argument of an object method is a pointer to the object data itself, so the code uses this pointer and offsets from it to have it's own data.

    If you dont need multiple instances then choose from what you wants an separate object to have readable, understeandable code for happy maintenance later

    Dont use cross references. Make an object as a "black box". You put something in it and it give you something back, for example in an event. Very easy for re-use in other projects then.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Vertices and VB.Net
    By alon in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 02-19-2010, 04:31 PM
  2. How to get the Locations for the 4 vertices of a Square?
    By cx123 in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 10-26-2004, 11:01 AM
  3. Bug on Polyline and line
    By Maverick in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 02-28-2003, 07:10 AM
  4. How to determine the length of Shape.vertices in Delphi?
    By schuchhardp in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 12-13-2002, 05:45 AM
  5. Zip codes or cities vertices or shapes
    By Claude VERDIER in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 09-17-2002, 06:21 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