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=字段中才能获得所需的结果。

感谢您的帮助!

最新更新