python - Python:加载设施名称时地图未加载
问题描述
我正在制作一张交互式地图,以绘制全国各地的各种医疗设施。我在网上找到了一个合适的形状/数据库文件(连同 GeoJson 和一个 CSV),可以用于这个项目。
我设法让位置显示在地图上,但设施名称没有出现。
根据我打印的 sf.fields ,名称在字段 8 中,我可以将这些名称打印为record.record[8]
,它们将出现在控制台中。
但是,当我将弹出窗口设置为popup=record.record[8].title()
地图时将不再加载。它在控制台中编译并且不返回错误。我在这里想念什么?
这是我到目前为止所得到的:
import folium
import pandas
import shapefile
import csv
with open('VA_Facilities.csv', 'r') as data_file:
csv_data = csv.reader(data_file)
myshp = open('data/va_facilities_1.shp', "rb")
mydbf = open('data/va_facilities_1.dbf', "rb")
sf = shapefile.Reader(shp=myshp, dbf=mydbf)
records = sf.shapeRecords()
# Prints the number of records, type of the shape, and fields for the
dataset
print (len(records))
print (sf.shapes()[0].shapeType)
print (sf.fields)
# Prints the first three records for verification reasons
for record in records[:3]:
print (record.record[0], record.shape.points[0], record.record[8])
map=folium.Map(location=[47.1164, -101.2996],zoom_start=4,tiles='CartoDB
positron')
for record in records:
lat, lng = (record.shape.points[0][1],record.shape.points[0][0])
folium.RegularPolygonMarker(
[lat, lng],
popup=record.record[8].title(),
fill_color='#EE1C25',
number_of_sides=5,
radius=5
).add_to(map)
map.save(outfile='Healthcare_Facilities.html')
将值更改record.record[0]
回零将照常加载地图,但没有名称。
解决方案
弄清楚了。最新版本的 Folium 依赖于原始 HTML 输入,因此parse_html=True
必须添加到popup=
字段中才能获得所需的结果。
谢谢您的帮助!
推荐阅读
- linux - 用for循环将变量连接成用逗号分隔的单个变量
- winapi - SendInput 在 UAC 提示符下失败
- julia - julialang:可以(应该)在编译时捕获这种类型的错误吗?
- python - 如果列表中包含最后一个数字,如何删除列表中的最后一个数字
- angular - matTooltip 和 [matTooltip] 有什么区别?
- php - 使用php计算给定日期的每个下个月
- android - 如何在 Android 上使用 ScreenshotClient 获得快速像素颜色?
- php - 添加帖子元并在产品页面上查看更改时出现问题
- flutter - 未来的建设者给出了失败的断言错误
- python - 迭代元组列表并仅解包第一个元素