def test_polygon_w_nested_holes(self):
        w1 = Way(1, {'landusage': 'forest'}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
        w2 = Way(2, {'landusage': 'scrub'}, [1, 2, 3, 4, 1])
        w2.coords = [(1, 1), (9, 1), (9, 9), (1, 9), (1, 1)]
        w3 = Way(3, {}, [5, 6, 7, 8, 5]) # with no tags
        w3.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]
        w4 = Way(4, {'landusage': 'scrub'}, [9, 10, 11, 12, 9])
        w4.coords = [(3, 3), (7, 3), (7, 7), (3, 7), (3, 3)]
        w5 = Way(5, {'landusage': 'forest'}, [9, 10, 11, 12, 9])
        w5.coords = [(4, 4), (6, 4), (6, 6), (4, 6), (4, 4)]
    
        r = Relation(1, {'landusage': 'forest'}, [
            (1, 'way', 'outer'), (2, 'way', 'inner'), (3, 'way', 'inner'),
            (4, 'way', 'inner'), (5, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2, w3, w4, w5])
        eq_(len(rings), 5)
        eq_(rings[0].geom.area, 100)
        eq_(rings[1].geom.area, 64)
        eq_(rings[2].geom.area, 36)
        eq_(rings[3].geom.area, 16)
        eq_(rings[4].geom.area, 4)
    
        builder.build_relation_geometry(rings)

        eq_(rings[0].inserted, True)
        eq_(rings[1].inserted, False)
        eq_(rings[2].inserted, True)
        eq_(rings[3].inserted, False)
        eq_(rings[4].inserted, True)
    
        eq_(r.geom.area, 100-64+36-16+4)
Exemple #2
0
    def test_touching_polygons_w_hole(self):
        w1 = Way(1, {'water': 'riverbank'}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
        w2 = Way(2, {'water': 'riverbank'}, [2, 5, 6, 3, 2])
        w2.coords = [(10, 0), (30, 0), (30, 10), (10, 10), (10, 0)]
        w3 = Way(3, {'landusage': 'forest'}, [7, 8, 9, 10, 7])
        w3.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]

        r = Relation(1, {'water': 'riverbank'}, [(1, 'way', 'outer'),
                                                 (2, 'way', 'outer'),
                                                 (3, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2, w3])
        eq_(len(rings), 3)
        eq_(rings[0].geom.area, 100)
        eq_(rings[1].geom.area, 200)
        eq_(rings[2].geom.area, 36)

        builder.build_relation_geometry(rings)

        eq_(rings[0].inserted, True)
        eq_(rings[1].inserted, True)
        eq_(rings[2].inserted, False)

        eq_(r.geom.area, 100 + 200 - 36)
Exemple #3
0
    def test_polygon_w_nested_holes(self):
        w1 = Way(1, {'landusage': 'forest'}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
        w2 = Way(2, {'landusage': 'scrub'}, [1, 2, 3, 4, 1])
        w2.coords = [(1, 1), (9, 1), (9, 9), (1, 9), (1, 1)]
        w3 = Way(3, {}, [5, 6, 7, 8, 5])  # with no tags
        w3.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]
        w4 = Way(4, {'landusage': 'scrub'}, [9, 10, 11, 12, 9])
        w4.coords = [(3, 3), (7, 3), (7, 7), (3, 7), (3, 3)]
        w5 = Way(5, {'landusage': 'forest'}, [9, 10, 11, 12, 9])
        w5.coords = [(4, 4), (6, 4), (6, 6), (4, 6), (4, 4)]

        r = Relation(1, {'landusage': 'forest'}, [(1, 'way', 'outer'),
                                                  (2, 'way', 'inner'),
                                                  (3, 'way', 'inner'),
                                                  (4, 'way', 'inner'),
                                                  (5, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2, w3, w4, w5])
        eq_(len(rings), 5)
        eq_(rings[0].geom.area, 100)
        eq_(rings[1].geom.area, 64)
        eq_(rings[2].geom.area, 36)
        eq_(rings[3].geom.area, 16)
        eq_(rings[4].geom.area, 4)

        builder.build_relation_geometry(rings)

        eq_(rings[0].inserted, True)
        eq_(rings[1].inserted, False)
        eq_(rings[2].inserted, True)
        eq_(rings[3].inserted, False)
        eq_(rings[4].inserted, True)

        eq_(r.geom.area, 100 - 64 + 36 - 16 + 4)
Exemple #4
0
    def test_polygon_w_touching_holes(self):
        w1 = Way(1, {'landusage': 'forest'}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
        w2 = Way(2, {'landusage': 'scrub'}, [1, 2, 3, 4, 1])
        w2.coords = [(1, 1), (5, 1), (5, 9), (1, 9), (1, 1)]
        w3 = Way(3, {'water': 'basin'}, [1, 2, 3, 4, 1])
        w3.coords = [(5, 1), (9, 1), (9, 9), (5, 9), (5, 1)]

        r = Relation(1, {'landusage': 'forest'}, [(1, 'way', 'outer'),
                                                  (2, 'way', 'inner'),
                                                  (3, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2, w3])
        eq_(len(rings), 3)
        eq_(rings[0].geom.area, 100)
        eq_(rings[1].geom.area, 32)
        eq_(rings[2].geom.area, 32)

        builder.build_relation_geometry(rings)

        eq_(rings[0].inserted, True)
        eq_(rings[1].inserted, False)
        eq_(rings[2].inserted, False)

        eq_(r.geom.area, 100 - 64)
Exemple #5
0
def test_merge_rings():
    w1 = Way(1, {}, [1, 2, 3])
    w1.coords = [(0, 0), (10, 0), (10, 10)]
    r1 = Ring(w1)
    w2 = Way(2, {}, [3, 4, 1])
    w2.coords = [(10, 10), (0, 10), (0, 0)]
    r2 = Ring(w2)

    rings = merge_rings([r1, r2])
    eq_(len(rings), 1)
    r = rings[0]
    eq_(r.is_closed(), True)
def test_merge_rings():
    w1 = Way(1, {}, [1, 2, 3])
    w1.coords = [(0, 0), (10, 0), (10, 10)]
    r1 = Ring(w1)
    w2 = Way(2, {}, [3, 4, 1])
    w2.coords = [(10, 10), (0, 10), (0, 0)]
    r2 = Ring(w2)
    
    rings = merge_rings([r1, r2])
    eq_(len(rings), 1)
    r = rings[0]
    eq_(r.is_closed(), True)
 def test_inserted_multiple_tags(self):
     w1 = Way(1, {'landusage': 'forest', 'highway': 'secondary'}, [1, 2, 3])
     w1.coords = [(0, 0), (10, 0), (10, 10)]
     w2 = Way(2, {'highway': 'secondary'}, [3, 4, 1])
     w2.coords = [(10, 10), (0, 10), (0, 0)]
 
     r = Relation(1, {'landusage': 'forest'}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
     builder = self.relation_builder(r, None, None)
     rings = builder.build_rings([w1, w2])
     
     builder.build_relation_geometry(rings)
     
     eq_(w1.inserted, False) # also highway=secondary
     eq_(w2.inserted, False)
 def test_simple_polygon_from_two_lines(self):
     w1 = Way(1, {}, [1, 2, 3])
     w1.coords = [(0, 0), (10, 0), (10, 10)]
     w2 = Way(2, {}, [3, 4, 1])
     w2.coords = [(10, 10), (0, 10), (0, 0)]
 
     r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
     builder = self.relation_builder(r, None, None)
     rings = builder.build_rings([w1, w2])
     eq_(len(rings), 1)
     eq_(rings[0].geom.area, 100)
 
     builder.build_relation_geometry(rings)
 
     eq_(r.geom.area, 100)
Exemple #9
0
    def test_inserted_multiple_tags(self):
        w1 = Way(1, {'landusage': 'forest', 'highway': 'secondary'}, [1, 2, 3])
        w1.coords = [(0, 0), (10, 0), (10, 10)]
        w2 = Way(2, {'highway': 'secondary'}, [3, 4, 1])
        w2.coords = [(10, 10), (0, 10), (0, 0)]

        r = Relation(1, {'landusage': 'forest'}, [(1, 'way', 'outer'),
                                                  (2, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2])

        builder.build_relation_geometry(rings)

        eq_(w1.inserted, False)  # also highway=secondary
        eq_(w2.inserted, False)
Exemple #10
0
    def test_simple_polygon_from_two_lines(self):
        w1 = Way(1, {}, [1, 2, 3])
        w1.coords = [(0, 0), (10, 0), (10, 10)]
        w2 = Way(2, {}, [3, 4, 1])
        w2.coords = [(10, 10), (0, 10), (0, 0)]

        r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2])
        eq_(len(rings), 1)
        eq_(rings[0].geom.area, 100)

        builder.build_relation_geometry(rings)

        eq_(r.geom.area, 100)
Exemple #11
0
def test_merge_rings_reverse_endpoint():
    w1 = Way(1, {'name': 'foo'}, [1, 2, 3, 4])
    w1.coords = []
    r1 = Ring(w1)
    w2 = Way(2, {'building': 'true'}, [6, 5, 4])
    w2.coords = []
    r2 = Ring(w2)
    w3 = Way(3, {}, [1, 7, 6])
    w3.coords = []
    r3 = Ring(w3)

    rings = merge_rings([r1, r2, r3])
    eq_(len(rings), 1)
    r = rings[0]
    eq_(r.tags, {'name': 'foo', 'building': 'true'})
    eq_(r.is_closed(), True)
    def test_broken_polygon_self_intersect(self):
        #  2##3    6##7
        #  #  #    ####
        #  1##4____5##8
        w1 = Way(1, {}, [1, 2, 3, 4, 5, 6, 7, 8, 1])
        w1.coords = [(0, 0), (0, 10), (10, 10), (10, 0), (20, 0), (20, 10), (30, 10), (30, 0), (0, 0)]
        w2 = Way(2, {}, [15, 16, 17, 18, 15])
        w2.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]
        yield self.check_broken_polygon, w1, w2

        #  2##3    6##7
        #  #  #    ####
        #  1##4____5##8
        w1 = Way(1, {}, [4, 1, 2, 3, 4, 5, 6, 7, 8, 4])
        w1.coords = [(10, 0), (0, 0), (0, 10), (10, 10), (10, 0), (20, 0), (20, 10), (30, 10), (30, 0), (10, 0)]
        yield self.check_broken_polygon, w1, w2
 def test_simple_polygon_w_hole(self):
     w1 = Way(1, {}, [1, 2, 3, 4, 1])
     w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
     w2 = Way(2, {}, [5, 6, 7, 8, 5])
     w2.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]
 
     r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
     builder = self.relation_builder(r, None, None)
     rings = builder.build_rings([w1, w2])
     eq_(len(rings), 2)
     eq_(rings[0].geom.area, 100)
     eq_(rings[1].geom.area, 36)
 
     builder.build_relation_geometry(rings)
 
     eq_(r.geom.area, 100-36)
Exemple #14
0
    def test_simple_polygon_w_hole(self):
        w1 = Way(1, {}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
        w2 = Way(2, {}, [5, 6, 7, 8, 5])
        w2.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]

        r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2])
        eq_(len(rings), 2)
        eq_(rings[0].geom.area, 100)
        eq_(rings[1].geom.area, 36)

        builder.build_relation_geometry(rings)

        eq_(r.geom.area, 100 - 36)
def test_merge_rings_reverse_endpoint():
    w1 = Way(1, {'name': 'foo'}, [1, 2, 3, 4])
    w1.coords = []
    r1 = Ring(w1)
    w2 = Way(2, {'building': 'true'}, [6, 5, 4])
    w2.coords = []
    r2 = Ring(w2)
    w3 = Way(3, {}, [1, 7, 6])
    w3.coords = []
    r3 = Ring(w3)
    
    rings = merge_rings([r1, r2, r3])
    eq_(len(rings), 1)
    r = rings[0]
    eq_(r.tags, {'name': 'foo', 'building': 'true'})
    eq_(r.is_closed(), True)
Exemple #16
0
    def test_broken_polygon_self_intersect(self):
        #  2##3    6##7
        #  #  #    ####
        #  1##4____5##8
        w1 = Way(1, {}, [1, 2, 3, 4, 5, 6, 7, 8, 1])
        w1.coords = [(0, 0), (0, 10), (10, 10), (10, 0), (20, 0), (20, 10),
                     (30, 10), (30, 0), (0, 0)]
        w2 = Way(2, {}, [15, 16, 17, 18, 15])
        w2.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]
        yield self.check_broken_polygon, w1, w2

        #  2##3    6##7
        #  #  #    ####
        #  1##4____5##8
        w1 = Way(1, {}, [4, 1, 2, 3, 4, 5, 6, 7, 8, 4])
        w1.coords = [(10, 0), (0, 0), (0, 10), (10, 10), (10, 0), (20, 0),
                     (20, 10), (30, 10), (30, 0), (10, 0)]
        yield self.check_broken_polygon, w1, w2
