3

I have the following task.

This is my sample data.

WGS84 datum (longitude/latitude):
-123.75 36.59788913307022
-118.125 40.97989806962013

Spherical Mercator (meters):
-13775786.985667605 4383204.9499851465
-13149614.849955441 5009377.085697312

Pixels
2560 6144 2816 6400

Google
x:10, y:24, z:6

TMS
x:10, y:39, z:6

QuadTree
023010

I'm using the code from this source

http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/.

How should I chain the methods in order to get from google tiles (x:10, y:24, z:6) the Sperical Mercator meters

-13775786.985667605 4383204.9499851465
-13149614.849955441 5009377.085697312
?

I have used lots of combinations but I'm getting wrong numbers.

3

This issue has been sleeping here for long, but this might help some googler:

For a similar task I simplified the functions from the website that you mention to the following, it works fine for me (in Python):

def LatLonToPixels(lat, lon, zoom):
tileSize = 256
sinLat = math.sin(float(lat) * (math.pi/180))
py = (0.5 - math.log((1 + sinLat) / (1 - sinLat)) / (4 * math.pi)) * tileSize * 2**float(zoom)
px = ((float(lon) + 180) / 360) * tileSize * 2**float(zoom)
return px, py

def PixelsToTile(px, py, service):
tileSize = 256
tx = int( math.ceil( px / float(tileSize) ) - 1 )
ty = int( math.ceil( py / float(tileSize) ) - 1 )
return tx, ty

These two functions are very straightforward to use (less to get the maths behind it). You simply need to use the first one to get the coordinates in pixel of your longitude and latitude, and the second one to compute on which tile it is located.

The Bing help documents are really helpfull, have a look!

1

The PyPi package pyGeoTile simplifies this task.

from pygeotile.tile import Tile

tile = Tile.from_google(google_x=10, google_y=24, zoom=6)
point_min, point_max = tile.bounds

print(point_min.meters)
print(point_max.meters)

For more information have a look at the Github Repo: https://github.com/geometalab/pyGeoTile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.