Search notes:

Python library: mpmath

mpmath is a Python library that provides arbitrary precision real and complex floating-point arithmetics. (Compare with the built-in float type).

Calculate tile coordinates of a «tile server»

The following simple script calculates the tile coordinates of a tile server for a latitude, longitude and zoom level. These parameters must be passed to the script as «command line arguments».
import sys
import mpmath as mp

if len(sys.argv) != 4:
   print('expected lat lon zoom')
   quit()

lat_deg = float(sys.argv[1])
lon_deg = float(sys.argv[2])
zoom    = int  (sys.argv[3])
   
lat_rad = mp.radians(lat_deg)
n = 2 ** zoom

x = n * ((lon_deg + 180) / 360)
y = n * (1 - (mp.log(mp.tan(lat_rad) + mp.sec(lat_rad)) / mp.pi)) / 2

print('x = %d, y = %d' % (x, y))
Github repository about-Python, path: /libraries/mpmath/tile-coordinates-from-lat-lon.py
This example was inspired by (and almost verbatimely copied from) towardsdatascience.com.

Installation

With pip, globally:
sudo pip install SymPy

Index