# Simple optimal route application

3424
15
11-07-2011 06:13 AM
New Contributor
I want to code a simple application using java that read data from street shapefile, calculate the shortest path between two vertices using an algorithm and display the route in MapBean of my app. What is want is a custom and simple route solver, for algorithm demo purpose only.

It might be simple task but the problem is that I am new with ArcGIS, and new with geographic field too. So I found many difficults in implementing the demo. I think the trouble is how to determine the adjacent edges of a vertex in the network. Is there any kind of junction connectivity table stored in shapefile  and how to read these data, using java.

Any help would be greatly appreciated !
Tags (2)
15 Replies
New Contributor
Thank you all !

My algorithm is an improvement of LPA*, thus, it needs a heuristic estimation like the one of A*.

As Michael said, I look at the coordinate system of my shapefiles, and found out that it is in "GCS_Assumed_Geographic_1". So, i change the Geographic Coordinate System to Projected Coordinate System using Project tool in ArcToolbox. (i changed it to NAD_1983_California_Teale_Albers, pretty uncertain about how they work :D). Is that OK?

After that, i re-create my network dataset and check out the distance using Pythagorean theorem. It work ! The result is real distance in meter 😄
New Contributor III
(i changed it to NAD_1983_California_Teale_Albers, pretty uncertain about how they work ). Is that OK?

It is up to you to decide which projection works best for your particular purposes, as there are certainly many to choose from, and each has their own unique properties. Here are some good resources to become more familiar with projections and their associated properties:

My inclination would be to suggest that you find a good equidistant projection (e.g., see here for an example), as their purpose is to preserve distances as best as possible, and this is what you are ultimately looking for in your algorithm. However, you must also keep in mind any other purposes you might require for your dataset as well.

I hope this helps.
New Contributor
Thank you, Michael !

I am going to work on the materials.....
New Contributor
I have two more questions regard to my problem. They're about GUI implementation:

- After running the algorithm and find a shortest route, how can I draw the route on map so that user can easily regconizes that route. I found out piece of code in C#. Can I do the same with Java (I use ArcEngine 9.3)
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/RoutingForm/00480000014m...

- How I can let user choose a junction or an edge on a map by visually clicking on those elements (for example, choose the start point)

Thanks for any help!
Esri Contributor
You are venturing out of my area of expertise, but I'll try to point you in the right direction.

- After running the algorithm and find a shortest route, how can I draw the route on map so that user can easily regconizes that route. I found out piece of code in C#. Can I do the same with Java (I use ArcEngine 9.3)
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/RoutingForm/00480000014m...

To draw the route on the map, you will need to have tracked the edges that you have in your solution.

Here is some code that will help go from an elements EID to getting the source feature underlying it:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_access_source_fe...

Once you have your set of source features, it is up to you on how to store it and display it.  It is probably more trouble that worth it to set up your work as a custom solver with its own network analysis layer that can be used to display results.

In your case, you can take the street features (and optionally, the junctions and turns) and output them as a feature class to a either a workspace on disk (FileGDB, SDE, SHP) or to an in-memory workspace.  Then load the feature class as a layer in the table of contents of your map.

Look around the Managing Data part of the SDK to find a way to manage your results.  Not sure this is the best possible way, but in your shoes, I would first look into in-memory workspaces.  Then, look into how to display data as layers in the TOC.  If this link doesn't get you there, then look around that general area of the SDK for other options.

- How I can let user choose a junction or an edge on a map by visually clicking on those elements (for example, choose the start point)

Once you have the point on the map where the user clicked, you need to find the nearest network location.  A good starting point would be this InArcMap portion of this SDK document about how to load points in ArcMap.

I hope all of this helps. Also, note that anything you can do with .NET, you should be able to do with Java, with minor adjustments.  That is why I link to the .NET SDK so much.  It has a lot more information in it than the Java SDK.
New Contributor
Thanks a lot, Patrick. I have my problems solved with your comments. (try to work out with in-memory Workspace and finally decide to use just a polyline to display the route :D)

My GUI is now functional. But the problem is that it run very slow, in compare with the running time of non-GUI app. For example, to calculate the route, non-GUI app only need ~1s, but the GUI take about 30s to finished :(. Both apps use the same code, same algorithm.

Could you give me some advice for speeding up this stuff ?

Thanks and MERRY CHRISTMAS TO ALL !!!

Phu Nguyen.