【发布时间】:2022-01-20 11:52:25
【问题描述】:
我在 geopandas GeoDataFrame 中有一堆形状(例如,匀称的 LineStrings 或 Polygons)。
形状指定本地 200x200 米网格中的坐标,即所有坐标都在 (0, 0) 和 (200, 200) 之间。
我现在想在全球范围内“放置”这些行。 为此,我想指定一个 GPS 点(具有给定的纬度/经度)作为参考。
我的第一个(天真的)方法是使用 geolib,获取所有形状的坐标(在本地 X/Y 中)并应用以下转换并“重新创建”形状:
# Convert coordinates to GPS location
from shapely.geometry import LineString
from geographiclib.geodesic import Geodesic
geod = Geodesic.WGS84 # the base geodesic (i.e. the world)
origin = (48.853772345870176, 2.350983211585546) # this is somewhere in Paris, for example
def local_to_latlong(x, y, orientation=0, scale=1):
""" Two step process.
- First walk x meters to east from origin.
- Then, from that point, walk y meters north from origin.
Optional:
- orientation allows to "spin" the coordinates
- scale allows to grow/shrink the distances
"""
go_X = geod.Direct(*origin, orientation + 90, x * scale) # x is East-coordinate
go_Y = geod.Direct(go_X["lat2"], go_X["lon2"], orientation + 0, y * scale) # y is North-coordinate
return go_Y["lat2"], go_Y["lon2"]
original_line = LineString([(0,0), (100,100), (200,100)])
global_line = LineString([local_to_latlong(x, y) for y, x in original_line.coords])
但是,我希望这不是最聪明的方法,并且还有更聪明的方法......
我想将这种转换应用到 GeoDataFrame 中的任何形状上。理想情况下,它可以使用“to_crs”,但我不确定如何转换形状,以便它们“参考原点”以及使用哪个 crs。
【问题讨论】:
-
您声明“但是,我希望这不是最聪明的方法,并且还有更聪明的方法......”暗示了征求意见。当您遇到无法解决的特定问题时,最好使用本网站,一般性问题要求指导不符合 SO 的目标。
-
我不知道如何以有效的方式将它应用到整个 GeoDataFrame 上。我能做的是单独的形状,但这似乎是低效的。我知道 Geopandas 允许 CRS 更改,但我不确定要使用哪一个以及如何使其工作......
标签: python geopandas geographic-lib