Got it, appreciate the suggestion. I'm shifting from primarily using R so am still familiarizing myself with best practices in Python.
I've updated the code using the os.path.join() method, which required me to concatenate each level to build the full path. See in the code below:
# Imports
import arcpy
import os
import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor
# Paths
proj_dir = r"C:\Users\josephda\GitHub\osm"
streets_dir = os.path.join(proj_dir, "data", "raw", "Street_Centerlines", "Street_Centerlines.shp")
gtfs_dir = os.path.join(proj_dir, "data", "raw", "gtfs")
aprx_dir = os.path.join(proj_dir, "arcgis", "arcgis.aprx")
gdb_dir = os.path.join(proj_dir, "arcgis", "arcgis.gdb")
nw_dir = os.path.join(proj_dir, "arcgis", "arcgis.gdb", "TransitNetwork")
# Environment settings
arcpy.env.workspace = gdb_dir
# Set output coordinate system to NAD83 CA Albers
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(3310)
# Declare the project file
aprx = arcpy.mp.ArcGISProject(aprx_dir)
# List maps in the project
for m in aprx.listMaps():
print(m.name)
# List layers in the map
for lyr in m.listLayers():
print(lyr.name)
# Remove any existing layers except the basemap
if lyr.isBasemapLayer == False:
m.removeLayer(lyr)
aprx.save()
# Load the streets shapefile as a spatially enabled dataframe
streets_sed = pd.DataFrame.spatial.from_featureclass(streets_dir)
# Create fc from streets sed
streets_fc_dir = os.path.join(gdb_dir, "streets_fc")
streets_fc = streets_sed.spatial.to_featureclass(streets_fc_dir)
# Add restrict pedestrian field
arcpy.AddField_management("streets_fc", "RestrictPedestrians", "TEXT")
arcpy.CalculateField_management("streets_fc", "RestrictPedestrians", "'Y' if !circulatio! == 'Freeway' or !circulatio! == 'State Route' or !road_type! == 'Railway' else 'N'", "PYTHON")
arcpy.AddField_management("streets_fc", "ROAD_CLASS", "SHORT")
# Create the feature dataset
arcpy.CreateFeatureDataset_management(gdb_dir, "TransitNetwork", arcpy.SpatialReference(3310))
# Covert GTFS to transit data model
arcpy.transit.GTFSToPublicTransitDataModel(gtfs_dir, nw_dir, "NO_INTERPOLATE", "NO_APPEND")
# Copy streets to TransitNetwork feature dataset as "Streets"
nw_streets_dir = os.path.join(nw_dir, "Streets")
arcpy.CopyFeatures_management("streets_fc", nw_streets_dir)
# Delete the other copy of streets
arcpy.Delete_management("streets_fc")
# Connect the transit data model to streets
arcpy.transit.ConnectPublicTransitDataModelToStreets(nw_dir, "Streets", "100 Meters", "RestrictPedestrians <> 'N'")
It throws the same error
Unfortunately, this update still throws the same 000354 error when connecting the transit model to streets (at line 62). If I replace line 62 with the following:
arcpy.transit.ConnectPublicTransitDataModelToStreets(r"C:\Users\josephda\GitHub\osm\arcgis\arcgis.gdb\TransitNetwork", "Streets", "100 Meters", "RestrictPedestrians <> 'N'")
It throws the same error. This makes me think the issue isn't rooted in the path construction, but I could be wrong.