How to use the Generate Service Areas in Python

1375
4
Jump to solution
01-25-2017 11:59 AM
AmberTobin
New Contributor III

Hi All,

I am trying to use the Generate Service Areas tool in python. I used Model Builder to fill in my perimeters and exported it to a python script. I then cleaned the code up because the tool uses barriers that are in memory. I'm using the ESRI 10.2 Streets SDC.

I am getting the error: 

ExecuteError: ERROR 000622: Failed to execute (Generate Service Areas). Parameters are not valid.
ERROR 000800: The value is not a member of USE_HIERARCHY | NO_HIERARCHY.

I put breaks in the code so I could try to figure out what part had an issue. The error is thrown on line 36 which is the input that comes after Travel_Mode. In the help there are no perimeters after Travel_Mode but in ArcMap the results input shows 'Overrides:'. I'm not trying to do anything fancy just the bare bones.

Any help would be greatly appreciate! 

This is my code: 

# Import arcpy module
import arcpy
arcpy.CheckOutExtension("Network")

# Local variables:
PDS1 = "Z:\\Amber\\Geocodes\\AGO\\Cert Geodatabase.gdb\\Opioid_Treatment_Program_Methadone_Clinic"
Break_Values = "30"
Break_Units = "Minutes"
streets = "Z:\\ArcGIS\\10.2\\streetmap_na\\data\\streets4"
Attribute_Parameter_Values = "Z:\ArcGIS\10.2\streetmap_na\data\Attribute_Parameter_Values.dbf"
Drive_Times = "Z:\\Amber\\Geocodes\\AGO\\Cert Geodatabase.gdb\\Drive_Times2"
Solve_Succeeded = "true"
Output_Network_Analysis_Layer = ""
restrictions = "'Driving a Passenger Car';'Avoid Service Roads';'Avoid Pedestrian Zones';'Avoid Walkways';'Avoid Roads for Authorities';'Avoid Private Roads';'Avoid Unpaved Roads';'Through Traffic Prohibited';'Avoid Express Lanes';'Avoid Carpool Roads'"
attribute = "Z:\ArcGIS\10.2\streetmap_na\data\cfcc.sdc"

# Process: Generate Service Areas
arcpy.GenerateServiceAreas_na(PDS1, Break_Values, Break_Units, streets, Drive_Times, "TRAVEL_TO", "",\
"ALLOW_UTURNS", "Time", "Minutes", "Length", "Miles", "USE_HIERARCHY",\
restrictions,\
Attribute_Parameter_Values,\
"20 Kilometers", "EXCLUDE", "\"SDC Edge Source\" #", "NO_MERGE", "RINGS", "SIMPLE_POLYS", \
"", "10 Meters", "", "", "", "", "",\
"", "", "", "", \
"NO_SAVE_OUTPUT_LAYER", \
"GEO_LOCAL", \
"CUSTOM"\
"")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
AmberTobin
New Contributor III

Hi All,

Thank you Dan and Melinda for your comments. I have been in contact with ESRI Support. There are a lot of parameters that are used in memory. It is matter of weening them out. Turns out that the Attribute_Parameter_Values needs to be left out because it is a record set and the python tool doesn't like it. When I ran the tool in ArcMap I found the table it was referencing and then I copied it and referenced it in my python code thinking that it could affect the shape of the service area. When I took it out the service areas drew fine (I compared it to the ones that were drawn using the tool in ArcMap). My original code left out some of the optional parameters where there was supposed to be double quotes for the barriers. I had double quotes in originally and still had an issue. Below is my new code that works.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Drivetimes2.py
# Created on: 2017-01-25 12:03:06.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
arcpy.CheckOutExtension("Network")

# Local variables:
PDS1 = "Z:\\Amber\\Geocodes\\AGO\\Cert Geodatabase.gdb\\Opioid_Treatment_Program_Methadone_Clinic"
streets = "Z:\\ArcGIS\\10.2\\streetmap_na\\data\\streets"
Break_Values = "30"
Break_Units = "Minutes"
Time_Attribute = "Time"
Time_Attribute_Units = "Minutes"
Distance_Attribute = "Length"
Distance_Attribute_Units = "Miles"
Attribute_Parameter_Values = "Z:\ArcGIS\10.2\streetmap_na\data\Attribute_Parameter_Values.dbf"
Drive_Times = "Z:\\Amber\\Geocodes\\AGO\\Cert Geodatabase.gdb\\Drive_Times2"
Solve_Succeeded = "true"
Output_Network_Analysis_Layer = ""
restrictions = "'Driving a Passenger Car';'Avoid Service Roads';'Avoid Pedestrian Zones';'Avoid Walkways';'Avoid Roads for Authorities';'Avoid Private Roads';'Avoid Unpaved Roads';'Through Traffic Prohibited';'Avoid Express Lanes';'Avoid Carpool Roads'"



