Routing with Local Data

6360
24
08-24-2011 01:03 AM
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
JamesMcElroy
New Contributor
Hi Ralf,

This is very helpful.  I was able to basically reproduce the model example in the screenshot you provided, and I added a couple stops to my network analyst toolbar in ArcMap so that it would run.  As you can see, it sees the two stops I provided, it says it ran successfully, but it doesn't put a result in the results window for me to be able to export.  Am I missing something here on this last piece?

Thanks,

James
0 Kudos
MichaelErlich
New Contributor II
With creating the geoprocessor service via the gpk from your description above, am I correct in that the RouteTask will only work with ESRI's routing service, and that we will need to use GeoProcessor.Execute instead for our own custom routing by supplying the necessary GPParameter list that corresponds to what the REST service call expects as input parameters to create a route?

Also, if the file is too big to post here, feel free to post on the ftp that I provided to you; if you don't mind.

Thanks,
Mike
0 Kudos
RalfGottschalk
Esri Contributor
James,

Glad you found that post helpful, I was worried that my post would just cause confusion.  Now that you have created the Model you don�??t want to use the Network Analyst toolbar to set your points, instead what you want to do is make sure that your input locations are set to the Feature Set data type.  Right-click on them in Model Builder, select Properties, Data Type tab select a Feature Set as the data type, and import the schema from a point feature class. (A blank one with the correct spatial reference is probably best for the initial test.) 

Now when you double click on your Model in ArcMap, you will see your Feature Set Parameters get added as Layers to your map.  Click on each parameter in the GP tool dialog and populate the parameters.  Then run the tool.  You should see a resulting route produced on the map.  Open the Results Window from the Geoprocessing menu, right-click on that result and share it as a runtime enabled GPK.  This will package the data, inputs, and the result.

You can then consume the GPK in the Runtime.  I�??ve attached some more pictures that hopefully helps.  In the first picture you can see I opened my model and populate the feature set with some points.  All my feature set get added as layers in the map automatically when I run the model.  Then I run the tool and in the second picture I get a result layer. (This is the output parameter)  You can then right click the result and share it as a Geoprocessing Package.         

Hi Ralf,

This is very helpful.  I was able to basically reproduce the model example in the screenshot you provided, and I added a couple stops to my network analyst toolbar in ArcMap so that it would run.  As you can see, it sees the two stops I provided, it says it ran successfully, but it doesn't put a result in the results window for me to be able to export.  Am I missing something here on this last piece?

Thanks,

James
0 Kudos
JamesMcElroy
New Contributor
Right-click on them in Model Builder, select Properties, Data Type tab select a Feature Set as the data type, and import the schema from a point feature class. (A blank one with the correct spatial reference is probably best for the initial test.) 

Now when you double click on your Model in ArcMap, you will see your Feature Set Parameters get added as Layers to your map.  Click on each parameter in the GP tool dialog and populate the parameters.  Then run the tool.  You should see a resulting route produced on the map.


