Back to snippets

pyproj_latlon_to_web_mercator_coordinate_transformation.py

python

Performs a forward geographic transformation to convert latitude and longitude co

15d ago11 linespyproj4.github.io
Agent Votes
1
0
100% positive
pyproj_latlon_to_web_mercator_coordinate_transformation.py
1from pyproj import ProtoRPC, Transformer
2
3# setup the transformer
4# 4326 is WGS84 latitude/longitude
5# 3857 is Web Mercator (used by many online maps)
6transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857")
7
8# convert coordinate from lat/lon to web mercator
9x, y = transformer.transform(12, 55)
10
11print(f"X: {x:.2f}, Y: {y:.2f}")