def test_tile_to_meters_one(self): """Test conversion from tile coordinate to meters.""" merc = Mercator() z = x = y = 0 mx, my = merc.tile_to_meters(z, x, y) mx = merc.truncate(mx) my = merc.truncate(my) assert float(mx) == -20037508.34 and \ float(my) == -20037508.34
def test_get_coord_one(self): """Test get coordinate from tile method.""" merc = Mercator() z = x = y = 0 mx, my = merc.get_coord(z, x, y) mx = merc.truncate(mx) my = merc.truncate(my) assert float(mx) == -20037508.34 and \ float(my) == -20037508.34
def test_tile_to_meters_two(self): """Test conversion with a different tile coord to meters.""" merc = Mercator() z = 0 x = y = 1 mx, my = merc.tile_to_meters(z, x, y) mx = merc.truncate(mx) my = merc.truncate(my) assert float(mx) == 20037508.34 and \ float(my) == 20037508.34
def test_tile_to_meters_three(self): """Test a random tile to meters.""" merc = Mercator() z = 14 x = 11332 y = 9870 mx, my = merc.tile_to_meters(z, x, y) mx = merc.truncate(mx) my = merc.truncate(my) assert float(mx) == 7680392.60 and \ float(my) == 4104362.67
def test_get_coord_two(self): """Test get coord with a random tile.""" merc = Mercator() z = 14 x = 11332 y = 9870 mx, my = merc.get_coord(z, x, y) mx = merc.truncate(mx) my = merc.truncate(my) assert float(mx) == 7680392.60 and \ float(my) == 4104362.67
def test_tile_to_meters_four(self): """Test another corner of a random tile to meters.""" merc = Mercator() z = 14 x = 11333 y = 9871 mx, my = merc.tile_to_meters(z, x, y) mx = merc.truncate(mx) my = merc.truncate(my) assert float(mx) == 7682838.58 and \ float(my) == 4106808.65
def test_tile_to_lat_lon_two(self): """Test the top right corner of zoom 0.""" z = 0 x = y = 1 lat, lon = Mercator.tile_to_lat_lon(z, x, y) assert lon == 180.0 and lat == 85.0511287798066 z = 14 x = 11332 y = 9870 lat, lon = Mercator.tile_to_lat_lon(z, x, y) assert lon == 68.994140625 and \ lat == 34.56085936708385
def test_tile_to_lat_lon_four(self): """Test a random tile to lat/lon.""" z = 14 x = 11333 y = 9871 lat, lon = Mercator.tile_to_lat_lon(z, x, y) assert lon == 69.01611328125 and \ lat == 34.57895241036947
def test_invert_y_one(self): """Test inverted Y axis calculation.""" z = 1 y = 0 assert Mercator.invert_y(z, y) == 1
def test_invert_y_two(self): """Test a more complicated Y axis inversion.""" z = 13 y = 31 assert Mercator.invert_y(z, y) == 8160
def test_pixel_size(self): """Test pixel size calculation.""" z = randint(0, 21) result = Mercator.pixel_size(z) assert result * 2**z == 156543.033928041
def test_tile_to_lat_lon_one(self): """Test conversion from tile coordinate to lat/lon.""" z = x = y = 0 lat, lon = Mercator.tile_to_lat_lon(z, x, y) assert lon == -180.0 and lat == -85.0511287798066
def test_origin_shift(self): """Test origin shift calculation.""" merc = Mercator() assert merc.origin_shift == pi * merc.radius
def test_radius(self): """Test radius for mercator.""" merc = Mercator() assert merc.radius == 6378137
def test_tile_size(self): """Test tile size default.""" merc = Mercator() assert merc.tile_size == 256
def test_truncate(self): """Test mercator accuracy truncation.""" merc = Mercator() f = 1234.567890123 result = merc.truncate(f) assert float(result) == 1234.56
def test_init_res(self): """Test initial resolution calculation.""" merc = Mercator() assert merc.initial_resolution == 2 * \ merc.origin_shift / merc.tile_size