我想在房产地址的标绘点后面绘制墨尔本的背景地图。
我使用了以下代码:
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.add_basemap(ax, Zoom=5) 会删除 UserWarning,但仍然不会出现背景地图。
类似的问题也被问到了,但我无法将它们改造成我的问题。
我觉得我也为这个简单的任务导入了很多库,所以如果您有任何调整它的建议,我们也将不胜感激。
我通过从 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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)