Here are some made-up coordinates, UTM zone 16N, NAD27 datum:
x = 1796891.94
y = 101128551.19
We'd like to convert them into UTM zone 15N, WGS84 datum.
For a start, those look like they are in feet. Let's convert them:
x *= 0.3048
y *= 0.3048
x, y
(547692.663312, 30823982.402712002)
We will use the pyproj
project.
import pyproj as pp
Set up the 'source' and 'target' projections using EPSG codes:
utm16_nad27 = pp.Proj(init='epsg:26716')
utm15_wgs84 = pp.Proj(init='epsg:32615')
Now we can do the transformation...
new_coords = pp.transform(utm16_nad27, # From
utm15_wgs84, # To
x, y) # Coordinates
new_coords # These are in metres!
(633989.9634796401, -9177126.336612783)
The x
and y
could also be arrays:
import numpy as np
x = np.array([500000, 550000, 560000])
y = np.array([1600000, 1650000, 1660000])
pp.transform(utm16_nad27,utm15_wgs84, x, y)
(array([1147639.24836805, 1196558.79719467, 1206342.16627149]), array([1608596.47150905, 1660201.86925774, 1670532.61011427]))
If you have an array of (x, y) pairs, there's a quick way to unpack them:
coords = np.array([[500000, 1600000], [550000, 1650000], [560000, 1660000]])
pp.transform(utm16_nad27,utm15_wgs84, *coords.T)
(array([1147639.24836805, 1196558.79719467, 1206342.16627149]), array([1608596.47150905, 1660201.86925774, 1670532.61011427]))
Or you might have a pandas
DataFrame with x
and y
columns:
import pandas as pd
df = pd.DataFrame(coords, columns=['x_UTM16', 'y_UTM16'])
df['Attrib1'] = [123, 456, 789]
df
x | y | Attrib1 | |
---|---|---|---|
0 | 500000 | 1600000 | 123 |
1 | 550000 | 1650000 | 456 |
2 | 560000 | 1660000 | 789 |
df['x_UTM15'], df['y_UTM15'] = pp.transform(utm16_nad27,utm15_wgs84, df.x.values, df.y.values)
df
x | y | Attrib1 | x_UTM15 | y_UTM15 | |
---|---|---|---|---|---|
0 | 500000 | 1600000 | 123 | 1.147639e+06 | 1.608596e+06 |
1 | 550000 | 1650000 | 456 | 1.196559e+06 | 1.660202e+06 |
2 | 560000 | 1660000 | 789 | 1.206342e+06 | 1.670533e+06 |
pd.options.display.float_format = '{:.0f}'.format
df
x | y | Attrib1 | x_UTM15 | y_UTM15 | |
---|---|---|---|---|---|
0 | 500000 | 1600000 | 123 | 1147639 | 1608596 |
1 | 550000 | 1650000 | 456 | 1196559 | 1660202 |
2 | 560000 | 1660000 | 789 | 1206342 | 1670533 |
© 2019 Agile Geoscience — CC-BY — Have fun!