import numpy as np import pyproj # Use the "new" numpy API for the random number generation (requires numpy >=1.17) rng = np.random.default_rng(seed=1) # Create arrays with random points no_points = 5 longitudes = rng.uniform(low=10, high=20, size=no_points) latitudes = rng.uniform(low=33, high=45, size=no_points) print(" Longitude \t Latitude") print(np.column_stack((longitudes, latitudes))) print() # Create the transformer object. # You can create the object using either integers or "epsg" strings transformer = pyproj.Transformer.from_crs(crs_from=4326, crs_to=3857) # pyproj.Transformer.from_crs(crs_from="epsg:4326", crs_to="epsg:3857") # Apply the transformation. # Be careful! The order of the output here is Y/X y1, x1 = transformer.transform(longitudes, latitudes) print(np.column_stack((x1, y1))) print() # If you prefer to work with X/Y instead you need to set `always_xy=True` to the transformer object transformer = pyproj.Transformer.from_crs(crs_from=4326, crs_to=3857, always_xy=True) x2, y2 = transformer.transform(longitudes, latitudes) print(np.column_stack((x2, y2))) print()