# Process: Generate Service Areas
arcpy.GenerateServiceAreas_na(PDS1, Break_Values, Break_Units, streets, Drive_Times, "TRAVEL_TO", "", "ALLOW_UTURNS", "", "", "", Time_Attribute, Time_Attribute_Units, Distance_Attribute, Distance_Attribute_Units, "USE_HIERARCHY", restrictions, "", "20 Kilometers", "EXCLUDE", "\"SDC Edge Source\" #", "NO_MERGE", "RINGS", "SIMPLE_POLYS", "", "10 Meters", "", "", "", "", "", "", "", "", "", "NO_SAVE_OUTPUT_LAYER", "GEO_LOCAL", "CUSTOM", "")

 

View solution in original post

0 Kudos
4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

it might be worthwhile emulating the script example in the help topic Generate Service Areas—Help | ArcGIS Desktop  where they explicitly define the variables that they are using and assign them parameter values, then you can skip the rest of the unused parameters.  It makes it much easier to read and maintain because of you miss out a parameter, then the sequence gets out of order and a value that is supposed to be for one parameter becomes assigned to its predecessor raising an error.

0 Kudos
AmberTobin
New Contributor III

Hi Dan,

Thanks for your response. Usually I go to the code at the bottom of the help but this time there is so much added stuff in the code that it is not helpful. I've tried to take out the unused parameters but my code encounters an error and won't run. 

0 Kudos
MelindaMorang
Esri Regular Contributor

The error message to me indicates that your parameters are out of order.  It must be looking at the value of one of your other parameters which you have accidentally put in the place where the hierarchy setting should go.  Double-check your parameter order, or (maybe easier), use explicit keywords when setting each parameter.  For example,

arcpy.GenerateServiceAreas_na(Facilities=PDS1, Break_Values=Break_Values, Break_Units=Break_Units, Network_Dataset=streets, ...

I'm using the parameter names as specified in the tool documentation.  You can leave out optional parameters for which you just want the default, and the parameter order doesn't matter.

0 Kudos
AmberTobin
New Contributor III

Hi All,

Thank you Dan and Melinda for your comments. I have been in contact with ESRI Support. There are a lot of parameters that are used in memory. It is matter of weening them out. Turns out that the Attribute_Parameter_Values needs to be left out because it is a record set and the python tool doesn't like it. When I ran the tool in ArcMap I found the table it was referencing and then I copied it and referenced it in my python code thinking that it could affect the shape of the service area. When I took it out the service areas drew fine (I compared it to the ones that were drawn using the tool in ArcMap). My original code left out some of the optional parameters where there was supposed to be double quotes for the barriers. I had double quotes in originally and still had an issue. Below is my new code that works.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Drivetimes2.py
# Created on: 2017-01-25 12:03:06.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
arcpy.CheckOutExtension("Network")

# Local variables:
PDS1 = "Z:\\Amber\\Geocodes\\AGO\\Cert Geodatabase.gdb\\Opioid_Treatment_Program_Methadone_Clinic"
streets = "Z:\\ArcGIS\\10.2\\streetmap_na\\data\\streets"
Break_Values = "30"
Break_Units = "Minutes"
Time_Attribute = "Time"
Time_Attribute_Units = "Minutes"
Distance_Attribute = "Length"
Distance_Attribute_Units = "Miles"
Attribute_Parameter_Values = "Z:\ArcGIS\10.2\streetmap_na\data\Attribute_Parameter_Values.dbf"
Drive_Times = "Z:\\Amber\\Geocodes\\AGO\\Cert Geodatabase.gdb\\Drive_Times2"
Solve_Succeeded = "true"
Output_Network_Analysis_Layer = ""
restrictions = "'Driving a Passenger Car';'Avoid Service Roads';'Avoid Pedestrian Zones';'Avoid Walkways';'Avoid Roads for Authorities';'Avoid Private Roads';'Avoid Unpaved Roads';'Through Traffic Prohibited';'Avoid Express Lanes';'Avoid Carpool Roads'"



# Process: Generate Service Areas
arcpy.GenerateServiceAreas_na(PDS1, Break_Values, Break_Units, streets, Drive_Times, "TRAVEL_TO", "", "ALLOW_UTURNS", "", "", "", Time_Attribute, Time_Attribute_Units, Distance_Attribute, Distance_Attribute_Units, "USE_HIERARCHY", restrictions, "", "20 Kilometers", "EXCLUDE", "\"SDC Edge Source\" #", "NO_MERGE", "RINGS", "SIMPLE_POLYS", "", "10 Meters", "", "", "", "", "", "", "", "", "", "NO_SAVE_OUTPUT_LAYER", "GEO_LOCAL", "CUSTOM", "")

 

0 Kudos