diff --git a/README.md b/README.md index 35e2f0f..a5b4a05 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ QuadKey ======= -Quad key object used for Geospatial segmentation +Quad key object used for Geospatial segmentation. Based off the idea of a quadtree and used as the Bing Maps tile system. + +Given a (lat, lon) and level produce a quadkey to be used in Bing Maps. +Can also supply methods to generate a Google Maps TileXYZ + +Built off of the TileSystem static class outlined here: http://msdn.microsoft.com/en-us/library/bb259689.aspx + +Converts a lat,lon to pixel space to tile space to a quadkey + from quadkey import QuadKey - qk = QuadKey((-105, 40) 17) + qk = QuadKey.from_geo((-105, 40), 17) print qk.key # => 02310101232121212 assert qk.level is 17 - copy = QuadKey.from_str(qk.key) + tile = qk.to_tile() # => [(x, y), z] diff --git a/quadkey/__init__.py b/quadkey/__init__.py index 6b1e063..4998190 100644 --- a/quadkey/__init__.py +++ b/quadkey/__init__.py @@ -4,6 +4,7 @@ class QuadKey: @precondition(lambda c, key: valid_key(key)) + def __init__(self, key): """ A quadkey must be between 1 and 23 digits and can only contain digit[0-3] @@ -50,6 +51,9 @@ def area(self): side = (size / 2) * res return side*side + def to_tile(self): + return TileSystem.quadkey_to_tile(self.key) + def __eq__(self, other): return self.key == other.key