Problem with curbapproach

2592
2
10-15-2015 06:52 AM
Highlighted
New Contributor II

Hi, i have problem setting the curbapproach for some points while loading them with loadlocations in C#.

The code runs unter ArcGIS Desktop und Engine 10.2.1.

We want to calculate routes with curbapproach right for main roads and right/left for side roads.

In my sample i just wanted to test all my points mit curbaprroach right, i couldn't find sample code except for old c++ code i couldnt get through. i tried the set_DefaultValue("CurbApproach", "?") with 1 and "Right side of vehicle".

The result is always that the my assigned curbapproach ist not inherited.

public int LoadNALocations(ICursor inputPointFeatureCursor, INAContext naContext, string naClassName, string KeyfeldLayer)

  {

       if(inputPointFeatureCursor == null)

       {

           return 0;

    }

       INAClassLoader2 naClassLoader = new NAClassLoaderClass() as INAClassLoader2;

       var listOfAgents = new List<ESRI.ArcGIS.NetworkAnalyst.INALocatorAgent>();

    naClassLoader.Initialize(naContext, naClassName, inputPointFeatureCursor);

     

       int rowsIn = 0;

       int rowsOut = 0;

     

    naClassLoader.FieldMap.set_MappedField("Name", "Stuetzpunkte.ID");

    naClassLoader.FieldMap.set_DefaultValue("CurbApproach", "Right side of vehicle"); 

     

       int agentCount = naContext.Locator.LocatorAgentCount;

       for (int locIndex = 0; locIndex < agentCount; locIndex++)

    {

       listOfAgents.Add(naContext.Locator.get_LocatorAgent(locIndex));

    }

  // Remove the existing locator agents from the locator. This for loop is done in reverse order, because agents are being removed as the loop executes

       for (int locIndex = agentCount - 1; locIndex >= 0; locIndex--)

    {

        naContext.Locator.RemoveLocatorAgent(locIndex);

    }

       INALocatorLocationFieldsAgent naLocFAgent = new NALocatorLocationFieldsAgentClass();

    naLocFAgent.OIDFieldName = "Stuetzpunkte.SOURCEOID";

    naLocFAgent.SourceIDFieldName = "Stuetzpunkte.SOURCEID";

    naLocFAgent.PositionFieldName = "Stuetzpunkte.POSALONG";

    naLocFAgent.SideFieldName = "Stuetzpunkte.SIDEOFEDGE";

     

    ((INALocatorAgent)naLocFAgent).Bind(naContext.NetworkDataset, null);

    naContext.Locator.AddLocatorAgent(naLocFAgent as INALocatorAgent);

       try

    {

      naClassLoader.Load(inputPointFeatureCursor, null, ref rowsIn, ref rowsOut);

    }

       catch(Exception ex)

    {

      Prot.Meldung("Beim Laden der Stützpunkte ist ein Fehler aufgetreten:\n" + ex.ToString(), true);

           return 0;

    }

    ((INAContextEdit)naContext).ContextChanged();

       if (naContext.Locator.LocatorAgentCount == 1)

    {

            // Now remove the custom fields agent and add back the stored agents

       naContext.Locator.RemoveLocatorAgent(0);

            foreach (var agent in listOfAgents)

       {

          naContext.Locator.AddLocatorAgent(agent);

       }

    }

       return rowsOut;    

  }

Reply
0 Kudos
2 Replies
Highlighted
Occasional Contributor III

Hello! 

I think the problem might be the value you are trying to set.  Instead of using the text "Right side of vehicle", try using the integer enumeration value associated with that text.

0 = Either side of vehicle

1 = Right side of vehicle

2 = Left side of vehicle

3 = No u-turn

Reply
0 Kudos
Highlighted
New Contributor II

Thank you for your reply.

As I wrote in my text over the code example, i tried with "Right side of vehicle" and with 1, also with "1", but there was no impact on the solved result. it was always solved with standard "Either side of vehicle".

Reply
0 Kudos