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

## 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. Junior Member Yellow Belt
Join Date
Dec 2006
Posts
19

## 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. 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. Junior Member Yellow Belt
Join Date
Dec 2006
Posts
19

## Re: Looping through Vertices of PolyLine?

Originally Posted by Wilfried
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. 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)

#### Posting Permissions

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