Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import arcpy
- import os
- from arcpy import env
- # Set env
- arcpy.env.overwriteOutput = True
- # Set local variables
- inFeatures = "NewLine.shp"
- field = "OBJECTID_1"
- points = "Default.gdb\\RoutePoints"
- nodes = "MUCEP.gdb\\Highway\\Highway_Node"
- # Get spatial reference
- sr = arcpy.Describe(inFeatures).spatialReference
- print "Running RoutePoints script:"
- # Execute FeatureVerticesToPoints
- arcpy.FeatureVerticesToPoints_management(inFeatures, points, "ALL")
- # Get line information
- cursor = arcpy.SearchCursor(inFeatures)
- for row in cursor:
- linename=row.getValue("LineName")
- mode=row.getValue("Mode")
- oneway=row.getValue("Oneway")
- headway=row.getValue("Headway")
- xyspeed=row.getValue("XYSPEED")
- # Add field
- arcpy.AddField_management(points, "NODE", "LONG")
- # Make FeatureLayers
- arcpy.MakeFeatureLayer_management(points, "points_lyr")
- arcpy.MakeFeatureLayer_management(nodes, "nodes_lyr")
- rows = arcpy.UpdateCursor(points)
- for row in rows:
- # Get current row_id
- row_id = row.getValue(field)
- # Select the current point
- arcpy.SelectLayerByAttribute_management("points_lyr", "NEW_SELECTION",
- '"{0}" = {1}'.format(field, row_id))
- # Run SelectByLocation on the currently selected point
- arcpy.SelectLayerByLocation_management("nodes_lyr", "INTERSECT", "points_lyr")
- intersectRows = arcpy.SearchCursor("nodes_lyr")
- for intersectRow in intersectRows:
- intersectValue = intersectRow.getValue("N")
- del intersectRow, intersectRows
- row.setValue("NODE", intersectValue)
- rows.updateRow(row)
- del row, rows
- # Create Cube Transit data line
- # e.g. Line Name="J193B",Mode=1,Oneway=F,Headway=1,XYSPEED=18,N=3086,3084,3082,3080,3078,3074,3070,3076,3154,3150
- cursor = arcpy.SearchCursor(points)
- f = open("routepoints.txt", "w")
- f.write("Line Name=" + '"' + linename + '"' + "," + "Mode=" + mode + "," + "Oneway=" + oneway + "," + "Headway=" + headway + "," + "XYSPEED=" + xyspeed + ",")
- f.write("N=")
- row=cursor.next()
- count=1
- while row:
- if count<>1: f.write(",")
- f.write(str(row.getValue("NODE")))
- count=count+1
- row=cursor.next()
- f.close()
- print "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement