AnsweredAssumed Answered

Using condition in Field Mapping

Question asked by sotriant on Sep 24, 2018
Latest reply on Sep 24, 2018 by MMorang-esristaff

Below is the field mapping that i set up in order to create a Route layer with Network Analyst extension, using ArcGis10.4.1; 


fieldMappingsStops = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)
fieldMappingsStops["RouteName"].mappedFieldName = "Group_ID"    #correlates fields ie naStops attribute table with inStores attribute table.

 

The shapefile with mappedFieldName = "Group_ID" has distinct  values 108, 109 and 110. Is there any way to use a condition in order to set up Barriers for a specific route ?

(i.e for 110 route)

 if Group_ID.startswith('110'):
      fieldMappingsBR = arcpy.na.NAClassFieldMappings(outNALayer, pointBarriersLayerName)
      fieldMappingsBR["BarrierType"].defaultValue = 0                      #if it is restriction otherwise 1
      #Figure out the layer's impedance attribute
      solver_props = arcpy.na.GetSolverProperties(outNALayer)
      impedance = solver_props.impedance
      fieldMappingsBR["Attr_" + impedance].defaultValue = 1.4
      #Load restrictions features
      arcpy.na.AddLocations(outNALayer, pointBarriersLayerName, Barriers_shp, fieldMappingsBR)

 

Any help would be very much appreciated.

Outcomes