Ejemplo n.º 1
0
class TestWayAttributes(HandlerTestBase, unittest.TestCase):

    apply_locations = True

    data = [
        osmobj('N', id=1, lat=0, lon=0),
        osmobj('N', id=3, lat=1, lon=1),
        osmobj('W',
               id=1,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******',
               nodes=[1, 2, 3])
    ]

    class Handler(o.SimpleHandler):
        def way(self, n):
            assert_equals(n.id, 1)
            assert_equals(n.deleted, False)
            assert_equals(n.visible, True)
            assert_equals(n.version, 5)
            assert_equals(n.changeset, 58674)
            assert_equals(n.uid, 42)
            assert_equals(n.user_is_anonymous(), False)
            assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35))
            assert_equals(n.user, 'anonymous')
            assert_equals(n.positive_id(), 1)
            assert_false(n.is_closed())
            assert_false(n.ends_have_same_id())
            assert_false(n.ends_have_same_location())
            assert_true(check_repr(n))
            assert_true(check_repr(n.nodes))
Ejemplo n.º 2
0
    def run(self):
        data = [osmobj('N', id=1, lat=0, lon=0),
                osmobj('N', id=2, lat=0, lon=1),
                osmobj('N', id=3, lat=1, lon=0),
                osmobj('W', id=1, nodes = [1,2,3])]
        HandlerFunction(way=self).run(data, apply_locations=True)

        assert_equals(3, len(self.geoms))
        return self.geoms
Ejemplo n.º 3
0
    def run(self):
        data = [osmobj('N', id=1, lat=0, lon=0),
                osmobj('N', id=2, lat=0, lon=1),
                osmobj('N', id=3, lat=1, lon=0),
                osmobj('W', id=23,
                       nodes = [1,2,3,1], tags = { "area" : "yes" })]
        HandlerFunction(area=self).run(data, apply_locations=True)

        assert_equals(1, len(self.geoms))
        return self.geoms[0]
Ejemplo n.º 4
0
    def run(self):
        data = [
            osmobj('N', id=1, lat=0, lon=0),
            osmobj('N', id=2, lat=0, lon=1),
            osmobj('N', id=3, lat=1, lon=0),
            osmobj('W', id=23, nodes=[1, 2, 3, 1], tags={"area": "yes"})
        ]
        HandlerFunction(area=self).run(data, apply_locations=True)

        assert_equals(1, len(self.geoms))
        return self.geoms[0]
Ejemplo n.º 5
0
    def run(self):
        data = [
            osmobj('N', id=1, lat=0, lon=0),
            osmobj('N', id=2, lat=0, lon=1),
            osmobj('N', id=3, lat=1, lon=0),
            osmobj('W', id=1, nodes=[1, 2, 3])
        ]
        HandlerFunction(way=self).run(data, apply_locations=True)

        assert_equals(3, len(self.geoms))
        return self.geoms
Ejemplo n.º 6
0
class TestWkbCreateWay(HandlerTestBase, unittest.TestCase):
    data = [osmobj('N', id=1, lat=0, lon=0),
            osmobj('N', id=2, lat=0, lon=1),
            osmobj('N', id=3, lat=1, lon=0),
            osmobj('W', id=1, nodes = [1,2,3])]
    apply_locations = True

    class Handler(o.SimpleHandler):
        def way(self, w):
            wkb = wkbfab.create_linestring(w)
            wkb = wkbfab.create_linestring(w, direction=o.geom.direction.BACKWARD)
            wkb = wkbfab.create_linestring(w, use_nodes=o.geom.use_nodes.ALL)
Ejemplo n.º 7
0
class TestWkbCreatePoly(HandlerTestBase, unittest.TestCase):
    data = [osmobj('N', id=1, lat=0, lon=0),
            osmobj('N', id=2, lat=0, lon=1),
            osmobj('N', id=3, lat=1, lon=0),
            osmobj('W', id=23,
                   nodes = [1,2,3,1], tags = { "area" : "yes" }),
           ]
    apply_locations = True

    class Handler(o.SimpleHandler):
        def area(self, a):
            wkb = wkbfab.create_multipolygon(a)
