Exemplo n.º 1
0
 def test_creating_relation_from_donut_polygon(self):
     outer_ring_coordinates = [(0.3, 0.3), (0, 10), (10, 10), (10, 0),
                               (0.3, 0.3)]
     inner_ring_coordinates = [[(3.3, 3.3), (4, 4), (4, 3), (3.3, 3.3)]]
     polygon = util.InputPolygon(tags={},
                                 outer_ring=outer_ring_coordinates,
                                 inner_rings=inner_ring_coordinates)
     nodes, ways, relations = util.convert_to_osm_style_objects([polygon])
     assert len(nodes) == 7  # two nodes are reused
     assert len(ways) == 2
     assert len(relations) == 1
     relation = relations[0]
     assert len(relation.members) == 2
     nodes_dict = {n.id: (n.latitude, n.longitude) for n in nodes}
     outer_ring = [
         member for member in relation.members if member.role == 'outer'
     ][0]
     inner_ring = [
         member for member in relation.members if member.role == 'inner'
     ][0]
     outer_nodes = [way for way in ways
                    if way.id == outer_ring.id][0].node_ids
     reconstructed_outer_ring = [
         nodes_dict[node_id] for node_id in outer_nodes
     ]
     assert len(reconstructed_outer_ring) == 5
     assert outer_ring_coordinates == reconstructed_outer_ring
     inner_nodes = [way for way in ways
                    if way.id == inner_ring.id][0].node_ids
     reconstructed_inner_ring = [[
         nodes_dict[node_id] for node_id in inner_nodes
     ]]
     assert len(reconstructed_inner_ring) == 1
     assert len(reconstructed_inner_ring[0]) == 4
     assert inner_ring_coordinates == reconstructed_inner_ring
Exemplo n.º 2
0
 def test_relation_without_tags(self):
     outer_ring_coordinates = [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]
     inner_ring_coordinates = [[(3, 3), (4, 4), (4, 3), (3, 3)]]
     polygon = util.InputPolygon(tags={},
                                 outer_ring=outer_ring_coordinates,
                                 inner_rings=inner_ring_coordinates)
     nodes, ways, relations = util.convert_to_osm_style_objects([polygon])
     # 'type': 'multipolygon' is always added
     assert relations[0].tags == {'type': 'multipolygon'}
Exemplo n.º 3
0
    def test_creating_many_objects(self):
        # create point
        point = util.InputPoint(tags={'point': 'yes'}, latitude=0, longitude=0)
        # create line
        line_coordinates = [(0, 0), (1, 1), (2, 2)]
        line = util.InputLine(tags={'line': 'yes'},
                              list_of_coordinate_pairs=line_coordinates)
        # create polygon
        outer_ring_coordinates = [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]
        inner_ring_coordinates = [[(3, 3), (4, 4), (4, 3), (3, 3)]]
        polygon = util.InputPolygon(tags={},
                                    outer_ring=outer_ring_coordinates,
                                    inner_rings=inner_ring_coordinates)

        nodes, ways, relations = util.convert_to_osm_style_objects(
            [point, line, polygon])
        assert len(nodes) == 9
        assert len(ways) == 3
        assert len(relations) == 1

        assert len([n for n in nodes if n.tags.get('point')]) == 1

        way = [w for w in ways if w.tags.get('line')][0]
        assert len(way.node_ids) == 3
        nodes_dict = {n.id: (n.latitude, n.longitude) for n in nodes}
        reconstructed_line_coordinates = [
            nodes_dict[node_id] for node_id in way.node_ids
        ]
        assert len(reconstructed_line_coordinates) == 3
        assert line_coordinates == reconstructed_line_coordinates

        relation = relations[0]
        assert len(relation.members) == 2
        nodes_dict = {n.id: (n.latitude, n.longitude) for n in nodes}
        outer_ring = [
            member for member in relation.members if member.role == 'outer'
        ][0]
        inner_ring = [
            member for member in relation.members if member.role == 'inner'
        ][0]
        outer_nodes = [way for way in ways
                       if way.id == outer_ring.id][0].node_ids
        reconstructed_outer_ring = [
            nodes_dict[node_id] for node_id in outer_nodes
        ]
        assert len(reconstructed_outer_ring) == 5
        assert outer_ring_coordinates == reconstructed_outer_ring
        inner_nodes = [way for way in ways
                       if way.id == inner_ring.id][0].node_ids
        reconstructed_inner_ring = [[
            nodes_dict[node_id] for node_id in inner_nodes
        ]]
        assert len(reconstructed_inner_ring) == 1
        assert len(reconstructed_inner_ring[0]) == 4
        assert inner_ring_coordinates == reconstructed_inner_ring
Exemplo n.º 4
0
 def test_creating_way_from_polygon(self):
     polygon_coordinates = [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]
     polygon = util.InputPolygon(tags={},
                                 outer_ring=polygon_coordinates,
                                 inner_rings=[])
     nodes, ways, relations = util.convert_to_osm_style_objects([polygon])
     assert len(nodes) == 4  # one node is reused
     assert len(ways) == 1
     assert len(relations) == 0
     way = ways[0]
     assert len(way.node_ids) == 5
     nodes_dict = {n.id: (n.latitude, n.longitude) for n in nodes}
     reconstructed_polygon_coordinates = [
         nodes_dict[node_id] for node_id in way.node_ids
     ]
     assert len(reconstructed_polygon_coordinates) == 5
     assert polygon_coordinates == reconstructed_polygon_coordinates