Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. import os, sys
  2. import arcpy
  3. from arcpy import env
  4.  
  5. # Set env
  6. arcpy.env.overwriteOutput = True
  7.  
  8. # Set local variables
  9. inDBF = "00PTR00A.dbf"
  10. nodes = "MUCEP.gdb\\Highway\\Highway_Node"
  11. links = "MUCEP.gdb\\Highway\\Highway_Link"
  12. outDir = "Default.gdb"
  13. fcName = "PTLoads"
  14. fcFields = (
  15. ("A", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
  16. ("B", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
  17. ("NAME", "TEXT", None, None, 50, "", "NULLABLE", "NON_REQUIRED"),
  18. ("LONGNAME", "TEXT", None, None, 150, "", "NULLABLE", "NON_REQUIRED"),
  19. ("DIST", "DOUBLE", 8, 3, None, "", "NULLABLE", "NON_REQUIRED"),
  20. ("TIME", "DOUBLE", 8, 3, None, "", "NULLABLE", "NON_REQUIRED"),
  21. ("LINKSEQ", "SHORT", 4, None, None, "", "NULLABLE", "NON_REQUIRED"),
  22. ("HEADWAY_1", "FLOAT", 8, 3, None, "", "NULLABLE", "NON_REQUIRED"),
  23. ("VOL", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
  24. ("ONA", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
  25. ("OFFA", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
  26. ("ONB", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
  27. ("OFFB", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED")
  28. )
  29. fcOut = "Default.gdb\\PTLoads_Dissolve"
  30.  
  31. # Get spatial reference
  32. sr = arcpy.Describe(nodes).spatialReference
  33.  
  34. # Make FeatureLayers
  35. arcpy.MakeFeatureLayer_management(nodes, "nodes_lyr")
  36.  
  37. print "Running LineLoads script..."
  38.  
  39. rows = arcpy.SearchCursor(inDBF)
  40. # skip first line
  41. #rows.next()
  42.  
  43. point = arcpy.Point()
  44. array = arcpy.Array()
  45.  
  46. # Create output feature class
  47. fc = arcpy.CreateFeatureclass_management(outDir, fcName, "POLYLINE", spatial_reference=sr)
  48. for fcField in fcFields:
  49. arcpy.AddField_management(fc, *fcField)
  50.  
  51. cursor = arcpy.InsertCursor(fc)
  52. feat = cursor.newRow()
  53. nrecs = 0
  54.  
  55. for row in rows:
  56. nrecs = nrecs + 1
  57. # Get line data
  58. Linename = row.getValue("NAME")
  59. Longname = row.getValue("LONGNAME")
  60. Dist = row.getValue("DIST")
  61. Time = row.getValue("TIME")
  62. Linkseq = row.getValue("LINKSEQ")
  63. Headway = row.getValue("HEADWAY_1")
  64. Vol = row.getValue("VOL")
  65. OnA = row.getValue("ONA")
  66. OffA = row.getValue("OFFA")
  67. OnB = row.getValue("ONB")
  68. OffB = row.getValue("OFFB")
  69. # get Anode
  70. Anode = row.getValue("A")
  71. arcpy.SelectLayerByAttribute_management("nodes_lyr","NEW_SELECTION",
  72. '{0} = {1}'.format("N", Anode))
  73. selectedRows = arcpy.SearchCursor("nodes_lyr")
  74. for selectedRow in selectedRows:
  75. AnodeX = selectedRow.getValue("X")
  76. AnodeY = selectedRow.getValue("Y")
  77. del selectedRow, selectedRows
  78. # get Bnode
  79. Bnode = row.getValue("B")
  80. arcpy.SelectLayerByAttribute_management("nodes_lyr", "NEW_SELECTION",
  81. '"{0}" = {1}'.format("N", Bnode))
  82. selectedRows = arcpy.SearchCursor("nodes_lyr")
  83. for selectedRow in selectedRows:
  84. BnodeX = selectedRow.getValue("X")
  85. BnodeY = selectedRow.getValue("Y")
  86. del selectedRow, selectedRows
  87.  
  88. # create points
  89. point.X = AnodeX
  90. point.Y = AnodeY
  91. array.add(point)
  92. point.X = BnodeX
  93. point.Y = BnodeY
  94. array.add(point)
  95.  
  96. # Create a polyline object
  97. polyline = arcpy.Polyline(array)
  98. array.removeAll()
  99.  
  100. if (Linename != "*100" and Linename != "*200"):
  101. # Set the attributes
  102. feat.A = Anode
  103. feat.B = Bnode
  104. feat.NAME = Linename
  105. feat.LONGNAME = Longname
  106. feat.DIST = Dist
  107. feat.TIME = Time
  108. feat.LINKSEQ = Linkseq
  109. feat.HEADWAY_1 = Headway
  110. feat.VOL = Vol
  111. feat.ONA = OnA
  112. feat.OFFA = OffA
  113. feat.ONB = OnB
  114. feat.OFFB = OffB
  115. # Insert the feature
  116. feat.shape = polyline
  117. cursor.insertRow(feat)
  118. #print Linename
  119. del feat
  120. del rows, cursor
  121.  
  122. # Merge features
  123. arcpy.env.workspace = "Default.gdb"
  124. dissolveFields = "NAME"
  125. dissolveStats = "VOL SUM"
  126. arcpy.Dissolve_management(fc_name, fcOut, dissolveFields, dissolveStats)
  127.  
  128. print nrecs, "records processed."
  129. print "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement