Search notes:

Python library: mpmath

mpmath is a Python library that provides arbitrary precision real and complex floating-point arithmetics.

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

See also

The built-in float type and the decimal standard-library module.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758204443, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/libraries/mpmath/index(72): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78