我在python中使用folium.Search()。但是,代码在运行代码时返回错误。如何解决此问题?
import folium
from folium import plugins
import json
m = folium.Map(location=[39.92370048 , 32.85271525],zoom_start=12)
with open('3596566.json') as f:
data = json.load(f)
plugins.Search(data,position='topright',
search_zoom=20,
search_label='ParselNo',
geom_type="Polygon").add_to(m)
m.save('map.html')
错误是:
Traceback (most recent call last):
File "C:/Users/HP/proje/ödev2.py", line 17, in <module>
geom_type="Polygon").add_to(m)
File "C:\Python36\lib\site-packages\folium\plugins\search.py", line 100, in __init__
), 'Search can only index FeatureGroup, ' \
AssertionError: Search can only index FeatureGroup, MarkerCluster, GeoJson, and TopoJson layers at this time.
答案 0 :(得分:0)
我已按如下修复此错误。我将GeoJson文件传输到一个变量。
points ={
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
32.73684,
39.85925
],
[
32.73575,
39.85949
],
[
32.73573,
39.85952
],
[
32.73574,
39.85954
],
[
32.73574,
39.85955
],
[
32.73576,
39.85969
],
[
32.73576,
39.85984
],
[
32.73582,
39.8599
],
[
32.73695,
39.86009
],
[
32.73701,
39.86006
],
[
32.73701,
39.85968
],
[
32.73701,
39.85966
],
[
32.7369,
39.85928
],
[
32.73684,
39.85925
]
]
]
},
"properties": {
"ParselNo": 1,
"Alan": "7,384.59",
"Mevkii": "",
"Nitelik": "Arsa - sağlık alanı",
"Ada": 29685,
"Il": "Ankara",
"Ilce": "Çankaya",
"Pafta": "",
"Mahalle": "Lodumu (me)"
}
}
]}
geojson_obj = folium.GeoJson(points).add_to(m)
plugins.Search(geojson_obj,position='topleft',
search_zoom=17,
search_label='ParselNo',
geom_type='Polygon').add_to(m)