Select to view content in your preferred language

NA : Barriers

731
6
11-30-2010 11:07 PM
carinestolz
Emerging Contributor
Hello,

I am using the Network Analyst with the Rest API to perform routing in the FlexViewer application.

I would like the Routing solver to take into account Barriers. At the moment, I send barriers to the solver through the "barriers" parameter of the solvetask in Flex.

Now, I would like the Routing Solver to use barrriers stored in a  database table instead of loading barriers through the REST API. Is there a way to specify the barriers datasource so that the solver can get them "automatically"  ?

Many thanks for your help.

Carine

PS : I hope my english is not too bad....
Tags (2)
0 Kudos
6 Replies
DmitryKudinov
Regular Contributor
Hi Carine,

Yes, you can do it as long as the feature class with barriers is part of the same map document which hosts Route layer:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/tasks/supportClasses/DataLayer.html

In order to speed up the processes of loading barriers from a layer, I would recommend to pre-calculate location fields on them. You can do it from ArcMap using the "Calculate Locations" GP Tool from Network Analyst Tools > Analysis category.

Dmitry
0 Kudos
carinestolz
Emerging Contributor
Thank you for your help, Dmitry.

It works perfectly.

Carine
0 Kudos
JulianoKersting
Emerging Contributor
Can you provide a quick example on how to use the DataLayer object as input for stops/barriers?
None of samples provide clear sample code on this.

I would like to use a set of Predefined locations instead of user defined map clicks.

Iim using Javascript API.
0 Kudos
DmitryKudinov
Regular Contributor
Hi Juliano,

Please take a look at the code below. In order to make it work, publish SanFrancisco tutorial MXD from ArcGIS 10.0 and change the value of the ROUTE_ENDPOINT variable in the code below accordingly:



[HTML]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>Simple Routing</title>

    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.3/js/dojo/dijit/themes/claro/claro.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.3"></script>

    <script type="text/javascript">
      dojo.require("esri.map");
      dojo.require("esri.tasks.route");

      var map, routeTask, routeParams;
      var stopSymbol, routeSymbol, lastStop;

      var ROUTE_ENDPOINT = "http://my_server/arcgis/rest/services/SanFrancisco/NAServer/Route";

      function init() {
        var initialExtent = new esri.geometry.Extent({"xmin":-13635300,"ymin":4545210,"xmax":-13623834,"ymax":4552853, "spatialReference":{"wkid":102100}});       
        map = new esri.Map("map", { extent: initialExtent });

        map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
        dojo.connect(map, "onClick", solve);

        routeTask = new esri.tasks.RouteTask(ROUTE_ENDPOINT);
       
        //setup the route parameters
        routeParams = new esri.tasks.RouteParameters();
        routeParams.stops = new esri.tasks.FeatureSet();
        routeParams.outSpatialReference = {"wkid":102100};
       
        dojo.connect(routeTask, "onSolveComplete", showRoute);
        dojo.connect(routeTask, "onError", errorHandler);

        //define the symbology used to display the route
        stopSymbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CROSS).setSize(15);
        stopSymbol.outline.setWidth(4);
        routeSymbol = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color([0,0,255,0.5])).setWidth(5);
      }

      dojo.addOnLoad(init);

      function solve() {
        var stops = new esri.tasks.DataLayer();
        stops.name = "Hospitals";
        stops.spatialRelationship = "esriSpatialRelContains";
        stops.geometry = map.extent;

        routeParams.impedanceAttribute = dojo.byId("impedance").value;

        routeParams.restrictionAttributes = [];
        if (dojo.byId('restDefault').checked)
          routeParams.restrictionAttributes = null;
        if (dojo.byId('restOneway').checked)
          routeParams.restrictionAttributes.push("Oneway");
        if (dojo.byId('restTurns').checked)
          routeParams.restrictionAttributes.push("RestrictedTurns");

        routeParams.stops = stops;
        routeTask.solve(routeParams);

      }

      //Adds the solved route to the map as a graphic
      function showRoute(solveResult) {
        map.graphics.clear();
        map.graphics.add(solveResult.routeResults[0].route.setSymbol(routeSymbol));
      }

      //Displays any error returned by the Route Task
      function errorHandler(err) {
        alert("An error occured\n" + err.message + "\n" + err.details.join("\n"));

        routeParams.stops.features.splice(0, 0, lastStop);
        map.graphics.remove(routeParams.stops.features.splice(1, 1)[0]);
      }
    </script>

  </head>
  <body class="claro">
    <table><tr><td>
      Click the map -
    </td><td>
      Solve on
      <select id="impedance">
        <option value="Minutes" selected="true">Minutes</option>
        <option value="Meters">Meters</option>
      </select>
    </td><td>
      Restrictions:<br/>
      <input type="checkbox" id="restDefault" checked="true" onchange="dojo.byId('restOneway').checked=false;dojo.byId('restTurns').checked=false;solve();">Use defaults</input><br/>
      <input type="checkbox" id="restOneway" onchange="dojo.byId('restDefault').checked=false;solve();">Oneway</input><br/>
      <input type="checkbox" id="restTurns" onchange="dojo.byId('restDefault').checked=false;solve();">RestrictedTurns</input><br/>
    </td></tr></table>
    <div id="map" style="width:600px; height:400px; border:1px solid #000;"></div>
  </body>
</html>

[/HTML]
0 Kudos
JulianoKersting
Emerging Contributor
Hi Again

I tried finding answers on forums and could not find, that is why I am asking here.

I have an network routing application for classroom scheduling that uses DataLayer as input for Stops.

I have a pre ordered sequence I want the route to be solved, for example MS-325, SS-1253, PF-4214, ENB-202, ES-718

When solving the route however it does not follow the sequence specified in the where clause.
(BLD_ID = 'MS' AND RM_ID = '325') OR (BLD_ID = 'SS' AND RM_ID = '1253') OR (BLD_ID = 'PF' AND RM_ID = '4214') OR (BLD_ID = 'ENB' AND RM_ID = '202') OR (BLD_ID = 'ES' AND RM_ID = '718')
I understand it is following the Record Order the rooms are stored in the table. Also, I tried the ORDER BY statement but doesn�??t seem to have any effect.

Is there a way to order the Route Stops when using a Datalayer?

Thank you very much for all and any help.
0 Kudos
DmitryKudinov
Regular Contributor
Hi Juliano,

A one way to do it would be through creating a RDBMS view on top of the Feature Class and specify Order Clause on it. On the other hand, it might require some SDE skills. It also will not be dynamic enough, shell you decide to change sorting depending on the client requests.

On the other hand, I just discovered that there is a way to pass 3D input locations even to the 10.0 NAServer REST endpoint: to do it you need to pass X, Y, Z attributes on the Stops (you do not even have to specify "geometry" part), e.g.:

{ 
"features"  : [
{
  "attributes" : {"X":481903.591, "Y":3768558.745, "Z":0}
},
{
  "attributes" : {"X":481849.220, "Y":3768533.156, "Z":9}
},
{
  "attributes" : {"X":481883.752, "Y":3768450.258, "Z":4.5}
}
]


Hope this will help,
Dmitry
0 Kudos