Adding Line Barriers as NaLocations

821
2
Jump to solution
09-24-2016 11:41 AM
Highlighted
Occasional Contributor

I cant figure out how can i specify line barrier in setPolylineBarriersByRef  of NAServerRouteParams class, 

i know it takes INAServerLocations  but i cant figure out how to provide line in propertySet 

IPropertySet line = new PropertySet();

line.setProperty("paths", polyline);   // cant figure out this

IPropertySetArray pPropSets = new PropertySetArray();

pPropSets.add(line );

//Setting the Server Property Sets for the Network Analysis
INAServerPropertySets propSets = new NAServerPropertySets();


propSets .setPropertySetsByRef(pPropSets);

INAServerLocations2 serverLoc = (INAServerLocations2) propSets ;
return serverLoc;

Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor

Hi Haider,

The GISClient API you are referring to is deprecated since version 10.0. If you still have to use it, the following snippet may help:

protected INAServerPropertySets GetPolylineBarriers(int numberOfLocations2Load, double[] candidates)
{
  /* Assumes that candidates is an array of doubles
  * which contains 3 vertices (6 double numbers) per polyline-
  *
  * 3 * (x, y)
  */

  INAServerPropertySets res = new NAServerPropertySetsClass();
  res.PropertySets = new PropertySetArrayClass();

  for (int i = 0; i < numberOfLocations2Load; i++)
  {
    res.PropertySets.Add(new PropertySetClass());

    res.PropertySets.get_Element(i).SetProperty("Name", "Polyline " + (i + 1));

    IPolyline pl = new PolylineClass();
    IPointCollection pcol = pl as IPointCollection;

    object missing = Type.Missing;
    for (int j = 0; j < 3; j++)
    {
      IPoint pnt = new PointClass();
      int xIndex = i * 6 + j * 2;
      pnt.X = candidates[xIndex];
      pnt.Y = candidates[xIndex + 1];

      pcol.AddPoint(pnt, ref missing, ref missing);
    }

    res.PropertySets.get_Element(i).SetProperty("Shape", pl);
  }

  return res;

}

On the other hand, if you are using a newer version of ArcGIS Server I strongly recommend using REST API instead:

ArcGIS REST API 

View solution in original post

2 Replies
Highlighted
Occasional Contributor

Hi Haider,

The GISClient API you are referring to is deprecated since version 10.0. If you still have to use it, the following snippet may help:

protected INAServerPropertySets GetPolylineBarriers(int numberOfLocations2Load, double[] candidates)
{
  /* Assumes that candidates is an array of doubles
  * which contains 3 vertices (6 double numbers) per polyline-
  *
  * 3 * (x, y)
  */

  INAServerPropertySets res = new NAServerPropertySetsClass();
  res.PropertySets = new PropertySetArrayClass();

  for (int i = 0; i < numberOfLocations2Load; i++)
  {
    res.PropertySets.Add(new PropertySetClass());

    res.PropertySets.get_Element(i).SetProperty("Name", "Polyline " + (i + 1));

    IPolyline pl = new PolylineClass();
    IPointCollection pcol = pl as IPointCollection;

    object missing = Type.Missing;
    for (int j = 0; j < 3; j++)
    {
      IPoint pnt = new PointClass();
      int xIndex = i * 6 + j * 2;
      pnt.X = candidates[xIndex];
      pnt.Y = candidates[xIndex + 1];

      pcol.AddPoint(pnt, ref missing, ref missing);
    }

    res.PropertySets.get_Element(i).SetProperty("Shape", pl);
  }

  return res;

}

On the other hand, if you are using a newer version of ArcGIS Server I strongly recommend using REST API instead:

ArcGIS REST API 

View solution in original post

Highlighted
Occasional Contributor

Thanks that worked, i.e. line.setProperty("Shape", polyline);   

Actually our requirement is to get multiple alternative route  , so our solution was to use SOE to avoid multiple call to server i.e. in the SOE find the route and provide that route as barrier for next  solve route.

Reply
0 Kudos