【问题标题】:How to access the geojson file correctly?如何正确访问geojson文件?
【发布时间】:2020-05-05 19:35:41
【问题描述】:

我想使用 folium 和 GeoJSON 文件在世界地图上映射数据。 因此我必须正确访问 GeoJSON 文件。但我还没弄清楚怎么做。

KeyError: "None of [Index(['STATE_CODE', 'STATE_NAME'], dtype='object', name='Province')] are in the [index]"

索引来自 data_AU_series (pd.Series)

STATE_NAME 在 geoJSON 文件中,必须被访问并充当系列的键才能获取日期。

geodata_australia 来自 GeoJSON 文件:

{'type': 'FeatureCollection',
 'features': [{'type': 'Feature',
   'id': 0,
   'properties': {'STATE_CODE': '1', 'STATE_NAME': 'New South Wales'},
   'geometry': {'type': 'MultiPolygon',
    'coordinates': [[[[159.10542, -31.563994],
       [159.09775, -31.564275],
       [159.099634, -31.573372],...

data_AU_series(我想在地图上显示的数据(pd.Series)):

Province
Victoria                       2020-03-24
...

我想将系列中的值分配给地理数据和颜色的代码行

folium.GeoJson(
    geodata_australia,
    name='data_AU',
    style_function=lambda feature: {
        'fillColor': colormap(data_AU_series[feature['properties']]),
        'color': 'black',
        'weight': 1,
        'dashArray': '5, 5',
        'fillOpacity': 0.9,
    }
).add_to(m)

【问题讨论】:

    标签: python pandas geojson folium


    【解决方案1】:

    它适用于第二个键 ['STATE_NAME']

    colormap(data_AU_series[feature['properties']['STATE_NAME']]
    

    【讨论】:

      猜你喜欢
      • 2019-11-25
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-29
      • 1970-01-01
      相关资源
      最近更新 更多