Select to view content in your preferred language

Service Area Solve with Python

469
4
Jump to solution
03-13-2026 01:52 PM
TerriWaddell1
Occasional Contributor

Hello,
I have a Pro project that uses Network Analyst to show 5-mile driving distances from the district's fire stations. I am using lines instead of polygons for the service area and I have several different service areas saved depending on which station I'm looking at. The fire station locations never change, but the roads in the area do change due to development/new subdivisions.

Normally I just open the map in Pro and press the "Run" button on the service area to have it update the drive distances. No parameters are changing, just the roads in the network may have a few additional roads, and it's overwriting the existing feature classes in the service area's feature dataset in the database. No problem there.

I'd like to automate the "press Run" aspect in a stand-alone python script that I can schedule to run occasionally. I've gone through tons of documentation online about this but cannot seem to find anything similar to what I'm trying to do.

Has anybody done this and can share some pointers? Can just read in the parameters from my project's existing service area and then "solve"? Or must I create the service area again in the python? If I have to create it again, can I overwrite the existing service area so I don't end up with dozens feature datasets in the database?

If it matters, I'm doing this in  ArcGIS Pro 3.5, not on AGOL. 

Many thanks for your time,
Terri

0 Kudos
1 Solution

Accepted Solutions
MelindaMorang
Esri Regular Contributor

You can write a Python script that accesses the Service Area layer from within the project and calls the Solve() tool on it.  It would be something like this (untested):

proj = arcpy.mp.ArcGISProject(path to your .aprx file)
map_obj = proj.listMaps()[0] # Or whichever index points to the correct map
lyr = map_obj.listLayers(your Service Area layer's name)[0]
arcpy.na.Solve(lyr)

 That specifically solves the layer IN the project.  I THINK that will work.

If you want to automate your entire workflow rather than solving an existing layer in a project, here's a tutorial about to create a script tool: https://pro.arcgis.com/en/pro-app/latest/help/analysis/networks/create-a-python-script-tool-using-ar...

View solution in original post

4 Replies
MelindaMorang
Esri Regular Contributor

Pressing the Run button just calls the Solve tool, so you should be able to schedule running the Solve tool just like any other geoprocessing tool.  Documentation: https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/basics/schedule-geoprocessing-t... 

0 Kudos
TerriWaddell1
Occasional Contributor

I didn't phrase my question well, so please allow me to clarify:  someday I'd like to be able to schedule the task to run, but not now.  For now, the end user needs to be able to run the python manually as needed from outside of Pro.  They have a network anaylst license and are logged into ArcGIS Pro but don't necessarily have it open when they run the script.  I haven't been able to get solve to work under these circumstances.

0 Kudos
MelindaMorang
Esri Regular Contributor

You can write a Python script that accesses the Service Area layer from within the project and calls the Solve() tool on it.  It would be something like this (untested):

proj = arcpy.mp.ArcGISProject(path to your .aprx file)
map_obj = proj.listMaps()[0] # Or whichever index points to the correct map
lyr = map_obj.listLayers(your Service Area layer's name)[0]
arcpy.na.Solve(lyr)

 That specifically solves the layer IN the project.  I THINK that will work.

If you want to automate your entire workflow rather than solving an existing layer in a project, here's a tutorial about to create a script tool: https://pro.arcgis.com/en/pro-app/latest/help/analysis/networks/create-a-python-script-tool-using-ar...

TerriWaddell1
Occasional Contributor

I'd tried several variations similar but they never worked; this one work perfectly.  Thank you!

0 Kudos