NA : Barriers

11-30-2010 11:07 PM
New Contributor

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.


PS : I hope my english is not too bad....
Tags (2)
0 Kudos
6 Replies
Occasional 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:

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.

0 Kudos
New Contributor
Thank you for your help, Dmitry.

It works perfectly.

0 Kudos
New Contributor III
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
Occasional 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:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

<html lang="en">
    <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="">
    <script type="text/javascript" src=""></script>

    <script type="text/javascript">

      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(""));
        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);
        routeSymbol = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color([0,0,255,0.5])).setWidth(5);


      function solve() {
        var stops = new esri.tasks.DataLayer(); = "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)
        if (dojo.byId('restTurns').checked)

        routeParams.stops = stops;


      //Adds the solved route to the map as a graphic
      function showRoute(solveResult) {;[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);, 1)[0]);

  <body class="claro">
      Click the map -
      Solve on
      <select id="impedance">
        <option value="Minutes" selected="true">Minutes</option>
        <option value="Meters">Meters</option>
      <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/>
    <div id="map" style="width:600px; height:400px; border:1px solid #000;"></div>

0 Kudos
New Contributor III
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
Occasional 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,
0 Kudos