Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys
- import arcpy
- from arcpy import env
- # Set env
- arcpy.env.overwriteOutput = True
- # Set local variables
- inDBF = "00PTR00A.dbf"
- nodes = "MUCEP.gdb\\Highway\\Highway_Node"
- links = "MUCEP.gdb\\Highway\\Highway_Link"
- outDir = "Default.gdb"
- fcName = "PTLoads"
- fcFields = (
- ("A", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
- ("B", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
- ("NAME", "TEXT", None, None, 50, "", "NULLABLE", "NON_REQUIRED"),
- ("LONGNAME", "TEXT", None, None, 150, "", "NULLABLE", "NON_REQUIRED"),
- ("DIST", "DOUBLE", 8, 3, None, "", "NULLABLE", "NON_REQUIRED"),
- ("TIME", "DOUBLE", 8, 3, None, "", "NULLABLE", "NON_REQUIRED"),
- ("LINKSEQ", "SHORT", 4, None, None, "", "NULLABLE", "NON_REQUIRED"),
- ("HEADWAY_1", "FLOAT", 8, 3, None, "", "NULLABLE", "NON_REQUIRED"),
- ("VOL", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
- ("ONA", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
- ("OFFA", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
- ("ONB", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED"),
- ("OFFB", "LONG", 8, None, None, "", "NULLABLE", "NON_REQUIRED")
- )
- fcOut = "Default.gdb\\PTLoads_Dissolve"
- # Get spatial reference
- sr = arcpy.Describe(nodes).spatialReference
- # Make FeatureLayers
- arcpy.MakeFeatureLayer_management(nodes, "nodes_lyr")
- print "Running LineLoads script..."
- rows = arcpy.SearchCursor(inDBF)
- # skip first line
- #rows.next()
- point = arcpy.Point()
- array = arcpy.Array()
- # Create output feature class
- fc = arcpy.CreateFeatureclass_management(outDir, fcName, "POLYLINE", spatial_reference=sr)
- for fcField in fcFields:
- arcpy.AddField_management(fc, *fcField)
- cursor = arcpy.InsertCursor(fc)
- feat = cursor.newRow()
- nrecs = 0
- for row in rows:
- nrecs = nrecs + 1
- # Get line data
- Linename = row.getValue("NAME")
- Longname = row.getValue("LONGNAME")
- Dist = row.getValue("DIST")
- Time = row.getValue("TIME")
- Linkseq = row.getValue("LINKSEQ")
- Headway = row.getValue("HEADWAY_1")
- Vol = row.getValue("VOL")
- OnA = row.getValue("ONA")
- OffA = row.getValue("OFFA")
- OnB = row.getValue("ONB")
- OffB = row.getValue("OFFB")
- # get Anode
- Anode = row.getValue("A")
- arcpy.SelectLayerByAttribute_management("nodes_lyr","NEW_SELECTION",
- '{0} = {1}'.format("N", Anode))
- selectedRows = arcpy.SearchCursor("nodes_lyr")
- for selectedRow in selectedRows:
- AnodeX = selectedRow.getValue("X")
- AnodeY = selectedRow.getValue("Y")
- del selectedRow, selectedRows
- # get Bnode
- Bnode = row.getValue("B")
- arcpy.SelectLayerByAttribute_management("nodes_lyr", "NEW_SELECTION",
- '"{0}" = {1}'.format("N", Bnode))
- selectedRows = arcpy.SearchCursor("nodes_lyr")
- for selectedRow in selectedRows:
- BnodeX = selectedRow.getValue("X")
- BnodeY = selectedRow.getValue("Y")
- del selectedRow, selectedRows
- # create points
- point.X = AnodeX
- point.Y = AnodeY
- array.add(point)
- point.X = BnodeX
- point.Y = BnodeY
- array.add(point)
- # Create a polyline object
- polyline = arcpy.Polyline(array)
- array.removeAll()
- if (Linename != "*100" and Linename != "*200"):
- # Set the attributes
- feat.A = Anode
- feat.B = Bnode
- feat.NAME = Linename
- feat.LONGNAME = Longname
- feat.DIST = Dist
- feat.TIME = Time
- feat.LINKSEQ = Linkseq
- feat.HEADWAY_1 = Headway
- feat.VOL = Vol
- feat.ONA = OnA
- feat.OFFA = OffA
- feat.ONB = OnB
- feat.OFFB = OffB
- # Insert the feature
- feat.shape = polyline
- cursor.insertRow(feat)
- #print Linename
- del feat
- del rows, cursor
- # Merge features
- arcpy.env.workspace = "Default.gdb"
- dissolveFields = "NAME"
- dissolveStats = "VOL SUM"
- arcpy.Dissolve_management(fc_name, fcOut, dissolveFields, dissolveStats)
- print nrecs, "records processed."
- print "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement