예제 #1
0
def getGates():
    global trackStations,trackCoordinates
    counter = 0
    coordinationsStr = ""
    coordinates  = []
    stationLoc = []
    DOMTree = xml.dom.minidom.parse('/Users/Hossein/Downloads/bart.kml')
    collection = DOMTree.documentElement
    folders = collection.getElementsByTagName("Folder")
    print "Gates in Track: "
    for folder in folders:
       folderName = folder.getElementsByTagName('name')[0].childNodes[0].data
       if folderName == "BART Stations":
           placeMarks = folder.getElementsByTagName("Placemark")
           for placeMark in placeMarks:
               coordinationsStr = placeMark.getElementsByTagName("coordinates")[0].childNodes[0].data  
               coordinationsStr = coordinationsStr.replace(',0','')
               coordinates = coordinationsStr.split(',')
               stationName = placeMark.getElementsByTagName("name")[0].childNodes[0].data
               stationLat = float(coordinates[1])
               stationLon = float(coordinates[0])        
               stationLoc = [stationLat,stationLon]
               loc = utility.getTraveledDistance(trackCoordinates,stationLoc)
               if utility.inTrack(trackCoordinates,stationLoc,300):
                   counter+=1
                   gate = Gate.Gate(stationName, stationLat,stationLon,True,loc,counter)    
                   gateList.append(gate)                   
                   print "\t"+gate.__str__()
예제 #2
0
#==============================================================================================================
# Main Program:
#==============================================================================================================     

mymap = pygmaps.maps(37.7016, -121.9003, 16)
getSegments()
getGates()
totalDistance = 0
for gate in gateList:
    if gate.getGateStatStr() == 'open':
        mymap.addpoint(gate.getGateLat(),gate.getGateLon(), gate.getName(), utility.getColorCode("green"))
    else:
        mymap.addpoint(gate.getGateLat(),gate.getGateLon(),gate.getGatename(), utility.getColorCode("red"))        
print "Number of segments: " + str(len(segmentList))
for seg in segmentList:
    dBegin = utility.getTraveledDistance(trackCoordinates,seg.getStartPoint())
    dEnd = utility.getTraveledDistance(trackCoordinates,seg.getEndPoint())
    print "\tSegment: " + seg.getSegName() + " starts at " + str(dBegin/1000) + "km and ends in " + str(dEnd/1000) + "km ---> Segment length:" + str(seg.getSegmentLength()) 
initialPos1 = utility.getPointAtDistanceInPath(trackCoordinates,30)
train1 = Train.train(initialPos1,0,2,1,segmentList,trackCoordinates,gateList) 
trainList.append(train1)
initialPos2 = utility.getPointAtDistanceInPath(trackCoordinates,50)
train2 = Train.train(initialPos2,0,2,2,segmentList,trackCoordinates,gateList) 
trainList.append(train2)

stationComputer = StationComputer.StationComputer(trainList,segmentList,trackCoordinates,gateList)
mymap.addTrain(initialPos1[0], initialPos1[1], 1)
mymap.addTrain(initialPos2[0], initialPos2[1], 2)
mymap.draw('./mymap.html')
#train.nextSegmentsInRange(10)