I have this code:
import pandas as pd
import numpy as np
from geopandas import GeoDataFrame
import geopandas
from shapely.geometry import LineString, Point
import matplotlib.pyplot as plt
import contextily
''' Do Something'''
df = start_stop_df.drop('track', axis=1)
crs = {'init': 'epsg:4326'}
gdf = GeoDataFrame(df, crs=crs, geometry=geometry)
ax = gdf.plot()
contextily.add_basemap(ax)
ax.set_axis_off()
plt.show()
Run Code Online (Sandbox Code Playgroud)
Basically, this generates a background map that is in Singapore. However, when I run it, I get the following error: HTTPError: Tile URL resulted in a 404 error. Double-check …
我试图通过 Contextily 将底图添加到我的绘图中,但在尝试查看绘图时收到此错误。
Traceback (most recent call last):
File "rasterio/_crs.pyx", line 322, in rasterio._crs._CRS.from_epsg
File "rasterio/_err.pyx", line 192, in rasterio._err.exc_wrap_int
rasterio._err.CPLE_AppDefinedError: PROJ: proj_create_from_database: /opt/anaconda3/share/proj/proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 196, in process
func(*args, **kwargs)
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/widgets.py", line 1051, in _clicked
self.set_active(closest)
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/widgets.py", line 1077, in set_active
func(self.labels[index].get_text())
File "vis.py", line 1109, in draw_basemap
ctx.add_basemap(ax, crs=properties_geo.crs.to_string())
File …
Run Code Online (Sandbox Code Playgroud) 这个问题与使用 geopandas 和 matplotlib 绘制地图的答案有关。
主要的一点是,在 Windows 下安装(空间)库如Proj.4或Contextily可能是一项令人困惑的任务,因此大多数时候我们建议直接
使用OSGeo4W软件分发。
这种提醒的例子在这里。
相反,其他操作系统的任务相当容易。
主要思想是为有疑问的用户提供“精简”的安装方法。
我正在尝试将上下文底图绘制到我的 cartopy GeoAxes 之一上,但问题是底部的源页脚很大。有什么办法可以减小它的尺寸吗?谢谢!
这就是我简单地将其添加到我的轴中的方法:
import contextily as ctx
ax2=fig.add_subplot(gs01[:,0], projection=ccrs.PlateCarree())
ctx.add_basemap(ax2)
Run Code Online (Sandbox Code Playgroud)
我想在房产地址的标绘点后面绘制墨尔本的背景地图。
我使用了以下代码:
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 上也提出了类似的问题,但我无法将它们改造成我的问题。
我觉得我也为这个简单的任务导入了很多库,所以如果您有任何调整它的建议,我们也将不胜感激。