Ejemplo n.º 8
0
def test_haversine():
    data = [osmobj('N', id=1, lat=0, lon=0),
                osmobj('N', id=2, lat=0, lon=1),
                osmobj('N', id=3, lat=1, lon=0),
                osmobj('W', id=1, nodes = [1,2,3])]

    results = []
    def call_haversine(w):
        results.append(o.geom.haversine_distance(w.nodes))
    HandlerFunction(way=call_haversine).run(data, apply_locations=True)

    assert_equal(1, len(results))
    assert_almost_equals(268520, results[0], 0)
Ejemplo n.º 9
0
class TestRelationAttributes(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('R',
               id=1,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******',
               members=[('way', 1, '')])
    ]

    class Handler(o.SimpleHandler):
        def relation(self, n):
            assert_equals(n.id, 1)
            assert_equals(n.deleted, False)
            assert_equals(n.visible, True)
            assert_equals(n.version, 5)
            assert_equals(n.changeset, 58674)
            assert_equals(n.uid, 42)
            assert_equals(n.user_is_anonymous(), False)
            assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35))
            assert_equals(n.user, 'anonymous')
            assert_equals(n.positive_id(), 1)
            assert_true(check_repr(n))
            assert_true(check_repr(n.members))
Ejemplo n.º 10
0
class TestWkbCreateWay(HandlerTestBase, unittest.TestCase):
    data = [osmobj('N', id=1, lat=0, lon=0),
            osmobj('N', id=2, lat=0, lon=1),
            osmobj('N', id=3, lat=1, lon=0),
            osmobj('W', id=1, nodes = [1,2,3])]
    apply_locations = True

    class Handler(o.SimpleHandler):
        wkbs = []
        def way(self, w):
            self.wkbs.append(wkbfab.create_linestring(w))
            self.wkbs.append(wkbfab.create_linestring(w, direction=o.geom.direction.BACKWARD))
            self.wkbs.append(wkbfab.create_linestring(w, use_nodes=o.geom.use_nodes.ALL))

    def check_result(self):
        assert_equals(3, len(self.handler.wkbs))
Ejemplo n.º 11
0
class TestChangesetAttributes(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('C',
               id=34,
               created_at="2005-04-09T19:54:13Z",
               num_changes=2,
               closed_at="2005-04-09T20:54:39Z",
               open="false",
               min_lon=-0.1465242,
               min_lat=51.5288506,
               max_lon=-0.1464925,
               max_lat=51.5288620,
               user="******",
               uid="1")
    ]

    class Handler(o.SimpleHandler):
        def changeset(self, c):
            assert_equals(34, c.id)
            assert_equals(1, c.uid)
            assert_false(c.user_is_anonymous())
            assert_equals("Steve", c.user)
            assert_equals(mkdate(2005, 4, 9, 19, 54, 13), c.created_at)
            assert_equals(mkdate(2005, 4, 9, 20, 54, 39), c.closed_at)
            assert_false(c.open)
            assert_equals(2, c.num_changes)
            assert_equals(0, len(c.tags))
            assert_equals(-1464925, c.bounds.top_right.x)
            assert_equals(515288620, c.bounds.top_right.y)
            assert_equals(-1465242, c.bounds.bottom_left.x)
            assert_equals(515288506, c.bounds.bottom_left.y)
            assert_true(check_repr(c))
Ejemplo n.º 12
0
class TestNodeAttributes(HandlerTestWithMergeInput, unittest.TestCase):
    data = [
        osmobj('N',
               id=1,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user=u'änonymous')
    ]

    class Handler(ExecutedHandler):
        def node(self, n):
            assert_equals(n.id, 1)
            assert_equals(n.deleted, False)
            assert_equals(n.visible, True)
            assert_equals(n.version, 5)
            assert_equals(n.changeset, 58674)
            assert_equals(n.uid, 42)
            assert_equals(n.user_is_anonymous(), False)
            assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35))
            assert_equals(n.user, u'änonymous')
            assert_equals(n.positive_id(), 1)
            assert_true(check_repr(n))
            self.has_run = True
Ejemplo n.º 13
0
class TestWkbCreatePoly(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('N', id=1, lat=0, lon=0),
        osmobj('N', id=2, lat=0, lon=1),
        osmobj('N', id=3, lat=1, lon=0),
        osmobj('W', id=23, nodes=[1, 2, 3, 1], tags={"area": "yes"}),
    ]
    apply_locations = True

    class Handler(o.SimpleHandler):
        wkbs = []

        def area(self, a):
            self.wkbs.append(wkbfab.create_multipolygon(a))

    def check_result(self):
        assert_equals(1, len(self.handler.wkbs))
