上下文 add_basemap 推断的缩放级别无效,更改缩放参数不能解决问题

Rya*_*ard 1 python geospatial geopandas contextily

我想在房产地址的标绘点后面绘制墨尔本的背景地图。

我使用了以下代码:

import pandas as pd
import geopandas as gpd
from shapely.geometry import shape
import matplotlib.pyplot as plt
import contextily

MELB_PROPERTY_DATA = "https://data.melbourne.vic.gov.au/resource/imwx-szwr.json"

properties = pd.read_json(MELB_PROPERTY_DATA)
properties['the_geom'] = properties['the_geom'].apply(shape)
properties_geo = gpd.GeoDataFrame(properties).set_geometry('the_geom')

ax = properties_geo.plot(markersize=1)
contextily.add_basemap(ax)
plt.show()
Run Code Online (Sandbox Code Playgroud)

在 contextily.add_basemap(ax) 行,我收到以下 UserWarning。

contextily\tile.py:632: UserWarning: 推断的缩放级别 30 对于当前图块提供程序无效(有效缩放:0 - 18)。

我阅读了Contextily 文档,但它们没有解决我的问题。

将行更改为 contextily.add_basemap(ax, Zoom=5) 会删除 UserWarning,但仍然不会出现背景地图。SO 上也提出了类似的问题,但我无法将它们改造成我的问题。

我觉得我也为这个简单的任务导入了很多库,所以如果您有任何调整它的建议,我们也将不胜感激。

输出图表显示墨尔本地址标记,但没有上下文底图

Rya*_*ard 5

我通过从 swatchai 的评论中意识到坐标参考系统(CRS)从未被定义来解决了这个问题。

请参阅下面的最终代码,其中注释掉了错误行以显示差异。

import pandas as pd
import geopandas as gpd
from shapely.geometry import shape
import matplotlib.pyplot as plt
import contextily

MELB_PROPERTY_DATA = "https://data.melbourne.vic.gov.au/resource/imwx-szwr.json"

properties = pd.read_json(MELB_PROPERTY_DATA)
properties['the_geom'] = properties['the_geom'].apply(shape)

# properties_geo = gpd.GeoDataFrame(properties).set_geometry('the_geom')
properties_geo = gpd.GeoDataFrame(properties, geometry='the_geom', crs='EPSG:4326')

ax = properties_geo.plot(markersize=1)

# contextily.add_basemap(ax)
contextily.add_basemap(ax, crs=properties_geo.crs.to_string())

plt.show()
Run Code Online (Sandbox Code Playgroud)