import pyproj
import numpy as np
import math
import pyproj as ppj
print("# numpy version = ",np.__version__)
print("# pyproj version = ",ppj.__version__)
# M3+ events
lond = -115.6000000
latd = 33.1750000
# where latd and lond at xy coordinate
x0 = 0
y0 = 0
This example assumes: x -> longitude, y-> latitude. if xy coordinate is rotated with some degrees, we need to use "azimuth" or "invAngle" when we have latd2 and lond2.
x1s = [-20, 10] # distance (km) from x0. will change longitude
y1s = [0,-10] # distance (km) from y0. will change latitude
This example uses WGS84 system. latd2 and lond2 are projected values in lat & lon system.
geod = pyproj.Geod(ellps='WGS84')
latd2out = np.zeros(len(x1s))
lond2out = np.zeros(len(x1s))
for i, x1 in enumerate(x1s):
#print (x1)
# do get x1 and y1 in meter
x1 = x1 * 1000
y1 = y1s[i] * 1000
#print ("# x1 = ",x1," y1 = ",y1)
distance = math.sqrt((x1-x0)**2+(y1-y0)**2)
azimuth = math.degrees(math.atan2((x1-x0),(y1-y0))) # from x0,y0
lond2,latd2,invAngle = geod.fwd(lond, latd, azimuth, distance)
#print (x1, y1,latd2, lond2, invAngle)
print("# latd2 = ", latd2, " y1 = ", y1)
print("# lond2 = ", lond2, " x1 = ", x1)
print("# distance = ", distance, " azimuth = ", azimuth)