Routing with Local Data

6352
24
08-24-2011 01:03 AM
Labels (1)
JamesMcElroy
New Contributor
I want to do routing with local data instead of using a web service.  I've created my Network dataset and route layer successfully.  I exported it as a Map Pack and tried using that in the

_routeTask = new RouteTask("D:\\MyRoute.mpk");

line and then when I tried to run the

_routeTask.SolveAsync

command it returns failed with the error:
"An exception occurred during a WebClient request."
with an internal exception of:
"Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'."

So obviously it's expecting a URL and not a filepath in the constructor of the RouteTask, which is interesting since the FindTask and the Locator both accept filepaths. 

What am I doing wrong here?  Did I go wrong with exporting as a map pack?

Thanks,

James
0 Kudos
24 Replies
RalfGottschalk
Esri Contributor
Hi James,

You�??re not doing anything wrong, at this time the Runtime does not support the RouteTask with local resources.  Routing is supported by geoprocessing model and then creating a Geoprocessing Package (gpk) with runtime support enabled from that model.  We are looking into adding this support in the future.
0 Kudos
JamesMcElroy
New Contributor
Alright, I tried this, but I'm having a different problem.  If I right-click my "Make Route Layer" result in ArcGIS and share result as a geoprocessing package it lets me create the gpk, but doesn't have runtime support enabled.  But in Catalog, when I run the "Data Management Tools/Package/Package Result" tool and add the same "Make Route Layer" result and check the enable runtime checkbox (see error1a.jpg) it runs immediately, says successful, but doesn't actually create the file (see error1b.jpg).  So now what am I doing wrong?

Thanks,

James
0 Kudos
JamesMcElroy
New Contributor
*bump*....
0 Kudos
RalfGottschalk
Esri Contributor
James,

When using Geoprocessing with the Runtime you want to think of it in a similar way as you would when creating Geoprocessing services for Server.  For the Runtime you wouldn�??t just package a single tool. There are certain data types that are not supported as inputs and outputs, so you would want to massage these through the model and have the model produce the result you are looking for, in this case the route.

For example you would build a model that does your routing, something like taking the Make Route Layer -> Add Locations -> Solve -> Select Data and select your routes.  Set your Input Locations as a parameter and then change the data type to �??Feature Set�?�.  And set the Route result as the output Parameter.  Before you package your model you need to enable Runtime support through ArcMap�??s Options window on the Sharing tab.  After your run your tool you can package it with Runtime support enabled.  This will run a set of analyzers that will tell you if you are using any data types that are not supported, what license level you need your Runtime to be at, and what functionality packages (dlls) you need to include to run this model.  Once it�??s packaged, you can then consume it in the Runtime.
0 Kudos
JamesMcElroy
New Contributor
Hi Ralf,

Thanks for the reply.  I'm out of my depth here.  All I want to do is work with the SDK, and I don't have much experience using ArcMap.  Most of what you just said doesn't make any sense to me.

Below is what I want to do, a how-to or specific instructions would be most appreciated:

I have a shape file that contains a road network.  I want to take that and end up with a local dataset (I guess a gpx) that I can use with the LocalGeoprocessingService and RouteTask objects to do routing in my application. 

I have managed to use the same file to create both a mpx and an apx to display the data and do geocoding.  The last piece is the routing, and creating the gpx for routing appears to be the most complicated.  So, how do I create the package needed to do routing from a shape file?  Specific steps please or a link to a specific how-to.

Thanks,

James
0 Kudos
JamesMcElroy
New Contributor
This is where I've gotten.  As you can see I created a Network Dataset from my road shapefile.  That created the road_ND network dataset and the road_ND_Junctions layer.  Then I clicked on the "Network Analyst"/"New Route" option on the Network Analyst toolbar.  That created the "Route" layer and the items in the Left-hand Network Analyst box.

How do I go from here to a gpx that I can reference in my code to solve routing problems using the RouteTask?

Thanks,

