Hi,
I am using ArcGIS Pro 2.3.2 through Jupyter Notebook
I am trying to create a Service Area using Network Analysis (i.e., MakeServiceAreaAnalysisLayer_na) based on predefined distances identified in a field of the input table (i.e., field named 'cut_off'). I have created a field with the cutoff values in them formatted as '[2, 3, 4]'. Each feature in the point feature class has a different value in the cutoff value field. From the help files I can see that "This default cutoff value can be overridden on a per-facility basis by specifying individual break values in the facilities sublayer." Unfortunately I cannot find any example of how to do this. I have developed some code but it doesn't seem to override the default distances of "5, 10, 15" minutes.
Here is the example code that doesn't seem to work:
<SPAN class="comment token">#Import system modules</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os<SPAN class="punctuation token">,</SPAN> datetime
<SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">as</SPAN> np
<SPAN class="comment token">#Check out Network Analyst license if available. Fail if the Network Analyst license is not available.</SPAN>
<SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CheckExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"network"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Available"</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"network"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">raise</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ExecuteError<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Network Analyst Extension license is not available."</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Set environment settings</SPAN>
output_dir <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\afclark82\ChildCare_Version2"</SPAN>
input_gdb <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>output_dir<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Default.gdb"</SPAN><SPAN class="punctuation token">)</SPAN>
travel_mode <SPAN class="operator token">=</SPAN> <SPAN class="string token">"[Meters, DriveTime]"</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Environment settings set"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#The NA layers data will be saved to the workspace specified here</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> input_gdb
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token">#Set local variables</SPAN>
network <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>input_gdb<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Network"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NetworkDataSet"</SPAN><SPAN class="punctuation token">)</SPAN>
facilities <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"Locations\ChildCareLocations"</SPAN>
output_layer_file <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>output_dir<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SrvcAreasLyr.lyrx"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#verifying that the feature dataset "shortestpaths" is already in the geodatabase</SPAN>
<SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"ShortestPaths"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>network<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CreateFeatureDataset_management<SPAN class="punctuation token">(</SPAN>input_gdb<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ShortestPaths"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>facilities<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"cutoffs"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">==</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>facilities<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"cutoffs"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>CalculateField<SPAN class="punctuation token">(</SPAN>facilities<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"cutoffs"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'"[{}, {}, {}]".format(!Per50!,!Per62!,!Per75!)'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PYTHON3"</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Create a new service area"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Create a new service area layer.</SPAN>
result_object <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>MakeServiceAreaAnalysisLayer<SPAN class="punctuation token">(</SPAN>network<SPAN class="punctuation token">,</SPAN>output_layer_file<SPAN class="punctuation token">,</SPAN>travel_mode<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"FROM_FACILITIES"</SPAN><SPAN class="punctuation token">,</SPAN>cutoffs<SPAN class="operator token">=</SPAN><SPAN class="string token">"breaks_minutes"</SPAN><SPAN class="punctuation token">,</SPAN>polygon_detail<SPAN class="operator token">=</SPAN><SPAN class="string token">"HIGH"</SPAN><SPAN class="punctuation token">,</SPAN>geometry_at_overlaps<SPAN class="operator token">=</SPAN><SPAN class="string token">"OVERLAP"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Get the layer object from the result object. The service area layer can</SPAN>
<SPAN class="comment token">#now be referenced using the layer object.</SPAN>
layer_object <SPAN class="operator token">=</SPAN> result_object<SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Get the names of all the sublayers within the service area layer.</SPAN>
sublayer_names <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>GetNAClassNames<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Store sublayers"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Stores the layer names that we will use later</SPAN>
facilities_layer_name <SPAN class="operator token">=</SPAN> sublayer_names<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Facilities"</SPAN><SPAN class="punctuation token">]</SPAN>
polygons_layer_name <SPAN class="operator token">=</SPAN> sublayer_names<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"SAPolygons"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#The input data has a field for CentreID that we want to transfer to</SPAN>
<SPAN class="comment token">#our analysis layer. Add the field, and then use field mapping to transfer</SPAN>
<SPAN class="comment token">#the values.</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>AddFieldToAnalysisLayer<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">,</SPAN> facilities_layer_name<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"CentreID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>AddFieldToAnalysisLayer<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">,</SPAN> facilities_layer_name<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"cutoffs"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">)</SPAN>
field_mappings <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>NAClassFieldMappings<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">,</SPAN>facilities_layer_name<SPAN class="punctuation token">)</SPAN>
field_mappings<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"CentreID"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>mappedFieldName <SPAN class="operator token">=</SPAN> <SPAN class="string token">"CentreID"</SPAN>
field_mappings<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"cutoffs"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>mappedFieldName <SPAN class="operator token">=</SPAN> <SPAN class="string token">"cutoffs"</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"field mapping"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Load the day care centres as facilities.</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>AddLocations<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">,</SPAN> facilities_layer_name<SPAN class="punctuation token">,</SPAN> facilities<SPAN class="punctuation token">,</SPAN>field_mappings<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Add fields to the output Polygons sublayer for later use.</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>AddFieldToAnalysisLayer<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">,</SPAN> polygons_layer_name<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"CentreID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>AddFieldToAnalysisLayer<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">,</SPAN> polygons_layer_name<SPAN class="punctuation token">,</SPAN><SPAN class="string token">"cutoffs"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEXT"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Get sublayers to work with later</SPAN>
facilities_sublayer <SPAN class="operator token">=</SPAN> layer_object<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN>facilities_layer_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
polygons_sublayer <SPAN class="operator token">=</SPAN> layer_object<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN>polygons_layer_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#Get the Service Area Layers solver properties. This can be used to</SPAN>
<SPAN class="comment token">#set individual properties later without re-creating the layer.</SPAN>
solver_properties <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>GetSolverProperties<SPAN class="punctuation token">(</SPAN>layer_object<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>Solve<SPAN class="punctuation token">(</SPAN>result_object<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"added locations"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>