import sys sys.path.append('C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy') import arcpy arcpy.env.workspace = "C:\\Users\\Admiral Ackbar\\Desktop\\442PythonTempWorkspace\\442PythonTempWorkspace.gdb" PSRGList = arcpy.ListFeatureClasses("","","PSUEDO_STOPS_ROUTE_GROUPS") #Retrieve a list of all 2D Psudeo Stop feature classes internally grouped by route they service in the feature dataset "PSUEDO_STOPS_ROUTE_GROUPS" for PSRG in PSRGList: #for every pseudo stop route group (PSRG) in the PSGR list PSRGcounter = 0 #PSRG counter that indicates the index of the PSRGList that is currently going through iteration newPSRGname = PSRGlist[PSRGcounter] + "_3D" #Get the name of the PSRG feature from the list and add '_3D' for the new name PSRG3D = arcpy.FeatureTo3DByAttribute(PSRG, newPSRGname, "ELEVATION") # Make the feature 3D by using the field 'ELEVATION' for height print "New 3d Feature" + newPSRGname +"created." SC_list=[] #Empty list for stopcodes that will be retrieved srows = arcpy.SearchCursor(newPSRGname,"","","STOP_CODE","STOP_CODE_A") #Create a search cursor to retrieve all stop code values in the 3D PSRG and put the values in ascending order for srow in srows: #For each row in the cursor Stop_code = srow.STOP_CODE #Assign a variable for the value of the STOP_CODE field SC_list.append(Stop_code) #Append that value to the SC_List del srow, srows #Delete the search cursor print "New Stop Code List created from" + str(newPSRGname) +"." SC_List =["x","y","z"] SCcounter=1 #counter query="" #Empty string for query SC_length = len(SC_list) #Get the length of the Stop Code list while SCcounter <= SC_length: #while there are items in the list SC_List for SC in SC_List: if SCcounter < SC_length: #if the SC counter is less than the length of the list SC_List query += "\"STOP_CODE\" == \'%s\' OR " %(SC) #Create the initial portion of the query SCcounter +=1 else: query += "\"STOP_CODE\" == \'%s\'" %(SC) #add other values to the query as long as there are values in the list SCcounter +=1 print "The query to be used in Select By Attribute is " + query + "." arcpy.MakeFeatureLayer_management("REALBUSSTOPS_3D","REALBUSSTOPS_3D_lyr") #Create a Feature Layer for Select by Attribute routenumlist = [] #create blank list routenumlist = PSRG.split(_) #Split the PSRG name at every occurrence of '_' routenum = routenumlist[1] #Get the route number from the list of words in the PSRG feature which resides at the index 1 for every standardized PSRG name selectedRBS_nam3 = "REALBUSSTOPS_3D_" + routenum #Name of the selected Real Bus Stops (RBS) feature to be arcpy.SelectByAttribute_management("REALBUSSTOPS_3D_lyr",NEW_SELECTION,query) #Select the corresponding REALBUSSTOP_3D records arcpy.CopyFeatures_management("REALBUSSTOPS_3D_lyr", sleectedRBS_nam3) #Create a new feature of the selected RealBusstops_3D print"New 3d Feature"+ selectedRBS_nam3 + "was created." arcpy.Delete_management("REALBUSSTOPS_3D_lyr") #Delete the layer mergeoutput = "PSUEDO_REAL_3D_STOPS_" + routenum #Assign variable for the name of the output merge file arcpy.Merge_management([newPSRGname, selectedRBS_nam3], mergeoutput) #Merge the RBS and the PBRG points into one file print"Selected real bus stops and PSRG" + routenum + "were merged into the file " + mergeoutput +"." outputconnector="Connector_" + routenum #Assign variable for the output points to line file arcpy.PointsToLine_management(mergeoutput, outputconnector, "STOP_CODE") #Create the 3D connectors for that route group print outputconnector + "was created." PSRGcounter=+1 #Increase the PSRG counter by one for naming conventions to be correct on the next iteration connectorlist = arcpy.ListFeatureClasses("",Polyline,"") #Creates a list of the connector features classes in the workspace (connectors are the only polyline features in the workspace). connectorstring = "" connectorcounter = 0 while connect in connectorlist: #while there are items in the list connectorlist if connectorcounter <24: connectorstring+= connect+";" #append the string from connector list to the string connector string connectorcounter+=1 #Add one to the counter else: connectorstring=+ connect #Append the string from connector list with no trailing semicolon connectorcounter+=1 #Add one to the counter arcpy.Merge_management(connectorstring, "MASTER_CONNECTORS_3D") #Merge all of the connectors into one 'Master' 3D feature
Solved! Go to Solution.