Ejemplo n.º 14
0
 def test_relation_with_tags(self):
     self._run_file(
         create_osm_file([
             osmobj('R',
                    id=1,
                    members=[('way', 1, '')],
                    tags=dict(foo='bar', name='xx'))
         ]))
Ejemplo n.º 15
0
 def test_way_with_tags(self):
     self._run_file(
         create_osm_file([
             osmobj('W',
                    id=1,
                    nodes=[1, 2, 3],
                    tags=dict(foo='bar', name='xx'))
         ]))
Ejemplo n.º 16
0
def test_haversine():
    data = [
        osmobj('N', id=1, lat=0, lon=0),
        osmobj('N', id=2, lat=0, lon=1),
        osmobj('N', id=3, lat=1, lon=0),
        osmobj('W', id=1, nodes=[1, 2, 3])
    ]

    results = []

    def call_haversine(w):
        results.append(o.geom.haversine_distance(w.nodes))

    HandlerFunction(way=call_haversine).run(data, apply_locations=True)

    assert_equal(1, len(results))
    assert_almost_equals(268520, results[0], 0)
Ejemplo n.º 17
0
 def test_file_header(self):
     fn = create_osm_file([osmobj('N', id=1)])
     try:
         rd = o.io.Reader(fn)
         h = rd.header()
         assert_false(h.has_multiple_object_versions)
         rd.close()
     finally:
         os.remove(fn)
Ejemplo n.º 18
0
 def test_file_header(self):
     fn = create_osm_file([osmobj('N', id=1)])
     try:
         rd = o.io.Reader(fn)
         h = rd.header()
         assert_false(h.has_multiple_object_versions)
         rd.close()
     finally:
         os.remove(fn)
Ejemplo n.º 19
0
 def test_broken_timestamp(self):
     fn = create_osm_file([osmobj('N', id=1, timestamp='x')])
     try:
         rd = o.io.Reader(fn)
         with assert_raises(ValueError):
             o.apply(rd, o.SimpleHandler())
             rd.close()
     finally:
         os.remove(fn)
Ejemplo n.º 20
0
 def test_broken_timestamp(self):
     fn = create_osm_file([osmobj('N', id=1, timestamp='x')])
     try:
         rd = o.io.Reader(fn)
         with assert_raises(ValueError):
             o.apply(rd, o.SimpleHandler())
             rd.close()
     finally:
         os.remove(fn)
Ejemplo n.º 21
0
class TestWkbCreateNode(HandlerTestBase, unittest.TestCase):
    data = [osmobj('N', id=1)]

    class Handler(o.SimpleHandler):
        wkbs = []
        def node(self, n):
            self.wkbs.append(wkbfab.create_point(n))

    def check_result(self):
        assert_equals(1, len(self.handler.wkbs))
Ejemplo n.º 22
0
 def test_file_header(self):
     fn = create_osm_file([osmobj('N', id=1)])
     try:
         rd = o.io.Reader(fn)
         h = rd.header()
         assert_false(h.has_multiple_object_versions)
         assert_true(h.box().valid())
         assert_equals(h.box().size(), 64800.0)
         rd.close()
     finally:
         os.remove(fn)
Ejemplo n.º 23
0
def import_data(function_complete):
    data = [osmobj('N', id=1, lat=28.0, lon=-23.3)]
    fn = create_osm_file(data)

    c = CountingHandler()
    try:
        c.apply_file(fn)
    finally:
        os.remove(fn)

    function_complete.set()
Ejemplo n.º 24
0
def test_get_newest_change_from_file():
    data = [osmobj('N', id=1, version=1, changeset=63965061, uid=8369524,
                   timestamp='2018-10-29T03:56:07Z', user='******')]
    fn = create_osm_file(data)


    try:
        val = osmium.replication.newest_change_from_file(fn)
        assert_equals(val, mkdate(2018, 10, 29, 3, 56, 7))
    finally:
        os.remove(fn)
Ejemplo n.º 25
0
def import_data(function_complete):
    data = [osmobj('N', id=1, lat=28.0, lon=-23.3)]
    fn = create_osm_file(data)

    c = CountingHandler()
    try:
        c.apply_file(fn)
    finally:
        os.remove(fn)

    function_complete.set()
