spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
Toolbar
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2009
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Sponsors
 Order

MapPoint 2009

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
ViaVirtualEarth
SVG Tutorials
MapPoint

Map Visitors

 Direct Media

IT support London
Connect is a London based Personal Computing company. We can provide you with unlimited access to an IT helpdesk and on-site support.

ink refill
Get an ink refill online from us. Black, cyan, magenta and yellow! Full refilling equipment and instructions with diagrams. Check it out!

Flights Lanzarote
Volcanic landscapes to explore and warm white sandy beaches to relax on. For flights to Lanzarote search Holiday Hypermarket.

Greece Holidays
Greece is rich in modern and ancient history making for a fantastic holiday destination. On The Beach holidays specialise in cheap holidays.

Bulgarian property >>
Now is a great time to purchase Bulgarian property at good prices.

Cheap Flights to Miami
Search through the wide selection of airlines, travel agents and tour operators offering cheap flights to Miami at dealchecker.co.uk! See now!

Crete
Crete- the largest and most spectacular of the Greek islands is a possibility for your next vacation. Check out Ulookubook.com for great bargains.

Furnished Offices London
MLS can help you with top quality furnished offices in London. Present your company in a prestigious and positive manner!

  ARTICLES  


Finding the Starting Point of a Route

Nico Bontenbal shares a method for determining the starting point of a route by examining the pixels in the map image using Window API calls

For some time I have tried to find a way to determine the coordinates of the starting point of route segments. I want to be able to send these coordinates to my basic Garmin GPS. I've written code that sends the points of a polyline to my GPS, but I always have to trace a route by hand because MapPoint only returns the middle of a route segment and not the start.

The 'Reverse geocoding, another method' article gave me hope that by using the extrapolation technique I would be able to find the starting points of all the route segments. This works for rather straight route segments, but on a roundabout this does not work; the middle of the route isn't in the middle of the start and end of the segment. While exploring this technique I came up with a completely different solution. I found out that when you select a route segment, a label with the instruction appears on the map at the start of the segment as shown in the images below.

Route Starting Point

On an enlargement you can see the individual pixels of the map:

Route Starting Point Enlarged

I found out that by using the GetPixel and GetBitmapBits API calls I could analyze the map bitmap and find the location of this label and therefore the starting point of a route segment. There are many disadvantages to this technique. It is slow and the different maps are 'flashing' over the screen. Also I have to improve the technique further because it is not working 100%. Nonetheless, because I saw in the forum that I'm not the only one who wanted to solve this problem, I decided to share the technique.

When you use this code:

    objmap.ActiveRoute.Directions(intSegment).Select
    objmap.ActiveRoute.Directions(intSegment).Location.GoTo
    objmap.Altitude = objmap.Altitude * 2
MapPoint wil display a map something like the one in the example above. By using quite a complicated set of API-calls it is possible to scan this map for the location of the label. By using the XYToLocation function these coordinates can be transferred into a Mappoint location object.

I've written a GetRouteSegmentStartLocation function (download code) that does just this. It accepts a MapPoint map object and the number of the route segment and displays the route segment on screen. The function then uses the GetBitmapBits API-call (along with some others) to transfer the map into an array. After this it is easy to retrieve the colours of the individual pixels of the map.

The map is 'traced' for the 'signature' of the top of a label. I've defined the signature as: a black pixel with a white pixel 1 and 14 pixels below it, and a black pixel 15 pixels below it. This is a very simple definition of the 'signature' but it works most of the times. Improving the signature is one of the areas of the technique that needs improvement. When the top of a label is found the function scans the bitmap to the left to find the left border of the caption. When it finds the left border the start of the route segment (white dot) is 4 pixels to the left and 4 pixels to the top of the upper left corner of the label.

For performance reasons the bitmap is not scanned line by line. I found that most of the time the label is near the middle of the map so the map is first scanned at the middle. If a caption is not found there, the map it scanned at 3/4 and 1/4 of it’s width, then at 7/8, 5/8, 3/8 and 1/8 etc. until the label is found.

When you put all this together you get the code example you see at the end of this article. The Main procedure loops through all the segments of a route and puts a pushpin at the start of all of them.

To use this example copy the code into a VB(A) project and set a reference to MapPoint. Then start Mappoint and create a route. After this the Main procedure in the code can be run. Ideveloped and test the code in the European version of MapPoint, and it works with the US version as well.

As I said before, the signature of the label needs improvement. This can be done by adding more rules to the signature. For instance, when scanning to the left to find the left border all pixels in between should be whiteor at least 10 pixels to the left or to the right of the top of the label should be black (with white pixels below), etc.

I found that sometimes when the route is selected, the label is not displayed on the map. This is why the GetRouteSegmentStartLocation function stops scanning the map after it has scanned 64 lines;after this it assumes there is no label on the map.

When the selected route segment is large, the map is zoomed out to show the entire segment. This way the XYToLocation function is getting less accurate. This can be improved by scanning the map again after the (inaccurate) location is found, but this time at maximum zoom.

If anyone improves this example, please report these improvements back to MP2Kmag. I hope together we can make this code really useable (perhaps even in a production environment).

Also I can imagine other uses for the 'scan the map pixel by pixel technique' such as the ability to trace a complete route, a road, or a postal code area.

Discuss this story in the forum.

Author: Nico Bontenbal
Email: nico(AT)xsoffice.nl
URL: http://www.xsoffice.nl
Nico Bontenbal has developed MS Access applications for the last 10 years. Many of these applications use a link to MS Word and MS Excel. When he bought a Garmin Etrex GPS half a year ago MS MapPoint caught his attention. Just for fun he tried to link the GPS to MapPoint so he could plan a route in MapPoint and send it to the GPS, and project the trace log of the GPS on a MapPoint map. But he found out MapPoint can also be used with the MS Access applications he develops. For example to plot the locations of addresses in a database on a map.

Nico works as a contractor under the name XS-Office (www.xsoffice.nl, links to a site in Dutch). He lives and works (in that order) in Alphen aan den Rijn, Netherlands (52.1185 4.6560).



Google
 
MP2Kmag Internet


 Recent Discussion
-Postcode Data- Northern Ireland
-Live Maps updated in China
-Testing for point in Polygon with Javascript
-Live Search Maps Improves Internationally
-Help with Routing
-MapForums Newsletters
-Virtual Earth Based NYCT Trip Planner Surpasses 10K Daily User Milestone
-multiple distance queries
-Ask.com Migrates off of DeCarta. What’s the size of the self-hosted map market?
-Ask Maps Now Using Virtual Earth
-Importing LatLongs and postcodes from excel
-Side by Side comparison 2006 and 2009
-Mappoint failed to load error..
-"The Virtual Earth Map Control is HUGE!" Or, is it?
-Checking the vertex within the shape
-Looking for help with using Virtual Earth for broadcasts
-Hi from a broadcaster in Ireland
-Bandwidth Exceeded
-Hi... getting started
-Mappoint 2006 US version
-ESRI Shapefile Layers on a Virtual Earth Map
-Dear Forum,
-Queryshape not returning all records
-Somebody Steal Your Blog?
-Microsoft Environment Group
 Resources
Browse GIS books and periodicals
Best Car Contract Hire Lease Save
Find a MapPoint Partner or Consultant
Real Estate Thornbrook Subdivision
Excellent Great Loop Travel Guide


Want Your Site To Appear Here?

   © 1999-2008 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006 are either trademarks or registered trademarks of Microsoft.

• Replacement Cordless Phone Batteries from DSMiller
Improve your career with a computer degree LocalEDU.com
• Tim Cohn's Marketing Strategy Consultancy
• Buy Toner, Ink Cartridges & Drums at Marquee Office Solutions
• Looking for Dry Erase Boards? See Dry Erase Boards • The Search Starts Here Used Cars
• 5339 - We Know Bikes: Road Bikes / Triathlon Bikes / Mountain Bikes / BMX Bikes
• Buy Your Car Used Cars, Car Lease and Contract Hire