Location-Allocation failed because 'cutoff must be present for every entry in "Demand Points"'

12-15-2021 08:15 PM
Labels (2)
New Contributor III

I am trying to use the arcpy.nax.LocationAllocation() method to solve location-allocation for dozens of different scenarios. I have a demand points layer that contains a Cutoff_Minutes field. This field is populated for each of the 23,419 records within my demand points layer. However, when trying to call loc_alloc.solve() I'm getting the following error:

"A default cutoff is required, or a cutoff must be present for every entry in 'Demand Points'"

I have quadruple-checked my demand points layer and the Cutoff_Minutes field does not contain any NULL or missing values. I think I'm missing a way to tell the loc_alloc object how to use this field instead of the default value, which I am intentionally leaving NULL.

Any insight is appreciated!



# An example showing how to perform location-allocation analysis using inputs from feature classes.
import arcpy

nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_facilities = "C:/data/io.gdb/Facilities"
input_demand_points = "C:/data/io.gdb/DemandPoints"
output_lines = "C:/data/io.gdb/AllocationLines"

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

# Instantiate a LocationAllocation solver object
loc_alloc = arcpy.nax.LocationAllocation(nd_layer_name)
# Set properties
loc_alloc.travelMode = travel_mode
loc_alloc.travelDirection = arcpy.nax.TravelDirection.ToFacility
loc_alloc.problemType = arcpy.nax.LocationAllocationProblemType.MaximizeCoverage
loc_alloc.timeUnits = arcpy.nax.TimeUnits.Minutes
# loc_alloc.defaultImpedanceCutoff = 15
loc_alloc.lineShapeType = arcpy.nax.LineShapeType.StraightLine
# Load inputs
loc_alloc.load(arcpy.nax.LocationAllocationInputDataType.Facilities, input_facilities)
loc_alloc.load(arcpy.nax.LocationAllocationInputDataType.DemandPoints, input_demand_points)
# Solve the analysis
result = loc_alloc.solve()

# Export the results to a feature class
if result.solveSucceeded:
    result.export(arcpy.nax.LocationAllocationOutputDataType.Lines, output_lines)
    print("Solve failed")



3 Replies
Esri Regular Contributor

Do you get this message if you do not leave the default value null?

Even if there is a default value present, the field values on the demand points take precedence. So it should be ok to set a default value if that works. 

Jay Sandhu

0 Kudos
New Contributor III

Thank you for the reply. This error does not occur if I assign a default value. However, after investigating the results, I am seeing that none of the individual cutoff values within the demand points are actually being used. The default value is taking precedence over the Cutoff_Minutes field within my Demand Points. I think there is still an issue with how this field is being passed to the loc_alloc object when running the solve. I'm exploring using a field mappings class to explicitly tell the solver to use my Demand Points cutoff values, but I haven't made any progress yet. 

Esri Regular Contributor

The arcpy.nax api uses different field names that when using a layer so “Cutoff_Minutes” is not automatically used. In your scenario you can rename the input field or use a field map. Using the field map will look like:


# Map fields

fieldMap_demandPoints = loc_alloc.fieldMappings(arcpy.nax.LocationAllocationInputDataType.DemandPoints)

fieldMap_demandPoints["Cutoff"].mappedFieldName = "Cutoff_Minutes"


# Set the default value to use if the field value is null (optional)

fieldMap_demandPoints["Cutoff"].defaultValue = 15


# Load inputs

loc_alloc.load(arcpy.nax.LocationAllocationInputDataType.DemandPoints, input_demand_points, fieldMap_demandPoints)


You can always get the field names list if you don’t know what to map or which names will be used automatically: