0

我正在使用默认地图,例如:

world = geopandas.read_file(gpd.datasets.get_path('naturalearth_lowres'))

我可以使用以下 for 循环示例从另一个 GeoDataFrame(此处称为 sample_gdf)成功地将标签注释到此地图:

for idx, row in sample_gdf.iterrows():
     plt.annotate(text=row['country_name'], # e.g. this column contains the names of each countries
                  xy=(row['longitude'], row['latitude']), # e.g. these columns are showing the coordinates of middle points of each countries
                  horizontalalignment='center')

这就是 epsg=4326 的样子 当我想更改地图的投影时,问题就开始了。上面变量“世界”的默认 CRS 是 epsg:4326。只要我像这样更改投影:

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world = world.to_crs(epsg=3035)

专注于欧洲,我的标签不再出现在正确的位置。我一直在寻找解决这个问题的建议一个星期,但现在找不到任何解决方案。谢谢你的帮助。 这就是 epsg=3035标签出现在左下角的样子。

4

1 回答 1

0

这一切都归结为您['longitude'], ['latitude']用于定位注释的列中存储的内容。您需要确保它们在正确的投影中,因为坐标需要反映绘图上使用的实际单位。

重投影后,获取新坐标并使用它们。

sample_gdf["x"] = sample_gdf.centroid.x
sample_gdf["y"] = sample_gdf.centroid.y

sample_gdf.plot()

for idx, row in sample_gdf.iterrows():
     plt.annotate(text=row['country_name'], # e.g. this column contains the names of each countries
                  xy=(row['x'], row['y']), # e.g. these columns are showing the coordinates of middle points of each countries
                  horizontalalignment='center')
于 2021-08-11T11:48:32.340 回答