0

关于这个问题,是否可以在纬度、经度投影(4326)和指北针中使用x、y 轴的比例尺(以米为单位投影,例如 3857) ?

我没有看到用 geopandas 做到这一点的交钥匙解决方案。虽然这似乎是 GIS 地图显示的基本设置。这有技术原因吗?

import geopandas as gpd
from matplotlib_scalebar.scalebar import ScaleBar
import matplotlib.pyplot as plt

df = gpd.read_file(gpd.datasets.get_path('nybb'))
ax = df.to_crs(4326).plot()
ax.add_artist(ScaleBar(1)) #how add ScaleBar for df in 3857? 
plt.show()
4

1 回答 1

1

由此看来您必须计算两个位置 A 和 B 之间的大圆距离,坐标 A=[longitudeA,latitudeA] 和 B=[longitudeA+1,latitudeA],在您感兴趣的纬度(在您的案例〜40.7°)。要计算大圆距离,您可以使用 sklearn 中的“haversine_distances”(此处)并将其乘以地球的半径6371000以获得以米为单位的距离。一旦你得到这个距离dx,你可以将它传递给你的比例尺ScaleBar(dx=dx,units="m")

总的来说,代码如下所示:

import numpy as np
import geopandas as gpd
from matplotlib_scalebar.scalebar import ScaleBar
import matplotlib.pyplot as plt
from sklearn.metrics.pairwise import haversine_distances

df = gpd.read_file(gpd.datasets.get_path('nybb'))
ax = df.to_crs(4326).plot()
A=[-74.5*np.pi/180.,40.7*np.pi/180.] #Latitude of interest here 40.7 deg, longitude -74.5
B=[-73.5*np.pi/180.,40.7*np.pi/180.] ##Latitude of interest here 40.7 deg, longitude -74.5+1
dx=(6371000)*haversine_distances([A,B])[0,1]
ax.add_artist(ScaleBar(dx=dx,units="m")) 
plt.show()

输出给出:

在此处输入图像描述

于 2021-12-07T10:23:49.200 回答