I am kind of new to python, and am attempting to write a script that will give me a unique identifier for roads based on the cardinal direction. Ultimatley, I would like to have a system set up such as the interstate system in the united states, where North -South roads are odd numbered, and east west roads are even numbered. I would also like to reflect these numbers based on their position within the area I am working in. For example, the southern most w to e road would take the number 2, while the western most n-s road would take 1. So far, the only code I could find is code to conver the endpoints of the roads into a numerical direction:
180 + math.atan2((!Shape.lastpoint.Y! - !Shape.firstpoint.Y!),(!Shape.lastpoint.X! - !Shape.firstpoint.X!)) * (180 / math.pi)
I am assuming I will have to write some if/else statements, but I am not entirely sure how to set them up.
I also found this block of code, but it didnt seem to work for me for numbering the n-s roads:
rec=0
def autoIncrement():
global rec
pStart = 1 #adjust startvalue, if req'd
pInterval = 2 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else: rec = rec + pInterval
return rec
Even if I were to get this to work, I still don't know how to get it to number roads based on how far north/south, east/west they are.