pyGeoTile

raw JSON →
1.0.6 verified Mon Apr 27 auth: no python

Python package to handle tiles and points of different projections, in particular WGS 84 (Latitude, Longitude), Spherical Mercator (Meters), Pixel Pyramid and Tiles (TMS, Google, QuadTree). Version 1.0.6 is the latest, released intermittently.

pip install pygeotile
error AttributeError: module 'pygeotile' has no attribute 'Tile'
cause Incorrect import: using 'from pygeotile import Tile' instead of 'from pygeotile.tile import Tile'.
fix
Use: from pygeotile.tile import Tile
error ValueError: The maximum zoom level is 30
cause Zoom level provided exceeds 30, which is the maximum allowed zoom.
fix
Provide a zoom level between 0 and 30 inclusive.
gotcha Tile coordinates are zero-based and may differ between TMS and Google (XYZ) schemes. Ensure correct flip for TMS Y axis.
fix Use tile.tms_y vs tile.google_y as appropriate.
gotcha The 'quadtree' methods expect a specific input format; incorrect usage leads to ValueError.
fix Review the QuadTree section in documentation.
deprecated Old import style from pygeotile.pygeotile may exist in outdated examples; not supported in v1.0.6.
fix Use correct imports as shown in quickstart.

Create a Tile from lat/lng and access TMS, Google coordinates, and bounds.

from pygeotile.tile import Tile

# Convert WGS84 coordinates to TMS tile at zoom 15
tile = Tile.for_latitude_longitude(latitude=47.376, longitude=8.548, zoom=15)
print('TMS tile:', tile.tms_x, tile.tms_y, tile.zoom)

# Convert tile to Google (XYZ) coordinates
print('Google tile:', tile.google_x, tile.google_y)

# Get bounding box of the tile
bbox = tile.bounds
print('Bounding box:', bbox)