-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
U-NORTHAMERICA\taheroux
authored and
U-NORTHAMERICA\taheroux
committed
Mar 6, 2014
1 parent
02e9518
commit 82bd182
Showing
4 changed files
with
49 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
from util import precondition | ||
from tile_system import TileSystem | ||
from tile_system import TileSystem, valid_key | ||
|
||
class QuadKey: | ||
|
||
def __init__(self, geo, level): | ||
# assert lat, lon and level are valid | ||
self.key = QuadKey.get_quadkey(geo, level) | ||
self.geo = geo | ||
self.latitude = geo[0] | ||
self.longitude = geo[1] | ||
self.level = level | ||
@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] | ||
""" | ||
self.key = key | ||
self.level = len(key) | ||
|
||
def is_parent(self, parent): | ||
return self != parent and parent.key[:len(self.key)-1] == self.key | ||
|
||
def __eq__(self, other): | ||
return self.key == other.key | ||
|
||
def __ne__(self, other): | ||
return not self.__eq__(other) | ||
|
||
def __str__(self): | ||
return self.key | ||
|
||
def __repr__(self): | ||
return self.key | ||
|
||
@classmethod | ||
def from_str(cls, key): | ||
level = len(key) | ||
geo = QuadKey.get_coordinates(key) | ||
return cls(geo, level) | ||
|
||
@staticmethod | ||
def get_quadkey(geo, level): | ||
def from_geo(geo, level): | ||
""" | ||
Constucts a quadkey representation from geo and level | ||
geo => (lat, lon) | ||
If lat or lon are outside of bounds, they will be clipped | ||
If level is outside of bounds, an AssertionError is raised | ||
""" | ||
pixel = TileSystem.geo_to_pixel(geo, level) | ||
tile = TileSystem.pixel_to_tile(pixel) | ||
quadkey = TileSystem.tile_to_quadkey(tile, level) | ||
return quadkey | ||
key = TileSystem.tile_to_quadkey(tile, level) | ||
return QuadKey(key) | ||
|
||
@staticmethod | ||
def get_coordinates(key): | ||
pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters