【问题标题】:Folium error 'Map' object has no attribute 'geo_json'叶错误“地图”对象没有属性“geo_json”
【发布时间】:2019-07-18 05:15:56
【问题描述】:

使用 GeoJson 时出现 AttributeError。我已阅读文档,但找不到任何线索。

import folium
from folium import GeoJson 


LA_COORDINATES = (34.0522, -118.2437)
zip_geo = r'zip-code-tabulation-areas-2012.geojson'

df_zip.to_json('ticket_agg.json')
df_zip.columns = ['Zipcode','Ticket_Count']

# creation of the choropleth
map1 = folium.Map(location=LA_COORDINATES, zoom_start=12)
map1.GeoJson(geo_path = zip_geo, 
              data_out = 'ticket_agg.json', 
              data = df_zip,
              columns = ['Zipcode','Ticket_Count'],
              key_on = 'feature.properties.external_id',
              fill_color = 'YlOrRd', 
              fill_opacity = 0.7, 
              line_opacity = 0.2,
              legend_name = 'Tickets per zip')

display(map1)

错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-61-f15e83f4678b> in <module>
     19 # creation of the choropleth
     20 map1 = folium.Map(location=LA_COORDINATES, zoom_start=12)
---> 21 map1.GeoJson(geo_path = zip_geo, 
     22               data_out = 'ticket_agg.json',
     23               data = df_zip,

AttributeError: 'Map' object has no attribute 'GeoJson'

这是我正在使用的 geo_json 文件的链接:http://s3-us-west-2.amazonaws.com/boundaries.latimes.com/archive/1.0/boundary-set/zip-code-tabulation-areas-2012.geojson

任何建议将不胜感激!

【问题讨论】:

    标签: python geojson folium


    【解决方案1】:

    显然是错误

    AttributeError: 'Map' 对象没有属性 'GeoJson'

    由于GeoJson 不是Map 类的方法而发生。

    我建议升级到 folium 的最新版本,其中choropleth maps 可以这样创建:

    folium.Choropleth(
        geo_path = zip_geo, 
        data = df_zip,
        columns = ['Zipcode','Ticket_Count'],
        key_on = 'feature.properties.external_id',
        fill_color = 'YlOrRd', 
        fill_opacity = 0.7, 
        line_opacity = 0.2,
        legend_name = 'Tickets per zip'
    ).add_to(map1)
    

    列出更改

    【讨论】:

      猜你喜欢
      • 2016-01-16
      • 1970-01-01
      • 2018-05-21
      • 2014-05-14
      • 2016-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      相关资源
      最近更新 更多