Sie sind auf Seite 1von 3

import arcpy

##AnomaliesUTF8_txt = arcpy.GetParameterAsText(0)
SpeedAnomalies = arcpy.GetParameterAsText(0)
##X_Field = arcpy.GetParameterAsText(2)
##Y_Field = arcpy.GetParameterAsText(3)
RoadNetwork = arcpy.GetParameterAsText(1)
STSToutput = arcpy.GetParameterAsText(2)
RoadNetworkWithNoSpeeds = arcpy.GetParameterAsText(3)
RoadNamesandSpeeds = arcpy.GetParameterAsText(4)
# 1. Go into the Roads with No Speeds table. Look inside the Street name Colum
n and get the first record.
# 2. Set the street name variable and look inside the Speed Anomalies table ins
ide the StreetName Column
# 3. Loop through Street Name Column inside the speed anomalies table and "Matc
H" using the first value
#
value of the roads with no speeds table.
#Convert .csv file from CFL to a shapefile.
##Event_Layer = AnomaliesUTF8_txt
##arcpy.MakeXYEventLayer_management(AnomaliesUTF8_txt, X_Field, Y_Field, Event_L
ayer, "", "")
##arcpy.CopyFeatures_management(Event_Layer, SpeedAnomalies, "", "0", "0", "0")
# Process: Erase
#Erase the road features that have a Speed Limit Attribute with the Road Network
Layer
#This will help us create a unique collection of road names that do not have spe
ed limit attribution.
arcpy.Erase_analysis(RoadNetwork, STSToutput, RoadNetworkWithNoSpeeds, "")
# 1. Create a list of unique names from the Road Network with no Speeds table.
#declare Collection Variable
speednames = []
searchcursor = arcpy.SearchCursor(RoadNetworkWithNoSpeeds)
#This is the first line in the table.
record = searchcursor.next()
#Loop through all the records
while record:
#Guard and strip the ",1" out of the name. Otherwise this will not create m
atches.
value = record.getValue("RIGHTNAME")
stripname = value.rstrip(',1')
if not stripname in speednames:
speednames.append(stripname)
#Goes to the next record.
record = searchcursor.next()

#Removes the cursor from memory.


del searchcursor, record
# 2. Add Match field to speed Speed Anomalies table
# Process: Add Field
#This field will be created to perform a process. The steps are outlined
arcpy.AddField_management(SpeedAnomalies, "Match", "TEXT", "", "", "10", "", "NO
N_NULLABLE", "NON_REQUIRED", "")
# 3. Interate over all the records in Speeds anomalies table and set match fiel
d to "Y"
#
a. If the name in the Street name column in the speed anomalies table mat
hches the speed collection table
#
then set the value to "Y" otherwise the value of the match field will
be "N"
updatecursor = arcpy.UpdateCursor(SpeedAnomalies)
# Points to the first record in the table
record = updatecursor.next()
while record:
value = "N"
if record.StreetName in speednames:
value = "Y"
# updates the record
record.Match = value
#writes record back to hard drive.
updatecursor.updateRow(record)
# moves to the next record on the hard drive in the file.
record = updatecursor.next()
del updatecursor, record
speednames = []
searchcursor = arcpy.SearchCursor(RoadNamesandSpeeds)
#This is the first line in the table.
record = searchcursor.next()
while record:
#Guard and strip the ",1" out of the name. Otherwise this will not create m
atches.
name = record.getValue("RIGHTNAME")
name = name.rstrip(',1')
if not name in speednames:
speednames.append(name)
#Goes to the next record.
record = searchcursor.next()
#Removes the cursor from memory.
del searchcursor, record

updatecursor = arcpy.UpdateCursor(SpeedAnomalies)
# Points to the first record in the table
record = updatecursor.next()
while record:
#Find all of the "Y" Values
if record.Match == "Y":
#if record is a "Y" then check to see if it is in the Roadnames and spee
ds.
if record.StreetName in speednames:
#Sets record to "N" if it matches. This is placed in memory
record.Match = "N"
# writes the record to disk. So if a match is found then it changes
the value from "Y" to "N"
updatecursor.updateRow(record)
# moves to the next record on the hard drive in the file.
record = updatecursor.next()
del updatecursor, record

Das könnte Ihnen auch gefallen