Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i hope using C# and how to blocked road and how to find shortest path in given map....
i use google map and my own create road map in selected area.
Posted
Comments
Tim Corey 8-Jun-12 15:31pm    
You don't really have a question here. Trying to tackle an entire solution as a question isn't really practical. Instead, Google for how to do this and get started. When you get stuck on a particular code bit, post a question here and we will try to help you.

As an algorithm, please try this. Now, I am assuming that you are using Google-map as you indicated.
1) Read the map as an image (metafile).

2) In Google map roads should have a specific value (or values in a narrow dynamic range). For example, larger roads in yellow and smaller roads in white colors.

3) First, do a thinning-processing (a morphological image processing). Thus, objects on the map become single pixel (s) or connection of the single pixels (roads). Also, see skelotonization of an image.
4) Then, define the departure point A and terminal point B. Save these coordinates in some variables. At the same time, define the pixel value for the road you are going to track (for example, a pixel value corresponding to a yellow pixel). Actually, this is a labeling issue in image processing. Sometimes it is called connectivity labeling. The main idea is extracting same object(s) or similar areas from an image.
5) Now, it’s time to start labeling (namely, compare the current pixel with its surrounding eight pixels- candidate pixels), if their values is a match count it as "1", and save it some place (as Matched Pixels). In general, among the eight pixels, only one pixel should be matched to the Current pixel (We did thinning-processing).
Now, the candidate pixel, which was matched, becomes the "Current Pixel”. This is an iteration process, repeat this. At the end, if everything is OK, you will reach the Terminal Point B. When, you got in the terminal point, stop the iteration and count all Matched Pixels, so that you can get distance (because you know the pixel’s size. Namely, in maps or satellite images, each pixel is corresponding to some area, e. g., XX- square meters. We call this spatial resolution). Now, you got a path and distance between A and B, [distance-1:D1].
6) Flip the image in X-direction, then rotate it 180-degrees. Now, the previous terminal point B becomes the new Departure point A. Repeat the steps of 4) and 5) again. Now, you got a path between the new A and B. If there are more than one road between A and B, you got two paths-the second distancel [distance-2: D2]. If there is only one road, you got almost the same distance with D1.
7) Then, C#, System.Math.Min(D1,D2). You got the answer.
 
Share this answer
 
v4
Comments
stefancode 10-Jun-12 9:07am    
thnx a lot sir,ur solution is great..in my project i'm doing image processing part..therefor ur solution is very important.
sir,do u have any sample project in this idea??
Soooo, you want to find the shortest path from point A to point B on an image alone?? No data on intersections and routes??
 
Share this answer
 
Comments
Maciej Los 8-Jun-12 17:42pm    
Dave, is it an answer?
Dave Kreskowiak 8-Jun-12 18:22pm    
The question you should be asking is "Is that really a question?" since there are details that are missing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900