我尝试使用 Contextily 将底图添加到使用 GeoPandas 创建的地图中,但出现以下错误:
HTTPSConnectionPool(host='a.tile.openstreetmap.org', port=443): Max retries exceeded with url: /14/8452/7869.png (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
File "D:\generate_udf_maps.py", line 42, in generate_map
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik)
File "D:\generate_udf_maps.py", line 60, in <module>
generate_map(gdb_path, None, operations_file)
这是我的代码:
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
from shapely.geometry import Point, Polygon
import contextily as ctx
fig, ax = plt.subplots()
p1 = Point(640864.516, 784724.566)
p2 = Point(638594.804, 788492.544)
p3 = Point(644076.197, 788141.637)
p4 = Point(641089.953, 789539.343)
df = gpd.GeoDataFrame(geometry=[p1, p2, p3, p4])
df.plot(ax=ax)
ctx.add_basemap(ax, source=ctx.providers.OpenStreetMap.Mapnik) # Error happens here. If this line is not present I get a map with just the points.
plt.show()
我尝试了不同的地图提供商,但没有成功,并看到几个链接提供了与参考包相关的建议,我不确定这些链接是否适用于此处。预先感谢!
我找到了一个不太理想且不安全的临时解决方案,即通过在 C:\path_to_python_librarie 中设置
verify=False
来关闭 SSL 验证