Ejemplo n.º 26
0
class TestAreaFromWayAttributes(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('N', id=1, lat=0, lon=0),
        osmobj('N', id=2, lat=0, lon=1),
        osmobj('N', id=3, lat=1, lon=0),
        osmobj('W',
               id=23,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******',
               nodes=[1, 2, 3, 1],
               tags={"area": "yes"}),
    ]

    class Handler(ExecutedHandler):
        def area(self, n):
            assert_equals(n.id, 46)
            assert_equals(n.deleted, False)
            assert_equals(n.visible, True)
            assert_equals(n.version, 5)
            assert_equals(n.changeset, 58674)
            assert_equals(n.uid, 42)
            assert_equals(n.user_is_anonymous(), False)
            assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35))
            assert_equals(n.user, 'anonymous')
            assert_equals(n.positive_id(), 46)
            assert_equals(n.orig_id(), 23)
            assert_equals(n.from_way(), True)
            assert_equals(n.is_multipolygon(), False)
            assert_equals(n.num_rings(), (1, 0))
            assert_equals(len(list(n.outer_rings())), 1)
            oring = list(n.outer_rings())[0]
            assert_equals(len(list(oring)), 4)
            assert_equals(set((1, 2, 3)), set([x.ref for x in oring]))
            assert_true(oring.is_closed())
            assert_true(oring.ends_have_same_id())
            assert_true(oring.ends_have_same_location())
            assert_equals(len(list(n.inner_rings(oring))), 0)
            self.has_run = True
Ejemplo n.º 27
0
def test_get_replication_header_empty():
    data = [osmobj('N', id=1, version=1, changeset=63965061, uid=8369524,
                   timestamp='2018-10-29T03:56:07Z', user='******')]
    fn = create_osm_file(data)

    try:
        val = rutil.get_replication_header(fn)
        assert_is_none(val.url)
        assert_is_none(val.sequence)
        assert_is_none(val.timestamp)
    finally:
        os.remove(fn)
Ejemplo n.º 28
0
class TestAreaFromBoundaryRelation(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('N', id=1, lat=0, lon=0),
        osmobj('N', id=2, lat=0, lon=1),
        osmobj('N', id=3, lat=1, lon=0),
        osmobj('W',
               id=23,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******',
               nodes=[1, 2, 3],
               tags={}),
        osmobj('W',
               id=24,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******',
               nodes=[3, 1],
               tags={}),
        osmobj('R',
               id=1,
               version=3,
               changeset=7654,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******',
               members=[('way', 23, 'outer'), ('way', 24, 'outer')],
               tags={'type': 'boundary'}),
    ]

    class Handler(ExecutedHandler):
        def area(self, n):
            assert_equals(n.id, 3)
            assert_equals(n.deleted, False)
            assert_equals(n.visible, True)
            assert_equals(n.version, 3)
            assert_equals(n.changeset, 7654)
            assert_equals(n.uid, 42)
            assert_equals(n.user_is_anonymous(), False)
            assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35))
            assert_equals(n.user, 'Anon')
            assert_equals(n.positive_id(), 3)
            assert_equals(n.orig_id(), 1)
            assert_equals(n.from_way(), False)
            assert_equals(n.is_multipolygon(), False)
            assert_equals(n.num_rings(), (1, 0))
            assert_equals(len(list(n.outer_rings())), 1)
            oring = list(n.outer_rings())[0]
            assert_equals(len(list(oring)), 4)
            assert_equals(set((1, 2, 3)), set([x.ref for x in oring]))
            assert_true(oring.is_closed())
            assert_true(oring.ends_have_same_id())
            assert_true(oring.ends_have_same_location())
            assert_equals(len(list(n.inner_rings(oring))), 0)
            self.has_run = True
