diff --git a/quadkey/__init__.py b/quadkey/__init__.py index 4c41fc0..abe4fb5 100644 --- a/quadkey/__init__.py +++ b/quadkey/__init__.py @@ -17,7 +17,6 @@ def __repr__(self): return self.key @classmethod - @precondition(TileSystem.valid_level) def from_str(cls, key): level = len(key) lat, lon = QuadKey.get_coordinates(key) diff --git a/quadkey/tile_system.py b/quadkey/tile_system.py index 5048b40..4d7719b 100644 --- a/quadkey/tile_system.py +++ b/quadkey/tile_system.py @@ -1,5 +1,9 @@ from util import precondition -from math import cos +from math import cos, pi + +def valid_level(level): + LEVEL_RANGE = (1,23) + return LEVEL_RANGE[0] <= level <= LEVEL_RANGE[1] class TileSystem: """ @@ -11,9 +15,6 @@ class TileSystem: EARTH_RADIUS = 6378137 LATITUDE_RANGE = (-85.05112878, 85.05112878) LONGITUDE_RANGE = (-180., 180.) - LEVEL_RANGE = (1,23) - - valid_level = lambda level: TileSystem.LEVEL_RANGE[0] <= level <= TileSystem.LEVEL_RANGE[1] @staticmethod @precondition(lambda n, minMax: minMax[0] <= minMax[1]) @@ -28,14 +29,14 @@ def map_size(level): return 256 << level @staticmethod - @precondition(valid_level(*args[1])) - def ground_resolution(float lat, int level): + @precondition(lambda lat, lvl: valid_level(lvl)) + def ground_resolution(lat, level): """Gets ground res in meters / pixel""" - lat = TileSystem.clip(lat, TileSytem.LATITUDE_RANGE) - return cos(lat * pi / 180) * 2 * pi * EARTH_RADIUS / TileSystem.map_size(level) + lat = TileSystem.clip(lat, TileSystem.LATITUDE_RANGE) + return cos(lat * pi / 180) * 2 * pi * TileSystem.EARTH_RADIUS / TileSystem.map_size(level) @staticmethod - @precondition(valid_level(*args[1])) + @precondition(lambda lat, lvl, dpi: valid_level(lvl)) def map_scale(lat, level, dpi): """Gets the scale of the map expressed as ratio 1 : N. Returns N""" return TileSystem.ground_resolution(lat, level) * dpi / 0.0254 diff --git a/quadkey/util.py b/quadkey/util.py index 21b0a36..5d09271 100644 --- a/quadkey/util.py +++ b/quadkey/util.py @@ -2,7 +2,7 @@ def condition(precondition=None, postcondition=None): def decorator(func): - @functools.wraps(func) # presever name, docstring, etc + @functools.wraps(func) # preserve name, docstring, etc def wrapper(*args, **kwargs): #NOTE: no self if precondition is not None: assert precondition(*args, **kwargs) diff --git a/tests/tile_system.py b/tests/tile_system.py index 7a0a155..fd02aa1 100644 --- a/tests/tile_system.py +++ b/tests/tile_system.py @@ -17,14 +17,26 @@ def testMapSize(self): with self.assertRaises(AssertionError): TileSystem.map_size(0) - def testFromString(self): - pass + def testGroundResolution(self): + TileSystem.ground_resolution(45, 7) - def testToString(self): - pass + def testMapScale(self): + TileSystem.map_scale(45, 7, 45) - def testGetQuadKey(self): - pass + def testGeoToPixel(self): + TileSystem.geo_to_pixel(geo, level) - def testGetCoordinates(self): - pass + def testPixelToGeo(self): + TileSystem.pixel_to_geo(pixel, level) + + def testPixelToTile(self): + TileSystem.pixel_to_tile(pixel) + + def testTileToPixel(self): + TileSystem.tile_to_pixel(tile) + + def testTileToQuadkey(self): + TileSystem.tile_to_quadkey(tile, level) + + def testQuadkeyToTile(self): + TileSystem.quadkey_to_tile(quadkey)