如何为 folium 创建 GeoJson Python

how can I create GeoJson for folium Python

任何人都可以帮助我解决以下问题 GeoJSON,我正在尝试 folium Python Library,尝试绘制所有 **LineStrings**,但我希望通过 id_ 使用 单独的颜色 ,所以我在我的 geoJson 中提供了 ids 选项,我想 fillcolor 使用 id 选项这个 id 有多个坐标点,并且有超过 81 个唯一的 ids ,这使得多个linestring,我想分开那些linestrings with colors

我的第一个问题是:

  1. 有没有可能做我想用 folium 做的事情 Python
  2. 如果是,请帮助我的 GeoJson 文件更正它

这张图片是我想要做的:

cords = list(zip(filteredData.lat.tolist(), filteredData.lon.tolist()))
id_= list (zip(filteredData.id.tolist())) 
subVoyage

line = {
    'type': 'Feature',
    'geometry': {
        'type': 'LineString',
        'coordinates': cords,
        'ids': id_
    },
    'properties':{
        "color": 'black',
        "stroke": "red",
        "stroke-opacity": 0.4,
        "stroke-width": 5,
        "fillcolor" : id_,

    }
}

m1 = folium.Map(location=[36.862317, -76.3151], zoom_start=6)

folium.GeoJson(data, style_function=lambda x: {
        'color' : x['properties']['color'],
        'weight' : x['properties']['stroke-width'],
        'opacity': 1,
        'fillColor' : x['properties']['fillcolor'],
        }).add_to(m1)
m1

这是可能的,因为我已经在笔记本中为您的案例做了一个演示(见下面的代码)。您的问题似乎与您的 GeoJSON 结构有关。

import folium

lines = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"color": "#0000ff", "stroke-width": 1},"geometry":{"type":"LineString","coordinates":[[-1.64794921875,46.46813299215554],[-0.94482421875,47.724544549099676],[-0.263671875,47.97521412341618]]}},{"type":"Feature","properties":{"color": "#00ff00", "stroke-width": 1},"geometry":{"type":"LineString","coordinates":[[-0.263671875,47.97521412341618],[1.58203125,48.67645370777654],[1.8896484375,48.32703913063476],[2.3291015625,48.37084770238366]]}},{"type":"Feature","properties":{"color": "#ff0000", "stroke-width": 1},"geometry":{"type":"LineString","coordinates":[[2.3291015625,48.37084770238366],[2.548828125,48.60385760823255],[3.01025390625,48.66194284607006],[3.251953125,48.42920055556841],[3.5815429687499996,48.531157010976706],[3.779296875,48.32703913063476]]}}]}


m1 = folium.Map(location=[45, 1], zoom_start=6)

style_function = lambda x: {
    'color' : x['properties']['color'],
    'weight' : x['properties']['stroke-width']
}

folium.GeoJson(lines, style_function=style_function).add_to(m1)

m1

您可以看到图示的结果(由于我使用了 GeoJSON,以法国为中心)