Routing and Driving Directions with Local Data

2220
3
03-28-2013 07:50 AM
Labels (1)
ChuckDavidson
New Contributor
Hello,
I am trying to return driving directions when using a GeoprocessorTask with a local dataset.
The example I am following is the "Point-to-point routing in ArcGIS Runtime for WPF" available here
http://www.arcgis.com/home/item.html?id=21a58d089764402e90ce127894dec94e.

Routing works just fine, however I am unable to get Routing Directions from the resulting FeatureSet.
Questions
1) Can one derive directions from a GeoprocessingTask and .gpk (if so how)?
2) Is the RouteTask and subsequent ArcGISServer Network Dataset the only way to return directions?

Ultimately my goal is to derive Routing Directions with a local dataset and not have to go through ArcGISServer.

Thanks in advance.
0 Kudos
3 Replies
BrianLocke
Occasional Contributor II
I was able to Successfully do this can you perhaps put your code up, might be able to help?
0 Kudos
ChuckDavidson
New Contributor
Below is code

............................................................................


private LocalGeoprocessingService geoprocessingService;
private Geoprocessor geoprocessorTask;

// Creating the service and starting
public bool CreateNewRoute()
        {
            try
            {
                var source = ConfigUtils.ProjectLocation + ConfigurationManager.RouteLayer.SourceLayerName + ".gpk";
                geoprocessingService = new LocalGeoprocessingService(source, GPServiceType.SubmitJob);
                geoprocessingService.StartAsync((x) =>
                {
                    if (x.Error != null)
                        Log.Error(x.Error);
                });
                return true;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return false;
            }
        }

// Solving route with input locations
public bool SolveRoute()
        {
            try
            {
                geoprocessorTask = new Geoprocessor(geoprocessingService.UrlGeoprocessingService + "/Route");
                geoprocessorTask.Failed += new EventHandler<TaskFailedEventArgs>(GeoprocessorTaskFailed);
                geoprocessorTask.JobCompleted += new EventHandler<JobInfoEventArgs>(GeoprocessorTaskJobCompleted);

                routeTask = new RouteTask(geoprocessingService.UrlGeoprocessingService + "/Route");
                routeTask.SolveCompleted += new EventHandler<RouteEventArgs>(RouteTaskSolveCompleted);
                routeTask.Failed += new EventHandler<TaskFailedEventArgs>(RouteTaskFailed);

                List<GPParameter> parameters = new List<GPParameter>();
                List<Geometry> inputLocations = new List<Geometry>()
                {
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(routeStartPoint.X, routeStartPoint.Y,esriMap.SpatialReference),
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(routeEndPoint.X, routeEndPoint.Y,esriMap.SpatialReference)
                };

                FeatureSet featureSet = new FeatureSet(inputLocations);
                featureSet.GeometryType = GeometryType.Point;
                featureSet.SpatialReference = esriMap.SpatialReference;
                GPFeatureRecordSetLayer gpFeatureRecordSetLayer = new GPFeatureRecordSetLayer("Input_Locations", featureSet);
                parameters.Add(gpFeatureRecordSetLayer);

                geoprocessorTask.UpdateDelay = 2000;
                geoprocessorTask.SubmitJobAsync(parameters);

                return true;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return false;
            }
        }

//Route solved async, only features are returned, no way of deriving route direction objects
private void GeoprocessorTaskJobCompleted(object sender, JobInfoEventArgs e)
        {
            try
            {
                geoprocessorTask.GetResultDataCompleted += (s1, e1) =>
                {
                    if (e1.Parameter is GPFeatureRecordSetLayer)
                    {
                        GPFeatureRecordSetLayer gpLayer = e1.Parameter as GPFeatureRecordSetLayer;
                        var gphLayer = (GraphicsLayer)esriMap.Layers["LocalGraphicsLayer"];
                        gphLayer.ClearGraphics();

                        int i = 1;
                        foreach (Graphic graphic in gpLayer.FeatureSet.Features)
                        {
                            Symbol sym = new SimpleLineSymbol()
                            {
                                Color = ConfigurationManager.RoutingColorBrush,
                                Width = ConfigurationManager.RoutingWidth,

                            };
                            graphic.Symbol = sym;
                            gphLayer.Graphics.Add(graphic);
                        }
                    }
                };
                geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId, "Routes");
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
0 Kudos
ChuckDavidson
New Contributor
I was able to Successfully do this can you perhaps put your code up, might be able to help?


I have attached code in previous post.
The only other way I can think of it is to create a text file output from the Geoprocessing model using ModelBuilder
example here
http://resources.arcgis.com/en/help/main/10.1/index.html#//00570000009q000000

And then have a method that reads the output text; but it would seem that the directions can be exposed some other way
0 Kudos