source: tmcsimulator/trunk/src/cptms/prep_cctv.py @ 304

Revision 304, 2.2 KB checked in by jdalbey, 7 years ago (diff)

cptms_map.html Added cctv icons

Line 
1import collections,math,sys
2# Scan the cctv file to find the nearest vds
3# jdalbey Mar 2019
4postmileFile = "d12_vds_uniq_sorted.csv"
5cctvFile = "cctv_locations_D12.csv"
6orientationLookup = {'N':0,'S':1,'E':0,'W':1}
7
8def loadHighways():
9
10    f = open(postmileFile,'r')
11    lines = [line.split(',') for line in f.readlines()]
12   
13    # Create a set containing just the route numbers
14    routeNums = set()
15    for item in lines:
16        routeNums.add(int(item[0]))
17    # put the route numbers in order
18    sortedRoutes = sorted (routeNums)   
19    # Create the empty postmile collections
20    for route in sortedRoutes:
21        #print route,
22        highways[str(route)]=[collections.OrderedDict(),collections.OrderedDict()]
23    #print
24    # Process all the data, placing it in proper route and collection
25    for item in lines:
26        route = item[0]
27        orientation = orientationLookup[item[1]]
28        postmileItem = item[2]
29        highways[route][orientation][postmileItem]=item
30
31
32def dumpHighways():
33    # Dump the highways data we've organized
34    for item in highways:
35        for cnt in [0,1]:
36            list1 = highways[item][cnt]
37            print "highway",item,list1
38            # show fields for one entry
39            for pm_entry in list1:
40                print pm_entry,list1[pm_entry]
41
42def findNearest():
43
44    f = open(cctvFile,'r')
45    lines = [line.split(',') for line in f.readlines()]
46
47    # Find he nearest VDS to each cctv
48    for item in lines:
49        route = item[0]
50        orientation = orientationLookup[item[1]]
51        postmileItem = item[2]
52        segment = highways[route][orientation] 
53
54        # Now we know which highway segment the cctv is on, look at all those VDS to find nearest
55        print route,item[1],postmileItem+",",
56        min = 9999
57        nearVDS = 0
58        for vds in segment:
59            diff = abs(float(vds) - float(postmileItem))
60            #print vds + "("+str(diff)+")",
61            if (diff < min):
62                min = diff
63                nearVDS = vds
64        print route,item[1],nearVDS
65
66# ------------------------------------------------------------------------------------------
67
68highways = collections.OrderedDict()   
69loadHighways()
70print "CCTV\tnearestVDS"
71findNearest()
72
Note: See TracBrowser for help on using the repository browser.