3

Using ArcGIS Desktop 10.1, I have 2 Feature Datasets in a geodatabase. One dataset contains bus routes and the other contains bus stops for each route. I want to create a script that will snap the bus stops to the vertex of the relevant bus route. There are over 100 routes and stops. They are stored in each dataset in order. They are named like this S102, S104 etc. for stops and B102, B104 for routes. I'm unsure about how to do a for loop that will get a stop and then get the right bus route

I've started writing a script. What I'm trying to do is get the last 3 characters of the stops ID (for S102 that would be 102) and then search for B + those characters in the routes dataset. I haven't gotten to the searching bit yet but I'm getting a Parsing error SyntaxError: invalid syntax (line 20) which is arcpy.env.workspace = RoutesD

import arcpy

StopsD = "C:\College Stuff\Dissertation\POWSCAR2011\Practice.gdb\Stops_temp"
RoutesD = "C:\College Stuff\Dissertation\POWSCAR2011\Practice.gdb\Routes_temp"

arcpy.env.workspace = StopsD
arcpy.env.overwriteOutput = True
StopsList = arcpy.ListFeatureClasses()

for Stops in StopsList:
        Stopname = Stops[1:4]
    Stopname2 = "B" + Stopname
        StopnameEx2 = "\"" + Stopname2 + "\""

    Routes = str(RoutesD) + "//" + "B"+ Stopname

    arcpy.env.workspace = RoutesD
    RoutesList = arcpy.ListFeatureClasses(Stopname2)
    for routes in RoutesList
        print routes

arcpy.env.workspace = StopsD
3
  • Your StopsD and RoutesD are pointing to feature datasets not workspaces.

To get a list of fc within a dataset try something like this:

workSpace = "C:\College Stuff\Dissertation\POWSCAR2011\Practice.gdb"
datasetList = arcpy.ListDatasets("*", workSpace)
for dataset in datasetList:
    print dataset
    fcList = arcpy.ListFeatureClasses("*","",dataset)
    for fc in fcList:
        print fc
  • To get the last three characters of a string use myVariable[-3:].

  • Your indentations are also not correct within your first for loop.

  • The way I was using for last 3 characters worked. Is there anyway I can do a loop that will get the stop and then the route snap them and then repeat? – Conor Aug 8 '13 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.