Exemple #17
0
    def test_broken_polygon_self_intersect_triangle(self):
        #  2###
        #  #    ###4
        #  #    ###3
        #  1###
        # triangle with four points, minor overlapping

        w1 = Way(1, {}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (0, 100), (100, 50 - 0.00001),
                     (100, 50 + 0.00001), (0, 0)]
        w2 = Way(2, {}, [15, 16, 17, 18, 15])
        w2.coords = [(10, 45), (10, 55), (20, 55), (20, 45), (10, 45)]

        r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2])
        eq_(len(rings), 2)
        assert_almost_equal(rings[0].geom.area, 100 * 100 / 2, 2)
        eq_(rings[1].geom.area, 100)

        builder.build_relation_geometry(rings)
        assert_almost_equal(r.geom.area, 100 * 100 / 2 - 100, 2)

        # larger overlapp
        w1 = Way(1, {}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (0, 100), (100, 50 - 1), (100, 50 + 1), (0, 0)]
        w2 = Way(2, {}, [15, 16, 17, 18, 15])
        w2.coords = [(10, 45), (10, 55), (20, 55), (20, 45), (10, 45)]

        r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2])
        eq_(len(rings), 2)
        assert_almost_equal(rings[0].geom.area, 100 * 100 / 2, -3)
        eq_(rings[1].geom.area, 100)

        builder.build_relation_geometry(rings)
        assert_almost_equal(r.geom.area, 100 * 100 / 2 - 100, -3)
    def test_broken_polygon_self_intersect_triangle(self):
        #  2###
        #  #    ###4
        #  #    ###3
        #  1###
        # triangle with four points, minor overlapping
        
        w1 = Way(1, {}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (0, 100), (100, 50 - 0.00001), (100, 50 + 0.00001), (0, 0)]
        w2 = Way(2, {}, [15, 16, 17, 18, 15])
        w2.coords = [(10, 45), (10, 55), (20, 55), (20, 45), (10, 45)]

        r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2])
        eq_(len(rings), 2)
        assert_almost_equal(rings[0].geom.area, 100 * 100 / 2, 2)
        eq_(rings[1].geom.area, 100)
    
        builder.build_relation_geometry(rings)
        assert_almost_equal(r.geom.area, 100 * 100 / 2 - 100, 2)

        # larger overlapp
        w1 = Way(1, {}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (0, 100), (100, 50 - 1), (100, 50 + 1), (0, 0)]
        w2 = Way(2, {}, [15, 16, 17, 18, 15])
        w2.coords = [(10, 45), (10, 55), (20, 55), (20, 45), (10, 45)]

        r = Relation(1, {}, [(1, 'way', 'outer'), (2, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2])
        eq_(len(rings), 2)
        assert_almost_equal(rings[0].geom.area, 100 * 100 / 2, -3)
        eq_(rings[1].geom.area, 100)
    
        builder.build_relation_geometry(rings)
        assert_almost_equal(r.geom.area, 100 * 100 / 2 - 100, -3)
    def test_polygon_w_touching_holes(self):
        w1 = Way(1, {'landusage': 'forest'}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
        w2 = Way(2, {'landusage': 'scrub'}, [1, 2, 3, 4, 1])
        w2.coords = [(1, 1), (5, 1), (5, 9), (1, 9), (1, 1)]
        w3 = Way(3, {'water': 'basin'}, [1, 2, 3, 4, 1])
        w3.coords = [(5, 1), (9, 1), (9, 9), (5, 9), (5, 1)]
    
        r = Relation(1, {'landusage': 'forest'}, [
            (1, 'way', 'outer'), (2, 'way', 'inner'), (3, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2, w3])
        eq_(len(rings), 3)
        eq_(rings[0].geom.area, 100)
        eq_(rings[1].geom.area, 32)
        eq_(rings[2].geom.area, 32)
    
        builder.build_relation_geometry(rings)

        eq_(rings[0].inserted, True)
        eq_(rings[1].inserted, False)
        eq_(rings[2].inserted, False)
    
        eq_(r.geom.area, 100-64)
    def test_touching_polygons_w_hole(self):
        w1 = Way(1, {'water': 'riverbank'}, [1, 2, 3, 4, 1])
        w1.coords = [(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]
        w2 = Way(2, {'water': 'riverbank'}, [2, 5, 6, 3, 2])
        w2.coords = [(10, 0), (30, 0), (30, 10), (10, 10), (10, 0)]
        w3 = Way(3, {'landusage': 'forest'}, [7, 8, 9, 10, 7])
        w3.coords = [(2, 2), (8, 2), (8, 8), (2, 8), (2, 2)]

        r = Relation(1, {'water': 'riverbank'}, [
            (1, 'way', 'outer'), (2, 'way', 'outer'), (3, 'way', 'inner')])
        builder = self.relation_builder(r, None, None)
        rings = builder.build_rings([w1, w2, w3])
        eq_(len(rings), 3)
        eq_(rings[0].geom.area, 100)
        eq_(rings[1].geom.area, 200)
        eq_(rings[2].geom.area, 36)

        builder.build_relation_geometry(rings)

        eq_(rings[0].inserted, True)
        eq_(rings[1].inserted, True)
        eq_(rings[2].inserted, False)

        eq_(r.geom.area, 100+200-36)