Ejemplo n.º 1
0
    def test_all_nodes_inside(self):
        nodes = NodeSet()
        nodes.add(1, (-10, -10))
        nodes.add(2, (-5, -5))
        selected_nodes = select_nodes_in_rectangle(nodes, -10, 10, -10, 10)

        self.assertTrue(nodes.nodes.keys() == selected_nodes.nodes.keys())
Ejemplo n.º 2
0
    def test_random(self):
        # Create 100 random nodes
        nodes = NodeSet()
        for i in range(100):
            nodes.add(i, (random.randint(-180, 180), 
                           random.randint(-90, 90)))

        # Randomly choose the min and max latitude and longitude
        min_lat = random.randint(-90, 90)
        min_lng = random.randint(-180, 180)
        max_lat = min_lat + random.randint(0, 90-min_lat)
        max_lng = min_lng + random.randint(0, 180-min_lng)
        
        # Extract all nodes within the randomly generated rectangle
        selected_nodes = select_nodes_in_rectangle(nodes, min_lat, max_lat, 
                                   min_lng, max_lng)

        # Make sure that all nodes that should be inside are inside
        for n in nodes.nodes.values():
            if n.id in selected_nodes.nodes.keys():
                self.assertTrue(node_inside(n, min_lat, max_lat, 
                                            min_lng, max_lng))
            else:
                self.assertFalse(node_inside(n, min_lat, max_lat, 
                                             min_lng, max_lng))
Ejemplo n.º 3
0
    def test_some_nodes_inside(self):
        nodes = NodeSet()
        nodes.add(1, 8, 12)
        nodes.add(2, 10, 15)

        selected_nodes = select_nodes_in_rectangle(nodes, 4, 9, 8, 14)
        self.assertTrue(selected_nodes.nodes)
Ejemplo n.º 4
0
    def test_empty_clip_nodes(self):
        nodes = NodeSet()
        nodes.add(1, (-10, -10))
        nodes.add(2, (-5, -5))

        selected_nodes = select_nodes_in_rectangle(nodes, 0, 10, 0, 10)
        self.assertFalse(selected_nodes.nodes)
Ejemplo n.º 5
0
    def test_all_nodes_inside(self):
        nodes = NodeSet()
        nodes.add(1, -9, -9.9999)
        nodes.add(2, -5, -5)

        selected_nodes = select_nodes_in_rectangle(nodes, -10, 10, -10, 10)
        self.assertTrue(nodes.nodes.keys() == selected_nodes.nodes.keys())
Ejemplo n.º 6
0
    def test_empty_clip_nodes(self):
        nodes = NodeSet()
        nodes.add(1, -10, -10)
        nodes.add(2, -5, -5)

        selected_nodes = select_nodes_in_rectangle(nodes, 0, 10, 0, 10)
        self.assertFalse(selected_nodes.nodes)
Ejemplo n.º 7
0
    def test_some_nodes_inside(self):
        nodes = NodeSet()
        nodes.add(1, -10, -10)
        nodes.add(2, -5, -5)

        selected_nodes = select_nodes_in_rectangle(nodes, -10, 10, -10, 10)
        self.assertTrue(
            any(x in selected_nodes.get_nodes().keys()
                for x in nodes.get_nodes().keys()))
Ejemplo n.º 8
0
def extract_osm_nodes(f_name):
    # Parse the supplied OSM file
    print("Loading data...")
    parser = get_default_parser(f_name)
    node_set = NodeSet()

    for node in parser.iter_nodes():
        node_set.add(node['id'], node['lat'], node['lon'])

    return node_set
Ejemplo n.º 9
0
def select_nodes_in_rectangle(nodes, min_lat, max_lat, min_lng, max_lng):
    # actual min and max latitude and longitude of coordinates
    #if needed change <= to <
    nodes_in_rectangle = NodeSet()
    for k, node in nodes.get_nodes().items():
        if (min_lat <= node.lat and node.lat <= max_lat and min_lng <= node.lng
                and node.lng <= max_lng):
            nodes_in_rectangle.add(k, node.lat, node.lng)

    return nodes_in_rectangle
Ejemplo n.º 10
0
    def test_random(self):
        #create 100 random nodes
        nodes = NodeSet()
        for i in range(100):
            nodes.add(i, random.randint(-180, 180), random.randint(-90, 90))

        #random min and max lat and long
        min_lat = random.randint(-90, 90)
        min_lng = random.randint(-180, 180)
        max_lat = min_lat + random.randint(0, 90 - min_lat)
        max_lng = min_lng + random.randint(0, 180 - min_lng)

        selected_nodes = select_nodes_in_rectangle(nodes, min_lat, max_lat,
                                                   min_lng, max_lng)

        #test that all nodes are inside
        for n in nodes.nodes.values():
            if n.id in selected_nodes.nodes.keys():
                self.assertTrue(
                    node_inside(n, min_lat, max_lat, min_lng, max_lng))
            else:
                self.assertFalse(
                    node_inside(n, min_lat, max_lat, min_lng, max_lng))
Ejemplo n.º 11
0
    def test_random(self):
        # Create 100 random nodes
        nodes = NodeSet()
        for i in range(100):
            nodes.add(i, random.randint(-180, 180), random.randint(-90, 90))

        # Randomly choose the min and max latitude and longitude
        min_lat = random.randint(-90, 90)
        min_lng = random.randint(-180, 180)
        max_lat = min_lat + random.randint(0, 90 - min_lat)
        max_lng = min_lng + random.randint(0, 180 - min_lng)

        # Extract all nodes within the randomly generated rectangle
        selected_nodes = select_nodes_in_rectangle(nodes, min_lat, max_lat,
                                                   min_lng, max_lng)

        # Make sure that all nodes that should be inside are inside
        for n in nodes.nodes.values():
            if n.id in selected_nodes.nodes.keys():
                self.assertTrue(
                    node_inside(n, min_lat, max_lat, min_lng, max_lng))
            else:
                self.assertFalse(
                    node_inside(n, min_lat, max_lat, min_lng, max_lng))
Ejemplo n.º 12
0
 def test_rand_cases(self):
     nodes = NodeSet()
     nodes.add(1, random.randint(-90, 90), random.randint(-180, 180))
     nodes.add(2, random.randint(-90, 90), random.randint(-180, 180))
     for k, n in nodes.get_nodes().items():
         self.assertTrue(-90 <= n.lat <= 90 and -180 <= n.lng <= 180)
Ejemplo n.º 13
0
 def test_edge_bounds(self):
     nodes = NodeSet()
     nodes.add(1, -90, -180)
     nodes.add(2, 90, 180)
     for k, n in nodes.get_nodes().items():
         self.assertTrue(-90 <= n.lat <= 90 and -180 <= n.lng <= 180)