Can't get cutoffs to work in script tool for service area

450
2
Jump to solution
10-26-2021 11:51 AM
StephenRhone
New Contributor III

I was able to put together a script that geocodes a given table of addresses and generates service areas for them, and I am currently in the process of converting it for use as a script tool.  I am having trouble with the command arcpy.na.MakeServiceAreaAnalysisLayer and its cutoffs variable.  I have set it up as a parameter in the script tool so that users can enter their own drive times, but no matter how I try to set it up, the output always defaults to the [5, 10, 15] drive times.

I know that when entering this at the command line, the desired cutoffs are to be separated by commas and enclosed by square brackets, as in my example above.  Based on other scripts I've done in the past, I set it up as follows:

DriveTime = arcpy.GetParameterAsText(9)
DTString = """[{0}]""".format(DriveTime)
NAServArea = arcpy.na.MakeServiceAreaAnalysisLayer(AGOL, "Service Area", "Driving Time (Miles)", "FROM_FACILITIES", DTString, None, "LOCAL_TIME_AT_LOCATIONS", "POLYGONS", "STANDARD", "OVERLAP", "DISKS", "0.1 Miles")

So if I enter 30, 60 into the script tool, it should pass [30, 60] into the command to set up the service area layer.  I am guessing it will come down to some kind of syntax quirk; hopefully it will be that simple.  Any help is appreciated.  Thanks!

0 Kudos
1 Solution

Accepted Solutions
StephenRhone
New Contributor III

Following additional research, I was able to solve my own problem.  I figured that even though the drive time string [30, 60] fit the correct format to be entered into the tool, it was still a string nonetheless, and the variable is required to be a double (i.e. numeric).  I figured out how to parse the string into actual numbers so that it would fit the format and return drive time polygons based on the given numbers.

DriveTime = arcpy.GetParameterAsText(9)
DriveTimeIntegers = [int(i) for i in DriveTime.split(", ")]

To give credit where credit is due, I found the solution at the site below.

stackoverflow.com/questions/15314421/in-python-how-do-i-split-a-string-into-multiple-integers

View solution in original post

0 Kudos
2 Replies
StephenRhone
New Contributor III

Following additional research, I was able to solve my own problem.  I figured that even though the drive time string [30, 60] fit the correct format to be entered into the tool, it was still a string nonetheless, and the variable is required to be a double (i.e. numeric).  I figured out how to parse the string into actual numbers so that it would fit the format and return drive time polygons based on the given numbers.

DriveTime = arcpy.GetParameterAsText(9)
DriveTimeIntegers = [int(i) for i in DriveTime.split(", ")]

To give credit where credit is due, I found the solution at the site below.

stackoverflow.com/questions/15314421/in-python-how-do-i-split-a-string-into-multiple-integers

0 Kudos
RachaelMurtaugh
New Contributor III

When calculating a service area with time as the factor, are you saying the field with the time for each line segment needs to be a double? I'm struggling to get it to calculate time accurately. I currently have that field as a float. 

0 Kudos