field_mappings["AdditionalTime"].mappedFieldName = turnoutTimeField not applying

05-22-2022 07:45 PM
New Contributor II

I am trying to generate a number of service profiles using the arcpy nax network analyst library. The idea is to create a profile for each  of the models (impedance  values) we use, and also some standard cut off times that we use.

The script appears to work but does not apply either the Additional Time mapped field name, or the default value. In the output facilities layer the value for all locations is 0.

I've made sure that the value in the turnout field is a double.

Any ideas what the issue could be.


import arcpy

roadNetwork = r"C:\aaa\rnm\2022_04.gdb\Core_VG2020\RoutingApplication_ND"
nd_layer_name = "Routing_ND"
#inFacilities = r"J:\projects\netmodels\04 Data\Turnout Times\FY2122_Q3\data.gdb\FY2022_Q3_Brigades_w_TOT"
inFacilities = r"C:\aaa\rnm\Statewide_Profiles\Resp_Profiles_2022_04.gdb\inside"

turnoutTimeField = "turnout"
additional_fields = ['turnout_id', 'short_name', 'brig_name', 'brig_no', 'distrct_no', 'turnout_mins',

toolOutput = r"C:\aaa\rnm\Statewide_Profiles\Resp_Profiles_2022_04.gdb"
outputName = "Resp_Profiles_2022_041"

models = ['ARRB_Min', 'ARRB_Mean', 'ARRB_Max', 'EmergencyServicesTime', 'GLM_Pumper_Off_Peak', 'GLM_Pumper_Peak',
          'GLM_Tanker_Off_Peak', 'GLM_Tanker_Peak']
breakValues = [8, 10, 20]
travel_mode_name = "CFA"

# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(roadNetwork, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["CFA"]

service_area = arcpy.nax.ServiceArea(nd_layer_name)
# Set properties
service_area.outputType = arcpy.nax.ServiceAreaOutputType.Polygons
service_area.geometryAtOverlap = arcpy.nax.ServiceAreaOverlapGeometry.Overlap
service_area.polygonDetail = arcpy.nax.ServiceAreaPolygonDetail.Standard

additional_fields_objects = [f for f in arcpy.ListFields(inFacilities) if in additional_fields]

field_mappings = service_area.fieldMappings(arcpy.nax.ServiceAreaInputDataType.Facilities,

field_mappings["AdditionalTime"].mappedFieldName = turnoutTimeField
field_mappings["AdditionalTime"] = 6.0

service_area.load(arcpy.nax.ServiceAreaInputDataType.Facilities, inFacilities, field_mappings)

for model in models:
    travel_mode.impedance = model
    travel_mode.timeAttributeName = model
    service_area.travelMode = travel_mode
    for cutoff in breakValues:
        service_area.defaultImpedanceCutoffs = cutoff
        result = service_area.solve()
        if result.solveSucceeded:
            output_fc = f"{toolOutput}\\{outputName}_{model}_{cutoff}"
            result.export(arcpy.nax.ServiceAreaOutputDataType.Polygons, output_fc)
            result.export(arcpy.nax.ServiceAreaOutputDataType.Facilities, output_fc + "_fac")
            print("Solve failed")


Tags (2)
0 Kudos
1 Reply
by MVP Regular Contributor
MVP Regular Contributor

Just guessing here for now, but I don’t think it likes the .notation. There’s no error, but no change either. I’ve found that field mappings work better if the whole fieldmap object is pulled out, modified, then reassigned.

field_mappings["AdditionalTime"].mappedFieldName = turnoutTimeField

Assign the field_mappings[‘AdditionalTime’] to a variable, change the ‘mappedFieldName’ property there, and reassign it back to field_mappings[‘AdditionalTime’]

tmp = field_mappings[‘AdditionalTime’]
tmp[‘MappedFld…’] = turnoutTimeField
field_mappings[‘AddititonalTime’] = tmp

0 Kudos