Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import arcpy
  2. import os
  3. from arcpy import env
  4.  
  5. # Set env
  6. arcpy.env.overwriteOutput = True
  7.  
  8. # Set local variables
  9. inFeatures = "NewLine.shp"
  10. field = "OBJECTID_1"
  11. points = "Default.gdb\\RoutePoints"
  12. nodes = "MUCEP.gdb\\Highway\\Highway_Node"
  13.  
  14. # Get spatial reference
  15. sr = arcpy.Describe(inFeatures).spatialReference
  16.  
  17. print "Running RoutePoints script:"
  18.  
  19. # Execute FeatureVerticesToPoints
  20. arcpy.FeatureVerticesToPoints_management(inFeatures, points, "ALL")
  21.  
  22. # Get line information
  23. cursor = arcpy.SearchCursor(inFeatures)
  24. for row in cursor:
  25. linename=row.getValue("LineName")
  26. mode=row.getValue("Mode")
  27. oneway=row.getValue("Oneway")
  28. headway=row.getValue("Headway")
  29. xyspeed=row.getValue("XYSPEED")
  30.  
  31. # Add field
  32. arcpy.AddField_management(points, "NODE", "LONG")
  33.  
  34. # Make FeatureLayers
  35. arcpy.MakeFeatureLayer_management(points, "points_lyr")
  36. arcpy.MakeFeatureLayer_management(nodes, "nodes_lyr")
  37.  
  38. rows = arcpy.UpdateCursor(points)
  39. for row in rows:
  40. # Get current row_id
  41. row_id = row.getValue(field)
  42. # Select the current point
  43. arcpy.SelectLayerByAttribute_management("points_lyr", "NEW_SELECTION",
  44. '"{0}" = {1}'.format(field, row_id))
  45. # Run SelectByLocation on the currently selected point
  46. arcpy.SelectLayerByLocation_management("nodes_lyr", "INTERSECT", "points_lyr")
  47. intersectRows = arcpy.SearchCursor("nodes_lyr")
  48. for intersectRow in intersectRows:
  49. intersectValue = intersectRow.getValue("N")
  50. del intersectRow, intersectRows
  51. row.setValue("NODE", intersectValue)
  52. rows.updateRow(row)
  53. del row, rows
  54.  
  55. # Create Cube Transit data line
  56. # e.g. Line Name="J193B",Mode=1,Oneway=F,Headway=1,XYSPEED=18,N=3086,3084,3082,3080,3078,3074,3070,3076,3154,3150
  57. cursor = arcpy.SearchCursor(points)
  58. f = open("routepoints.txt", "w")
  59. f.write("Line Name=" + '"' + linename + '"' + "," + "Mode=" + mode + "," + "Oneway=" + oneway + "," + "Headway=" + headway + "," + "XYSPEED=" + xyspeed + ",")
  60. f.write("N=")
  61. row=cursor.next()
  62. count=1
  63. while row:
  64. if count<>1: f.write(",")
  65. f.write(str(row.getValue("NODE")))
  66. count=count+1
  67. row=cursor.next()
  68. f.close()
  69.  
  70. print "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement