MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Looping through Vertices of PolyLine?

This is a discussion on Looping through Vertices of PolyLine? within the MapPoint 2006/2009 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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  4 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 12-12-2006
OOT OOT is offline
Junior Member
Yellow Belt
 
Join Date: Dec 2006
Posts: 14
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 12-12-2006
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 12-12-2006
OOT OOT is offline
Junior Member
Yellow Belt
 
Join Date: Dec 2006
Posts: 14
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 12-12-2006
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/looping-through-vertices-polyline-5471.html

Posted By For Type Date
TagJungle - VB+2005 This thread Refback 03-28-2007 02:25 PM
Massachusetts Map and Map of Massachusetts - MapPoint State Map Gallery - MP2K Magazine This thread Refback 12-19-2006 07:46 PM
Colorado Map and Map of Colorado - MapPoint State Map Gallery - MP2K Magazine This thread Refback 12-14-2006 06:57 AM
The Magazine for MapPoint - MP2K Magazine This thread Refback 12-13-2006 06:14 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
How to get the Locations for the 4 vertices of a Square? cx123 MapPoint 2006/2009 Discussion 0 10-26-2004 10:01 AM
Vertices and VB.Net alon MapPoint 2006/2009 Discussion 2 08-26-2004 02:12 AM
Bug on Polyline and line Maverick MapPoint 2006/2009 Discussion 0 02-28-2003 06:10 AM
How to determine the length of Shape.vertices in Delphi? schuchhardp MapPoint 2006/2009 Discussion 0 12-13-2002 04:45 AM
Zip codes or cities vertices or shapes Claude VERDIER MapPoint 2006/2009 Discussion 2 09-17-2002 05:21 AM


All times are GMT -5. The time now is 03:47 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

Ski Resorts
Choose from the comprehensive range of ski resorts at Holiday Hypermarket. Search for ski holidays online at Holiday Hypermarket to find ski holidays that are right for you.

Honeymoon Holidays
Book your Honeymoon holiday with Travel Counsellors. A personal advisor will help you plan the perfect honeymoon holiday.

Flights to Canada
Looking for cheap flights to Canada? dealchecker.co.uk helps you compare prices from all major scheduled and charter airlines.

Holidays in Cuba
Holidays in Cuba are an eclectic mix of golden beaches, rich, colourful scenery and a proud cultural heritage. Book a break in Cuba now!

Cyprus
Before visiting Cyprus, make sure you are well informed to make the most of your holiday. Online at ulookubook.com you check out our useful travel guides. Find out all about the Cyprus nightlife, shopping, eating and customs.

Compare holiday prices
Compare holiday prices online where you can see all the possibilities at Travel.co.uk

Florida Holidays
Take a sunny holiday break! Find info on Florida holidays at On The Beach!


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