From 482629ae4ec50cc3e49df996acb03e9aee2a9180 Mon Sep 17 00:00:00 2001 From: Buck Heroux Date: Wed, 23 Apr 2014 19:43:09 -0600 Subject: [PATCH] added .to_geo(centered=True) --- quadkey/__init__.py | 10 +++++----- quadkey/tile_system.py | 8 ++++++-- setup.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/quadkey/__init__.py b/quadkey/__init__.py index c7e03fd..f756910 100644 --- a/quadkey/__init__.py +++ b/quadkey/__init__.py @@ -8,7 +8,7 @@ def __init__(self, key): """ A quadkey must be between 1 and 23 digits and can only contain digit[0-3] """ - self.key = key + self.key = key self.level = len(key) def children(self): @@ -31,7 +31,7 @@ def is_ancestor(self, node): Get the difference in level If not, None """ - if self.level <= node.level or self.key[:len(node.key)] != node.key: + if self.level <= node.level or self.key[:len(node.key)] != node.key: return None return self.level - node.level @@ -53,11 +53,11 @@ def area(self): def to_tile(self): return TileSystem.quadkey_to_tile(self.key) - def to_geo(self): + def to_geo(self, centered=False): ret = TileSystem.quadkey_to_tile(self.key) tile = ret[0] lvl = ret[1] - pixel = TileSystem.tile_to_pixel(tile) + pixel = TileSystem.tile_to_pixel(tile, centered) return TileSystem.pixel_to_geo(pixel, lvl) def __eq__(self, other): @@ -84,7 +84,7 @@ def from_geo(geo, level): pixel = TileSystem.geo_to_pixel(geo, level) tile = TileSystem.pixel_to_tile(pixel) key = TileSystem.tile_to_quadkey(tile, level) - return QuadKey(key) + return QuadKey(key) @staticmethod def from_tile(tile, level): diff --git a/quadkey/tile_system.py b/quadkey/tile_system.py index e03c6bb..3088438 100644 --- a/quadkey/tile_system.py +++ b/quadkey/tile_system.py @@ -82,9 +82,13 @@ def pixel_to_tile(pixel): return pixel[0] / 256, pixel[1] / 256 @staticmethod - def tile_to_pixel(tile): + def tile_to_pixel(tile, centered=False): """Transform tile to pixel coordinates""" - return tile[0] * 256, tile[1] * 256 + pixel = [tile[0] * 256, tile[1] * 256] + if centered: + #should clip on max map size + pixel = [pix + 128 for pix in pixel] + return pixel[0], pixel[1] @staticmethod @precondition(lambda tile, lvl: valid_level(lvl)) diff --git a/setup.py b/setup.py index 9276af4..016f954 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name="quadkey", - version="0.0.3", + version="0.0.4", description="Python Implementation for Geospatial Quadkeys", author="Buck Heroux", url="https://github.com/buckheroux/QuadKey",