Select to view content in your preferred language

Dynamically changing Travel_Mode in PrepareTimeLapsePolygons

1080
5
Jump to solution
05-21-2023 08:59 PM
KD_
by
New Contributor II

I have no idea if this is possible, but thought it was worth asking in an effort to avoid manual work.

I'm accessing Transit Network Analysis Tools (v0.8.0) toolbox in a python notebook (Pro v3.1). My GTFS network is using the standard template available from ESRI. I want to run several scenarios of altered mode attribute parameters and would ideally define these in my script. I'm looping my scenarios which reference dictionaries to define the parameters for modified travel modes. But I can't get those new attributes or new modes to "stick" when I run the PrepareTimeLapsePolygons tool. Am I doing something wrong, can I tweak the source code somewhere, or am I doomed to manually create 10+ travel modes using the conventional interface?

Note: The script works when the travel mode manipulation is removed and I set the mode to "Public transit time" in line 16, so I'm confident my other variables in here are ok.

nd_layer_name="PT_network"
arcpy.nax.MakeNetworkDatasetLayer(PTNetwork,nd_layer_name)

for scenario in Scenarios_to_run:
    nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
    new_travel_mode = arcpy.nax.TravelMode(nd_travel_modes["Public transit time"])
    new_travel_mode.name = scenario
    attr_params = new_travel_mode.attributeParameters
    attr_params[('PublicTransitTime', 'Exclude modes')]=typedict[scenario]  #set type exclusion
    attr_params[('PublicTransitTime', 'Exclude lines')]=routedict[scenario]  #set route exclusion
    
    arcpy.TransitNetworkAnalysisTools.PrepareTimeLapsePolygons(
            Facilities=facilityfile,
            Output_Polygons=outputfc,
            Network_Data_Source=nd_layer_name,
            Travel_Mode=new_travel_mode, #also tried setting this to the name of the new mode(scenario)
            Cutoff_Times=[30],
            Cutoff_Time_Units="Minutes",
            Start_Day__Weekday_or_YYYYMMDD_date_=PTRunDate,
            Start_Time__HH_MM___24_hour_time_=PTStartTime,
            End_Day__Weekday_or_YYYYMMDD_date_=PTRunDate,
            End_Time__HH_MM___24_hour_time_=PTEndTime,
            Time_Increment__minutes_=time_increment,
            Travel_Direction=direction,
            Geometry_At_Cutoff="Disks",
            Geometry_At_Overlap=overlap_or_dissolve,
            Max_Processes=ParallelProcesses,
            Barriers=None,
            Precalculate_Network_Locations=True
        )

 

0 Kudos
1 Solution

Accepted Solutions
MelindaMorang
Esri Regular Contributor

I've fixed the problem and updated the toolbox.  You can get it from  ArcGIS Online or GitHub.

View solution in original post

0 Kudos
5 Replies
MelindaMorang
Esri Regular Contributor

Thankfully, this one has an easy solution!

You just need to set 

new_travel_mode.attributeParameters = attr_params

after modifying the travel mode.  The TravelMode object doesn't allow you to edit the attribute parameters in place.  It won't pick up the changes.

0 Kudos
KD_
by
New Contributor II

(note: I deleted my previous response as I was looking at the wrong thing when I tested the solution.)

Ok, I put that code in at line 11. Now when I run the script, I get an error "ERROR 000840: The value is not a String." stemming from line 16. If I change line 16 to be "Travel_Mode=scenario," the string name of my new mode, I get the error "ERROR 000800: The value is not a member of Public transit time | Public transit time with wheelchair"

Is it just a matter of turning off whatever type check is on "Travel_Mode" to allow it to accept a dictionary?

0 Kudos
MelindaMorang
Esri Regular Contributor

Oh dear, I believe this is actually a bug in the tool.  I see that for some reason the travel mode parameter is a string-type parameter instead of a travel mode.  I honestly can't remember why I implemented it that way years ago, but it has the effect of preventing this very reasonable workflow from working.

I think the fix should be straightforward but will require a bit of testing on my end.  Let me make sure I don't have anything else urgent to take care of today, and then I'll try to fix this for you.

0 Kudos
MelindaMorang
Esri Regular Contributor

I've fixed the problem and updated the toolbox.  You can get it from  ArcGIS Online or GitHub.

0 Kudos
KD_
by
New Contributor II

Awesome, thanks so much for your help as always.

 

 I honestly can't remember why I implemented it that way years ago

^ Story of my life!

0 Kudos