[英]Lat/Long to UTM conversion failing for dataframe
当我在 dataframe 上使用utm.from latlon()
function 时,会出现错误OutOfRangeError: latitude out of range (must be between 80 deg S and 84 deg N)"
。
但是,当我尝试单个纬度/经度时,它会返回结果。 我不确定发生了什么事。
例如 dataframe
Lat Lon
0 49.183630 -121.936812
1 43.901052 -78.939154
2 43.887452 -78.871573
3 42.882137 -82.445210
4 43.372565 -79.762019
正如我检查的那样,我的纬度/经度没有反转。
假设 utm function 定义为:
def f(x,y):
return utm.from_latlon(x,y)
我将 function 称为:
dataframe.apply(lambda row: f(row['Lat'], row['Lon']), axis=1)
假设您使用utm package:
import pandas as pd
import utm
df = pd.read_csv('latlon.csv')
df['utm'] = df.apply(lambda row: utm.from_latlon(*row), axis=1)
utm_cols = ['easting', 'northing', 'zone_number', 'zone_letter']
for n, col in enumerate(utm_cols):
df[col] = df['utm'].apply(lambda location: location[n])
df = df.drop('utm', axis=1)
print(df)
output
Lat Lon easting northing zone_number zone_letter
0 49.183630 -121.936812 577477.332853 5.448413e+06 10 U
1 43.901052 -78.939154 665502.266670 4.862947e+06 17 T
2 43.887452 -78.871573 670968.577419 4.861574e+06 17 T
3 42.882137 -82.445210 381977.464091 4.748739e+06 17 T
4 43.372565 -79.762019 600294.444939 4.802933e+06 17 T
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.