Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions opendm/tiles/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ class GlobalMercator(object):
"""

def __init__(self, tileSize=256):
"Initialize the TMS Global Mercator pyramid"
"""Initialize the TMS Global Mercator pyramid"""
self.tileSize = tileSize
self.initialResolution = 2 * math.pi * 6378137 / self.tileSize
self._tileSize_float = float(tileSize)
self.initialResolution = 2 * math.pi * 6378137 / tileSize
# 156543.03392804062 for tileSize 256 pixels
self.originShift = 2 * math.pi * 6378137 / 2.0
# 20037508.342789244

def LatLonToMeters(self, lat, lon):
"Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:3857"
Expand Down Expand Up @@ -238,18 +238,18 @@ def PixelsToMeters(self, px, py, zoom):
return mx, my

def MetersToPixels(self, mx, my, zoom):
"Converts EPSG:3857 to pyramid pixel coordinates in given zoom level"

"""Converts EPSG:3857 to pyramid pixel coordinates in given zoom level"""
res = self.Resolution(zoom)
px = (mx + self.originShift) / res
py = (my + self.originShift) / res
shift = self.originShift
px = (mx + shift) / res
py = (my + shift) / res
return px, py

def PixelsToTile(self, px, py):
"Returns a tile covering region in given pixel coordinates"

tx = int(math.ceil(px / float(self.tileSize)) - 1)
ty = int(math.ceil(py / float(self.tileSize)) - 1)
"""Returns a tile covering region in given pixel coordinates"""
tsf = self._tileSize_float
tx = int(math.ceil(px / tsf) - 1)
ty = int(math.ceil(py / tsf) - 1)
return tx, ty

def PixelsToRaster(self, px, py, zoom):
Expand All @@ -259,8 +259,7 @@ def PixelsToRaster(self, px, py, zoom):
return px, mapSize - py

def MetersToTile(self, mx, my, zoom):
"Returns tile for given mercator coordinates"

"""Returns tile for given mercator coordinates"""
px, py = self.MetersToPixels(mx, my, zoom)
return self.PixelsToTile(px, py)

Expand Down