Python地理空间坐标格式转换 [英] Python Geo-Spatial Coordinate Format Conversion
问题描述
我有一个包含6列坐标对的数据框:度|分钟|秒(对于纬度和经度).这就是NAD83格式.我想将它们转换为只有2列的十进制格式的新数据框,称为NAD27.
I have a dataframe containing 6 columns of coordinate pairs: Degrees|Minutes|Seconds (for both latitude and longitude). This is known as the NAD83 format. I want to convert these into a new dataframe of only 2 columns in decimal format, known as NAD27.
我通常使用的库geopy实际上支持每种格式,因此实际上没有专用的转换功能.我在这里仔细阅读了文档,以确保: https://geopy.readthedocs.io/en/1.10.0/
The library I typically use, geopy supports virtually every format, so there actually isn't a dedicated conversion function. I went through the documentation here to be sure: https://geopy.readthedocs.io/en/1.10.0/
python还有其他转换为NAD27的方法吗?
Does python have any other means to convert to NAD27?
感谢您阅读
推荐答案
让我们假设您的DataFrame df
包含列 lonD
, lonM
, lonS
, latD
, latM
和 latS
.然后,应该在内部使用 geopandas
, shapely
和 pyproj
进行以下操作.
Let's suppose your DataFrame df
contains columns lonD
, lonM
, lonS
, latD
, latM
and latS
.
Then the following should work, using geopandas
, shapely
and pyproj
internally.
import geopandas as gpd
import numpy as np
from shapely.geometry import Point
def dms_to_dec(d, m, s):
sign = np.sign(d)
return d + sign * m / 60 + sign * s / 3600
points = df.apply(lambda row: Point(dms_to_dec(*row[['lonD', 'lonM', 'lonS']]),
dms_to_dec(*row[['latD', 'latM', 'latS']])),
axis=1)
gdf_nad83 = gpd.GeoDataFrame(df, geometry=points, crs={'init': 'EPSG:4269'})
gdf_nad27 = gdf_nad83.to_crs({'init': 'EPSG:4267'})
这篇关于Python地理空间坐标格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!