I'm working through some examples in the Python Geospatial Development book by Erik Westra.
On page 439, about setting up a tile map server, he gives the following code for calculating a bounding box based on a centre location and a zoom level:
TILE_WIDTH = 256 TILE_HEIGHT = 256 x_extent = _unitsPerPixel(zoomLevel) * TILE_WIDTH y_extent = _unitsPerPixel(zoomLevel) * TILE_HEIGHT min_long = x * x_extent - 180.0 min_lat = y * y_extent - 90.0 max_long = min_long + x_extent max_lat = min_lat + y_extent def _unitsPerPixel(zoomLevel): return 0.703125/math.pow(2, zoomLevel)
Nowhere does he specify what the
y units are expected to be. I assumed lat long coords (same as map) but then the above calculations do not work.
For example, suppose I have
x = 50.0 and
y=-2.09 and a zoom level of 5.
For the min_lat, I will then have approximately:
min_lat = -2.09 * 5.63 - 90.0
Which is going to give less than -90, the limit of our map...?!?
Everytime you pass a negative lat/long coordinate this will fall down....
Just what x/y coordinates are being expected here?