【发布时间】:2020-11-30 10:19:41
【问题描述】:
我想在物业地址的标绘点后面绘制墨尔本的背景地图。
我使用了以下代码:
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()
在 contextily.add_basemap(ax) 行,我收到以下 UserWarning。
contextily\tile.py:632: UserWarning: 推断的缩放级别 30 是 对当前磁贴提供者无效(有效缩放:0 - 18)。
我阅读了Contextily docs,但它们并没有解决我的问题。
将行更改为 contextily.add_basemap(ax, zoom=5) 会删除 UserWarning 但仍然没有出现背景地图。 在 SO 上也有人问过类似的问题,但我无法将它们改造成我的问题。
我觉得我也为这个简单的任务导入了很多库,所以如果您有任何微调它的建议,也将不胜感激。
【问题讨论】:
-
底图和数据必须在同一个投影上,试试
contextily.add_basemap(ax, crs=properties_geo.crs.to_string()
标签: python geospatial geopandas contextily