Ejemplo n.º 29
0
class TestNodePositiveId(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('N',
               id=-34,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******')
    ]

    class Handler(o.SimpleHandler):
        def node(self, n):
            assert_equals(n.positive_id(), 34)
Ejemplo n.º 30
0
class TestNodeLargeId(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('N',
               id=17179869418,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******')
    ]

    class Handler(o.SimpleHandler):
        def node(self, n):
            assert_equals(n.id, 17179869418)
Ejemplo n.º 31
0
class TestNodeLargeId(HandlerTestWithMergeInput, unittest.TestCase):
    data = [
        osmobj('N',
               id=17179869418,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******')
    ]

    class Handler(ExecutedHandler):
        def node(self, n):
            assert_equals(n.id, 17179869418)
            self.has_run = True
Ejemplo n.º 32
0
def test_get_newest_change_from_file():
    data = [
        osmobj('N',
               id=1,
               version=1,
               changeset=63965061,
               uid=8369524,
               timestamp='2018-10-29T03:56:07Z',
               user='******')
    ]
    fn = create_osm_file(data)

    try:
        val = osmium.replication.newest_change_from_file(fn)
        assert_equals(val, mkdate(2018, 10, 29, 3, 56, 7))
    finally:
        os.remove(fn)
Ejemplo n.º 33
0
def test_get_replication_header_empty():
    data = [
        osmobj('N',
               id=1,
               version=1,
               changeset=63965061,
               uid=8369524,
               timestamp='2018-10-29T03:56:07Z',
               user='******')
    ]
    fn = create_osm_file(data)

    try:
        val = rutil.get_replication_header(fn)
        assert_is_none(val.url)
        assert_is_none(val.sequence)
        assert_is_none(val.timestamp)
    finally:
        os.remove(fn)
Ejemplo n.º 34
0
class TestNodeAttributes(HandlerTestBase, unittest.TestCase):
    data = [
        osmobj('N',
               id=1,
               version=5,
               changeset=58674,
               uid=42,
               timestamp='2014-01-31T06:23:35Z',
               user='******')
    ]

    class Handler(o.SimpleHandler):
        def node(self, n):
            assert_equals(n.id, 1)
            assert_equals(n.deleted, False)
            assert_equals(n.visible, True)
            assert_equals(n.version, 5)
            assert_equals(n.changeset, 58674)
            assert_equals(n.uid, 42)
            assert_equals(n.user_is_anonymous(), False)
            assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35))
            assert_equals(n.user, 'anonymous')
            assert_equals(n.positive_id(), 1)
Ejemplo n.º 35
0
 def test_way_only(self):
     self._run_file(create_osm_file([osmobj('W', id=1, nodes=[1,2,3])]))
Ejemplo n.º 36
0
    def run(self):
        data = [osmobj('N', id=1, lat=28.0, lon=-23.3)]
        HandlerFunction(node=self).run(data)

        assert_equals(1, len(self.geoms))
        return self.geoms[0]
Ejemplo n.º 37
0
class TestWkbCreateNode(HandlerTestBase, unittest.TestCase):
    data = [osmobj('N', id=1)]

    class Handler(o.SimpleHandler):
        def node(self, n):
            wkb = wkbfab.create_point(n)
Ejemplo n.º 38
0
 def test_relation_only(self):
     self._run_file(
         create_osm_file([osmobj('R', id=1, members=[('way', 1, '')])]))
Ejemplo n.º 39
0
    def run(self):
        data = [osmobj('N', id=1, lat=28.0, lon=-23.3)]
        HandlerFunction(node=self).run(data)

        assert_equals(1, len(self.geoms))
        return self.geoms[0]
Ejemplo n.º 40
0
 def test_relation_only(self):
     self._run_file(create_osm_file([osmobj('R', id=1, members=[('way', 1, '')])]))
Ejemplo n.º 41
0
 def test_node_with_tags(self):
     self._run_file(create_osm_file([osmobj('N', id=1, 
                                            tags=dict(foo='bar', name='xx'))]))
Ejemplo n.º 42
0
 def test_way_with_tags(self):
     self._run_file(create_osm_file([osmobj('W', id=1, nodes=[1,2,3],
                                            tags=dict(foo='bar', name='xx'))]))
Ejemplo n.º 43
0
 def test_relation_with_tags(self):
     self._run_file(create_osm_file([osmobj('R', id=1, members=[('way', 1, '')],
                                            tags=dict(foo='bar', name='xx'))]))
Ejemplo n.º 44
0
 def test_node_with_tags(self):
     self._run_file(
         create_osm_file(
             [osmobj('N', id=1, tags=dict(foo='bar', name='xx'))]))
Ejemplo n.º 45
0
 def test_node_only(self):
     self._run_file(create_osm_file([osmobj('N', id=1)]))