This is the part that doesn't work.  They are set to a feature class type.  And I selected "Route/Stops" and "Route/Point Barriers" as the schemas.  I don't know what else to set them to, as the only "data" file I have is the street network shape file that I started from.  Then when I try to run it I get the error saying there isn't any valid input for a route, because there aren't any stops defined.  But when I tried defining stops (see yesterday's post) it didn't give me a result then either.

Am I missing something elementary?  I don't have a shape file with "stops" defined.  I have a shape file with a road network.  I have used that same shape file to create my map pack, my tile pack, my address locator, this is the last piece.

Thanks,

James
0 Kudos
RalfGottschalk
Esri Contributor
With creating the geoprocessor service via the gpk from your description above, am I correct in that the RouteTask will only work with ESRI's routing service, and that we will need to use GeoProcessor.Execute instead for our own custom routing by supplying the necessary GPParameter list that corresponds to what the REST service call expects as input parameters to create a route?

Also, if the file is too big to post here, feel free to post on the ftp that I provided to you; if you don't mind.

Thanks,
Mike


Mike,

You are correct.  To do local Point to Point routing you will need to do this through the Geoprocessor.  Sample code would look something like this:

{
   LocalGeoprocessingService pointToPoint = new LocalGeoprocessingService(@"MyGPK.gpk", GPServiceType.Execute);

   pointToPoint.StartAsync((x) =>
   {
      if (x.Error != null)
          MessageBox.Show("Error creating local GP service:\n" + x.Error.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
   });

}

// Write some code to populate input Graphics either from a geocode or whatever you like.
// {
// {

// Execute the tool
{
   Geoprocessor gp = new Geoprocessor(pointToPoint.UrlGeoprocessingService + "/PointToPointWBarriers");
   gp.ExecuteCompleted += new System.EventHandler<GPExecuteCompleteEventArgs>(gp_ExecuteCompleted);
   gp.Failed += new System.EventHandler<TaskFailedEventArgs>(gp_Failed);

   List<GPParameter> parameters = new List<GPParameter>();
   FeatureSet featureSet = new FeatureSet();
   featureSet.Features.Add(startPoint);
   featureSet.Features.Add(endPoint);
   GPFeatureRecordSetLayer inutFeatures = new GPFeatureRecordSetLayer("Input_Locations", featureSet);
   parameters.Add(inutFeatures);  
}

void gp_ExecuteCompleted(object sender, GPExecuteCompleteEventArgs e)
{
   foreach (GPParameter outParameter in e.Results.OutParameters)
   {
      if (outParameter is GPFeatureRecordSetLayer)
      {
         GPFeatureRecordSetLayer outputFeatures = outParameter as GPFeatureRecordSetLayer;
         foreach (Graphic graphic in outputFeatures.FeatureSet)
         {
             graphic.Symbol = this.Resources["LineSymbol"] as ESRI.ArcGIS.Client.Symbols.SimpleLineSymbol;
             graphicsLayer.Graphics.Add(graphic);
          }
      }
   }
}


I'll upload the sample package to your FTP site if I can't get it in a place where all the beta testers can get to it.
0 Kudos
RalfGottschalk
Esri Contributor
Ok, the sample GPK is uploaded.  You should be able to get to it here:
https://betacommunity.esri.com/files/download.aspx/PointToPointWBarriers.gpk?d=0D08C5CF1E0B4D2380C5A...

Only members of the Beta Community will be able to access it.  Let me know if you have troubles.
0 Kudos
JamesMcElroy
New Contributor
Bump to make sure you didn't miss my response two post above.

Thanks,

James
0 Kudos
RalfGottschalk
Esri Contributor
Bump to make sure you didn't miss my response two post above.

Thanks,

James


James,

Thanks for the bump, I did miss your response.  It sounds like your model isn�??t set up correctly.  Try downloading the sample GPK and study that and try running it as it is within the Runtime.  You can use any service and just zoom to San Francisco to get the right coordinates.  I beleive the data will solve if you use WGS 84 for your input points.

You can open the package in ArcMap by double clicking on it; the model will show up in the results window.  Then edit the model and replace it with your data.  See if you can get that to work, first in ArcMap and then the Runtime.

From your descriptions it sounds like you parameters are not set up properly.  To set it to a Feature Set, you have to edit the model and modify the properties of the parameters.   

Good luck and let me know how it goes.
0 Kudos
JamesMcElroy
New Contributor
Hi Ralf,

I get an access denied error trying to download the GPK from the link you provided.  My login doesn't appear to be allowed.

As I said in my previous post, my inputs are set as feature set and the schema imported from the route/stops and route/point barriers.  I have attached screenshots of the property panes from both.

Thanks,

James
0 Kudos
RalfGottschalk
Esri Contributor
Hi James,

To get access to the data you can do one of two things.  Log onto the Beta Community site first and then click the link in the forum and it will let you go through.  For some reason it doesn�??t let you put in your credentials from the link itself.  Or, if you are already on the site you can get to the gpk by clicking on the resources tab.  It will be called �??Samples �?? Point to Point Routing Sample GPK.�?�

It�??s a bit difficult to get to the bottom of what could be going on, does your Model successfully run?  One of your screen shots it looked like the parameters were not populated correctly.  Are you populating the input parameters from the Model dialog itself?  Once it is a feature set you should be able to run the model and when you select the input parameter your cursor will allow you to click on the map to populate the values of the feature set.  In one of your screen shots it looks like you are using a list of values, for your input.  This is not necessary because a feature set is essentially an in memory feature class and it accepts multiple inputs.

Would it be possible to send me your package?
0 Kudos