James
0 Kudos
JamesMcElroy
New Contributor
Update:

From where I was previously, I tried using ArcToolbox/Network Analysis Tools/Make Route Layer, got that to build.  Then tried the right-click "share as" option in the result window.  This time it made the file for me.  I plugged it into my code and tried to do a routeTask and got this exception in the failed event

"Bad request: GET GPServer/solve The specified task was not found."

Now what?

Thanks,

James
0 Kudos
MichaelErlich
New Contributor II
Same issue here.  I have included the REST output for the URL of both the sample to ESRI's sample site (Route- NetworkAnalaysis ESRI_Route_NA) and the output calling the local service (ArcGISRuntime Server).

The pieces that are missing from my local gpk is the supported operations only include 'Exclude' and is missing 'solve'.  Also, I don't see any of the attributes that are part of the RouteTask.  So, is there any documentation on how to setup the route layer and/or GPK to include those items so that the gpk can work with the route task?  Or is there some other task that should be used for routing with a local service?

The setup code for the service is:
            _localGeoService = new LocalGeoprocessingService(@"D:\Map Data\TestRouteLayer.gpk", GPServiceType.Execute);
            _localGeoService.StartCompleted += new EventHandler<EventArgs>(service_StartCompleted);
            _localGeoService.StartAsync();


The setup code for the route task is:
_routeTask = new RouteTask(_localGeoService.Tasks[0].Url);

have also tried: localGeoService.Url and localGeoService.Url + "/Route" for assigning urls to the route task.
0 Kudos
RalfGottschalk
Esri Contributor
In order to run GP tools in the Runtime you really need to build a Model or create a Script tool.   James, I know you asked for steps, but I can�??t really describe how to build a model in a forum post, but here is the 10.1 help documentation that gets you started on Model Builder.
http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#/Tutorial_Creating_tools_with_ModelBuil...

When you build you model you want to think of it like you are building a Geoprocessing Service, so you need to make sure your input and output parameters are compatible with those of a GP Service.
http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#/What_is_a_geoprocessing_service/005700...

For this you will want to change your input location parameter as a Feature Set.
http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#//002w00000023000000.htm

So, here are the high level steps to building the model:
1. Enable Runtime support for sharing.
2. Create a Toolbox in ArcCatalog and add a Model to it.
3. Chain together a set of tools using your data, for this type of operation you would chain together Make Route Layer -> Add Locations -> Solve -> Select Data.
4. Set the appropriate inputs as parameters and change them to the appropriate type.  In this case the Add Locations tools input, you would change it to a Feature Set type of input.  This will allow you to use a GPRecordSetLayer in the API.
5. Run the model
6. Publish the result as a GPK.

Once you have created a GPK you�??ll need to consume it in the Runtime.  This is essentially the same as consuming a online GP service. 
http://resourcesbeta.arcgis.com/en/help/main/10.1/index.html#/Understanding_task_parameter_propertie...

For Beta 1, when you spin up your service you can paste the URL into a browser and explore the parameters to better understand how to code against it.  We are looking at ways to improve so it is easier to get this parameter info without the additional step.

We do have a little doc on creating packages for the Runtime here:
http://resourcesbeta.arcgis.com/en/help/runtime-wpf/help/#/About_Geoprocessing_packages/017000000057...

But I do think we need more documentation on this to help customers properly create GPKs, maybe even some sort of tutorial.  Our documentation is still a work in progress.

Mike, you wouldn�??t pass the GP service into the Rout Task.  The model would handle the creation of the route, and the output parameter would be your routing result.

I have a sample GPK that I am trying to figure out how to share with you guys that does point to point routing using the San Francisco sample data that comes with the standard desktop SDK.  It�??s too big to add as an attachment to this forum.  I�??ll post where it is when I figure out a way.  You could then open this in ArcMap, study it, and switch out the data with your own.
 
For now I added some pictures of the model, which you hopefully will find useful.
0 Kudos