Exemplo n.º 1
0
    def _build_location_index(self):   
        sys.stdout.write("Generating QuadTree location index... ")
        sys.stdout.flush()
        location_index = QuadTree(MAX_DEPTH, self.bounding_box)
        # iterate through all trips

        for trip in self.all_trips:
            #Iterate through all locations
            current_node = None
            #Loop for adding trajectory information
            for previous, location, next in self.previous_and_next(trip.locations):
                current_node = location_index.insert(location)

                # First location 
                if previous is not None and next is not None:
                    #get the node where the next location would fall
                    self.update_trajectory(previous, location, next, current_node)


        location_index.traverse() #Populate leaves[]

        _node_id = 0
        #Hash with all leaves
        for leave in location_index.leaves:
            location = leave._center_of_mass()
            leave.id = (location.latitude, location.longitude)
            self.all_nodes[(location.latitude, location.longitude)] = leave

        return location_index
Exemplo n.º 2
0
    def _build_dynamic_location_index(self):
        """
        Initialize a quadtree index and insert
        all the stored locations 
        """   
        sys.stdout.write("Generating QuadTree location index...\n ")
        sys.stdout.flush()
        location_index = QuadTree(self.bounding_box)
        # iterate through all trips

        for trip in self.all_trips:
            #Iterate through all locations
            current_cell = None
            #Loop for adding trajectory information
            for location in trip.locations:
                current_cell = location_index.insert(location)

        location_index.traverse() #Populate leaves[]

        _node_id = 0
        #Store a reference to all the quadtree LEAF cells
        for cell in location_index.leaves:
            location = cell._center_of_mass()
            cell.id = (location.latitude, location.longitude)
            self.all_nodes[(location.latitude, location.longitude)] = cell
        
        sys.stdout.write("Done...\n ")
        sys.stdout.flush()
        
        return location_index
Exemplo n.º 3
0
def main():
        #Load all files and initilize Simple Tracks
    os.chdir("/home/moyano/Projects/CreateTracks/trips/")
    all_points = []
    for trip in os.listdir("."):
            trip_data = load_file(trip)
            all_points += trip_data
            #tracks.append(Track(trip_data))
            
    boundries = max_bounding_rect(all_points)
   # depth = depth(boundries, 0.00035)
    #print "Nesting Level: %i" % depth
    qtree = QuadTree(10, boundries)
    #Make the QTree
    for coord in all_points:
        qtree.add_point(coord)
    qtree.traverse()
    nodes = qtree.leaves

    #Load Trips
    trips = []
    for trip in os.listdir("."):
        if not trip.startswith('.'):

            gps_data = load_file(trip)
            trips.append(Trip(gps_data,trip))

    routes(trips, qtree)

    #Weighted Points
    os.chdir("/home/moyano/Projects/CreateTracks/edges")
    test_file = open("edges.txt", "w")
    test_file.write("latitude, longitude, ocurrences, color")
    # print children
    for node in nodes:
        p = node._center_of_mass()
        count = len(node.items)
        if count > 2:
            test_file.write("\n")  
            test_file.write(str(p.latitude) + "," + str(p.longitude) + "," + str(count) + "," + get_color(count))

    #All points
    os.chdir("/home/moyano/Projects/CreateTracks/edges")
    test_file = open("edges2.csv", "w")
    test_file.write("latitude, longitude")
    test_file.write("#")  
    # print children
    xpoints = []
    for node in nodes:
        p = node._center_of_mass()
        count = len(node.items)
        if count > 100:

            for _ in xrange(count):
                xpoints.append((p.latitude, p.longitude))
                test_file.write(str(p.latitude) + ", " + str(p.longitude))
                test_file.write("#")