如何在地质层覆盖后盖上纵横比?

发布于 2025-01-26 13:57:56 字数 1361 浏览 2 评论 0 原文

我正在尝试将一些城市覆盖在地图之上。


import pandas as pd
import geopandas as gdp
import matplotlib.pyplot as plt
from shapely.geometry import box

destinations = ["Oslo", "Bergen", "Trondheim", "Tromsø", "Nordkapp", "Bodø", "Lofoten"]
world = gdp.read_file(gdp.datasets.get_path('naturalearth_lowres'))
norway = world[world.name=="Norway"]
norway =gdp.clip(norway, box(0, 0, 60,75)) # removing Svalbard
cities = world = gdp.read_file(gdp.datasets.get_path('naturalearth_cities'))
df = pd.read_csv("norway_cities.csv", sep=";")
norway_cities = gdp.GeoDataFrame(df, geometry=gdp.points_from_xy(df.lng, df.lat))

ax = norway.plot(color='white', edgecolor='black')
ax = cities[cities.name=="Stockholm"].plot(ax=ax, color='red')
ax = norway_cities[norway_cities.city.isin(destinations)].plot(ax=ax, color='blue')
plt.show()

当我绘制斯德哥尔摩坐标时,比例会受益:

”

当我绘制其余内容时,事情会扭曲:

来自不同的来源

数据 =“ https://i.sstatic.net/7ea4i.png” rel =“ nofollow noreferrer”>

更改图的大小不会影响结果,我如何保持第一张图片的相同纵横比?

I'm trying to overlay some cities on top of a map.


import pandas as pd
import geopandas as gdp
import matplotlib.pyplot as plt
from shapely.geometry import box

destinations = ["Oslo", "Bergen", "Trondheim", "Tromsø", "Nordkapp", "Bodø", "Lofoten"]
world = gdp.read_file(gdp.datasets.get_path('naturalearth_lowres'))
norway = world[world.name=="Norway"]
norway =gdp.clip(norway, box(0, 0, 60,75)) # removing Svalbard
cities = world = gdp.read_file(gdp.datasets.get_path('naturalearth_cities'))
df = pd.read_csv("norway_cities.csv", sep=";")
norway_cities = gdp.GeoDataFrame(df, geometry=gdp.points_from_xy(df.lng, df.lat))

ax = norway.plot(color='white', edgecolor='black')
ax = cities[cities.name=="Stockholm"].plot(ax=ax, color='red')
ax = norway_cities[norway_cities.city.isin(destinations)].plot(ax=ax, color='blue')
plt.show()

Proportions are mantained when I plot Stockholm coordinates:

Stockholm overlay

Things get distorted when I plot the rest:

enter image description here

Data are coming from different sources but the scale seems to be the same:

enter image description here

Changing the figure size does not affect the results, how do I keep the same aspect ratio of the first picture?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

总攻大人 2025-02-02 13:57:56

构建 norway_cities 时,您尚未定义CRS。

norway_cities = gdp.GeoDataFrame(
    df, geometry=gdp.points_from_xy(df.lng, df.lat), crs="epsg:4386"
)

完整代码

  • 从网页获取城市,因为我无法访问您的csv
import pandas as pd
import geopandas as gdp
import matplotlib.pyplot as plt
from shapely.geometry import box
import requests, io

destinations = ["Oslo", "Bergen", "Trondheim", "Tromsø", "Nordkapp", "Bodø", "Lofoten"]
world = gdp.read_file(gdp.datasets.get_path("naturalearth_lowres"))
norway = world[world.name == "Norway"]
norway = gdp.clip(norway, box(0, 0, 60, 75))  # removing Svalbard
cities = world = gdp.read_file(gdp.datasets.get_path("naturalearth_cities"))
# df = pd.read_csv("norway_cities.csv", sep=";")
df = pd.read_csv(
    io.StringIO(
        requests.get("https://simplemaps.com/static/data/country-cities/no/no.csv").text
    )
)
norway_cities = gdp.GeoDataFrame(
    df, geometry=gdp.points_from_xy(df.lng, df.lat), crs="epsg:4386"
)

ax = norway.plot(color="white", edgecolor="black")
ax = cities[cities.name == "Stockholm"].plot(ax=ax, color="red")
ax = norway_cities[norway_cities.city.isin(destinations)].plot(ax=ax, color="blue")
plt.show()

”在此处输入图像描述”

When constructing norway_cities you have not defined the CRS.

norway_cities = gdp.GeoDataFrame(
    df, geometry=gdp.points_from_xy(df.lng, df.lat), crs="epsg:4386"
)

full code

  • get cities from a web page as I do not have access to your CSV
import pandas as pd
import geopandas as gdp
import matplotlib.pyplot as plt
from shapely.geometry import box
import requests, io

destinations = ["Oslo", "Bergen", "Trondheim", "Tromsø", "Nordkapp", "Bodø", "Lofoten"]
world = gdp.read_file(gdp.datasets.get_path("naturalearth_lowres"))
norway = world[world.name == "Norway"]
norway = gdp.clip(norway, box(0, 0, 60, 75))  # removing Svalbard
cities = world = gdp.read_file(gdp.datasets.get_path("naturalearth_cities"))
# df = pd.read_csv("norway_cities.csv", sep=";")
df = pd.read_csv(
    io.StringIO(
        requests.get("https://simplemaps.com/static/data/country-cities/no/no.csv").text
    )
)
norway_cities = gdp.GeoDataFrame(
    df, geometry=gdp.points_from_xy(df.lng, df.lat), crs="epsg:4386"
)

ax = norway.plot(color="white", edgecolor="black")
ax = cities[cities.name == "Stockholm"].plot(ax=ax, color="red")
ax = norway_cities[norway_cities.city.isin(destinations)].plot(ax=ax, color="blue")
plt.show()

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文