Python的Folium搜索插件

2024-04-25 20:24:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我用小叶。搜索()英寸python。但是,当我运行代码。怎么写解决这个问题的方法是什么?你知道吗

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.

Tags: topyimportaddjsonsearchdatatype
1条回答
网友
1楼 · 发布于 2024-04-25 20:24:03

我修复了这个错误,如下所示。你知道吗

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)

相关问题 更多 >