【问题标题】:Cant correctly rotate point using GeoPandas无法使用 GeoPandas 正确旋转点
【发布时间】:2019-09-23 14:40:03
【问题描述】:

我的 Python 代码:

from geopandas import GeoSeries
from shapely.geometry import Point

WGS84 = {'init': 'epsg:4326'}
p1 = (41.8121843, 45.2178516,)
p2 = (41.8124878, 45.2177536,)

point2 = Point(p2)

s2 = GeoSeries(point2, crs=WGS84)
rotated = s2.rotate(90, p1)  # Try to rotate p2 around p1

print(rotated)  # 41.8122823 45.2181551

我的 JS 代码(Turf.js):

var p1 = [41.8121843, 45.2178516];
var p2 = [41.8124878, 45.2177536];

var l = turf.lineString( [p1, p2] );
L.geoJson(l, {style: {color: '#0000ff', fillOpacity: 1, fillColor: '#0000ff', opacity: 1}}).addTo(map);

// Rotate line around p1
var trufRotated = turf.transformRotate(l, -90, {pivot: p1});
L.geoJson(trufRotated, {style: {color: '#ff0000'}}).addTo(map);

插图。蓝色是原线。红色是使用 Turf.js 旋转的线(好的)。绿色是使用 GeoPandas 旋转的线(不好):

使用 geopandas 旋转的绿线偏移错误。也许是投影的问题,但我不知道如何解决。

我的问题是如何使用 GeoPandas 正确旋转?

【问题讨论】:

  • geopandas 将其 geometric 操作调度到 shapely。我不希望这样的操作在地理坐标中起作用。重新投影到本地坐标系。
  • @PaulH 我尝试在旋转后使用rotated = rotated.to_crs(WGS84),但它没有任何积极作用。你能举例说明如何正确地做到这一点吗?
  • 你需要在 旋转之前投影
  • @PualH 你可以在这里查看吗,stackoverflow.com/questions/55974083/…

标签: python rotation geo geopandas turfjs


【解决方案1】:

解决了。感谢@PaulH。我需要在墨卡托中旋转并在 lon/lat 中再次翻译:

WGS84 = {'init': 'epsg:4326'}
MERC = {'init': 'epsg:3857'}

p1 = (41.8121843, 45.2178516,)
p2 = (41.8124878, 45.2177536,)

point1 = Point(p1)
point2 = Point(p2)

s1 = GeoSeries(point1, crs=WGS84)
s2 = GeoSeries(point2, crs=WGS84)

s11 = s1.to_crs(MERC)
s22 = s2.to_crs(MERC)

rotated = s22.rotate(90, s11[0])
rotated = rotated.to_crs(WGS84)
print(rotated)

【讨论】:

    猜你喜欢
    • 2019-05-22
    • 2011-10-21
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多