叶子,plugins.TimestampedGeoJson,"Time not avaliable"
folium, plugins.TimestampedGeoJson, "Time not avaliable"
我想使用 plugins.TimestampedGeoJson.
绘制带时间戳的 GeoJSON
但是我在 folium 地图中的时间栏显示 "Time not available" 并且不起作用。
我找不到我的变量的哪一部分是错误的。
我使用的变量如下
如何让我的时间栏发挥作用?
points
[{'coordinates': [[37.4725028, 126.4313798],
[37.478525899999994, 126.6663152],
[37.561648999999996, 126.79433700000001]],
'popup': 1,
'time': '2020-01-19'},
{'coordinates': [[37.679657, 126.763737],
[37.4725028, 126.4313798],
[37.0796065, 127.0561043],
[37.0220402, 126.8134938],
[37.557176, 127.00768799999999]],
'popup': 1,
'time': '2020-01-20'},
{'coordinates': [[37.673517, 126.7553],
[37.670964, 126.761146],
[37.679657, 126.763737],
[37.520878, 127.02286299999999],
[37.524661, 127.028002],
[37.503137, 127.04909099999999],
[37.0520115, 126.91724440000002],
[37.463504, 126.65055600000001]],
'popup': 1,
'time': '2020-01-21'},
{'coordinates': [[37.560362700000006, 126.776299],
[37.567226899999994, 126.75337079999998],
[37.549605299999996, 126.86608829999999],
[37.567226899999994, 126.75337079999998],
[37.5672454, 127.00347020000001],
[37.524661, 127.028002],
[37.530772, 127.031924],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.523118200000006, 127.03281489999999],
[37.555136, 126.97048899999999]],
'popup': 1,
'time': '2020-01-22'},
{'coordinates': [[37.524703, 127.015943],
[37.500735, 127.036373],
[37.494607, 127.06329199999999],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.483702, 126.77811299999999]],
'popup': 1,
'time': '2020-01-23'},
{'coordinates': [[37.524661, 127.028002],
[37.658513, 126.832025],
[37.674671999999994, 126.776701],
[37.678166, 126.812165],
[37.0220402, 126.8134938],
[37.5616902, 126.97456809999998],
[37.266184, 126.999655],
[37.263417, 127.028654],
[37.361576, 126.935174]],
'popup': 1,
'time': '2020-01-24'},
{'coordinates': [[37.679657, 126.763737],
[37.642371999999995, 126.831253],
[37.0520115, 126.91724440000002],
[37.5616902, 126.97456809999998],
[37.483538, 127.032643],
[35.967625, 126.73678899999999],
[35.967625, 126.73678899999999],
[37.359123, 126.93095500000001],
[37.359123, 126.93095500000001]],
'popup': 1,
'time': '2020-01-25'},
{'coordinates': [[37.35132410000001, 127.12124329999999],
[37.5917891, 127.0164831],
[37.564001, 127.02953500000001],
[37.5903342, 127.01303200000001],
[37.590492100000006, 127.0119803],
[37.590611700000004, 126.9441293],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.9867, 126.70813000000001]],
'popup': 1,
'time': '2020-01-26'},
{'coordinates': [[37.5920615, 127.01670959999998],
[37.590611700000004, 126.9441293],
[37.5921286, 126.98387890000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.968089, 126.716128],
[37.557176, 127.00768799999999]],
'popup': 1,
'time': '2020-01-27'},
{'coordinates': [[37.5916736, 127.016226],
[37.5854777, 127.08637140000002],
[37.5982157, 127.0797739],
[37.5236782, 127.04434930000001],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.954685, 126.71244399999999],
[37.483702, 126.77811299999999]],
'popup': 1,
'time': '2020-01-28'},
{'coordinates': [[37.594741799999994, 127.0728561],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.976046000000004, 126.705522],
[35.982751, 126.734844]],
'popup': 1,
'time': '2020-01-29'},
{'coordinates': [[37.5647424, 126.99496140000001],
[37.579669, 126.99897],
[35.964349, 126.959676],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.498415, 126.762864]],
'popup': 1,
'time': '2020-01-30'},
{'coordinates': [[35.964349, 126.959676],
[37.5673125, 126.9706395],
[37.579669, 126.99897],
[37.579669, 126.99897],
[37.561648, 126.7855822],
[37.481458, 126.7804963]],
'popup': 1,
'time': '2020-01-31'},
{'coordinates': [[37.351375, 127.123411],
[37.481458, 126.7804963],
[37.304349, 127.0079881],
[37.391714799999995, 127.147098]],
'popup': 1,
'time': '2020-02-01'},
{'coordinates': [[37.5672412, 127.00347020000001], [37.351375, 127.123411]],
'popup': 1,
'time': '2020-02-02'}]
下面是我的特征变量。
features
[{'geometry': {'coordinates': [[37.4725028, 126.4313798],
[37.478525899999994, 126.6663152],
[37.561648999999996, 126.79433700000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-19'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.679657, 126.763737],
[37.4725028, 126.4313798],
[37.0796065, 127.0561043],
[37.0220402, 126.8134938],
[37.557176, 127.00768799999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-20'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.673517, 126.7553],
[37.670964, 126.761146],
[37.679657, 126.763737],
[37.520878, 127.02286299999999],
[37.524661, 127.028002],
[37.503137, 127.04909099999999],
[37.0520115, 126.91724440000002],
[37.463504, 126.65055600000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-21'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.560362700000006, 126.776299],
[37.567226899999994, 126.75337079999998],
[37.549605299999996, 126.86608829999999],
[37.567226899999994, 126.75337079999998],
[37.5672454, 127.00347020000001],
[37.524661, 127.028002],
[37.530772, 127.031924],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.523118200000006, 127.03281489999999],
[37.555136, 126.97048899999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-22'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.524703, 127.015943],
[37.500735, 127.036373],
[37.494607, 127.06329199999999],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.483702, 126.77811299999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-23'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.524661, 127.028002],
[37.658513, 126.832025],
[37.674671999999994, 126.776701],
[37.678166, 126.812165],
[37.0220402, 126.8134938],
[37.5616902, 126.97456809999998],
[37.266184, 126.999655],
[37.263417, 127.028654],
[37.361576, 126.935174]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-24'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.679657, 126.763737],
[37.642371999999995, 126.831253],
[37.0520115, 126.91724440000002],
[37.5616902, 126.97456809999998],
[37.483538, 127.032643],
[35.967625, 126.73678899999999],
[35.967625, 126.73678899999999],
[37.359123, 126.93095500000001],
[37.359123, 126.93095500000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-25'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.35132410000001, 127.12124329999999],
[37.5917891, 127.0164831],
[37.564001, 127.02953500000001],
[37.5903342, 127.01303200000001],
[37.590492100000006, 127.0119803],
[37.590611700000004, 126.9441293],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.9867, 126.70813000000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-26'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5920615, 127.01670959999998],
[37.590611700000004, 126.9441293],
[37.5921286, 126.98387890000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.968089, 126.716128],
[37.557176, 127.00768799999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-27'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5916736, 127.016226],
[37.5854777, 127.08637140000002],
[37.5982157, 127.0797739],
[37.5236782, 127.04434930000001],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.954685, 126.71244399999999],
[37.483702, 126.77811299999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-28'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.594741799999994, 127.0728561],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.976046000000004, 126.705522],
[35.982751, 126.734844]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-29'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5647424, 126.99496140000001],
[37.579669, 126.99897],
[35.964349, 126.959676],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.498415, 126.762864]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-30'},
'type': 'Feature'},
{'geometry': {'coordinates': [[35.964349, 126.959676],
[37.5673125, 126.9706395],
[37.579669, 126.99897],
[37.579669, 126.99897],
[37.561648, 126.7855822],
[37.481458, 126.7804963]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-31'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.351375, 127.123411],
[37.481458, 126.7804963],
[37.304349, 127.0079881],
[37.391714799999995, 127.147098]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-02-01'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5672412, 127.00347020000001],
[37.351375, 127.123411]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-02-02'},
'type': 'Feature'}]
我试着画了folium图
但是我在地图左下角的时间不起作用。
m = folium.Map([37.5650172,126.8494648], zoom_start = 10)
plugins.TimestampedGeoJson( { 'type': 'FeatureCollection', 'features': features },
period='P1D',
add_last_point=True,
auto_play=False,
loop=False,
max_speed=1,
loop_button=True,
date_options='YYYY-MM-DD',
time_slider_drag_update=True,
duration='P1D' ).add_to(m)
m
我遇到了同样的问题,在我的案例中解决了这个问题:
您描述的问题的发生可能是因为您的子字典关键字 "time"
不包含与每个 "feature"
中使用的 "coordinates"
长度相等的列表。
此外,我建议您将 "time"
重命名为 "times"
,您将在下面提到的 GitHub
上的原始 post 中看到。
此后,我根据您提供的功能列表做了一个最小的例子:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# * Example of correct feature list with length 1 * #
## Coordinates
coordinate_list1 = [[37.4725028, 126.4313798],
[37.478525899999994, 126.6663152],
[37.561648999999996, 126.79433700000001]]
## Times
# NOTE: if the same timestamp applies to all coordinates, create list with repeating timestamp of same length as coordinate list
times_list1 = ['2020-01-19'] * len(coordinate_list1)
## Features
# NOTE: fill in the coordinates and times, and name the associated time-keyword "times"
features = [{
'geometry': {
'coordinates': coordinate_list1,
'type': 'Point'
},
'properties': {
'icon': 'marker',
'iconstyle': {
'iconSize': [20, 20],
'iconUrl':
'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'
},
'id': 'house',
'popup': 1,
'times': times_list1
},
'type': 'Feature'
}]
修复此问题,它应该可以正常工作。
解决方案引用自this discussion:
[...] the plugin requires each feature
to have a property "times"
, which
should be a list containing either unix epoch timestamps in ms or ISO
format timestamps. See
https://python-visualization.github.io/folium/plugins.html#folium.plugins.TimestampedGeoJson
df = pd.read_excel("file.xlsx")
IconUrl = "https://cdn.icon-icons.com/icons2/1465/PNG/128/604bullettrain_100995.png"
m = folium.Map([37.5650172,126.8494648], zoom_start = 10)
# step 1
TempFeature = []
# do the following command for each marker
temp_df = df.query(f"Marker_id == {1}")
TempFeature.append({ 'type': 'Feature',
'geometry': { 'type': 'LineString',
# example coordinates
# [
# (-3.049648, 53.4372116),
# (-3.04967139134615, 53.4372056616587),
# (-3.04972986971154, 53.4371908158053),
# .
# .
# .
# (-3.04972986971154, 53.4371908158053),
# ]
'coordinates': list(zip(temp_df['Longitude'],temp_df['Latitude']))
},
'properties':{
'icon': 'marker',
'iconstyle': {'iconUrl': IconUrl, 'iconSize': [20, 20], },
# time must be like the following format : '2018-12-01T05:53:00'
'times': temp_df['Timetable'] ,
'popup': '<html> <head></head> <body> comments </body> </html>'
}})
# step 2
TimestampedGeoJson({
'type': 'FeatureCollection',
'features': TempFeature,
}
, period='P1D'
).add_to(m)
m
我想使用 plugins.TimestampedGeoJson.
绘制带时间戳的 GeoJSON但是我在 folium 地图中的时间栏显示 "Time not available" 并且不起作用。
我找不到我的变量的哪一部分是错误的。
我使用的变量如下
如何让我的时间栏发挥作用?
points
[{'coordinates': [[37.4725028, 126.4313798],
[37.478525899999994, 126.6663152],
[37.561648999999996, 126.79433700000001]],
'popup': 1,
'time': '2020-01-19'},
{'coordinates': [[37.679657, 126.763737],
[37.4725028, 126.4313798],
[37.0796065, 127.0561043],
[37.0220402, 126.8134938],
[37.557176, 127.00768799999999]],
'popup': 1,
'time': '2020-01-20'},
{'coordinates': [[37.673517, 126.7553],
[37.670964, 126.761146],
[37.679657, 126.763737],
[37.520878, 127.02286299999999],
[37.524661, 127.028002],
[37.503137, 127.04909099999999],
[37.0520115, 126.91724440000002],
[37.463504, 126.65055600000001]],
'popup': 1,
'time': '2020-01-21'},
{'coordinates': [[37.560362700000006, 126.776299],
[37.567226899999994, 126.75337079999998],
[37.549605299999996, 126.86608829999999],
[37.567226899999994, 126.75337079999998],
[37.5672454, 127.00347020000001],
[37.524661, 127.028002],
[37.530772, 127.031924],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.523118200000006, 127.03281489999999],
[37.555136, 126.97048899999999]],
'popup': 1,
'time': '2020-01-22'},
{'coordinates': [[37.524703, 127.015943],
[37.500735, 127.036373],
[37.494607, 127.06329199999999],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.483702, 126.77811299999999]],
'popup': 1,
'time': '2020-01-23'},
{'coordinates': [[37.524661, 127.028002],
[37.658513, 126.832025],
[37.674671999999994, 126.776701],
[37.678166, 126.812165],
[37.0220402, 126.8134938],
[37.5616902, 126.97456809999998],
[37.266184, 126.999655],
[37.263417, 127.028654],
[37.361576, 126.935174]],
'popup': 1,
'time': '2020-01-24'},
{'coordinates': [[37.679657, 126.763737],
[37.642371999999995, 126.831253],
[37.0520115, 126.91724440000002],
[37.5616902, 126.97456809999998],
[37.483538, 127.032643],
[35.967625, 126.73678899999999],
[35.967625, 126.73678899999999],
[37.359123, 126.93095500000001],
[37.359123, 126.93095500000001]],
'popup': 1,
'time': '2020-01-25'},
{'coordinates': [[37.35132410000001, 127.12124329999999],
[37.5917891, 127.0164831],
[37.564001, 127.02953500000001],
[37.5903342, 127.01303200000001],
[37.590492100000006, 127.0119803],
[37.590611700000004, 126.9441293],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.9867, 126.70813000000001]],
'popup': 1,
'time': '2020-01-26'},
{'coordinates': [[37.5920615, 127.01670959999998],
[37.590611700000004, 126.9441293],
[37.5921286, 126.98387890000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.968089, 126.716128],
[37.557176, 127.00768799999999]],
'popup': 1,
'time': '2020-01-27'},
{'coordinates': [[37.5916736, 127.016226],
[37.5854777, 127.08637140000002],
[37.5982157, 127.0797739],
[37.5236782, 127.04434930000001],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.954685, 126.71244399999999],
[37.483702, 126.77811299999999]],
'popup': 1,
'time': '2020-01-28'},
{'coordinates': [[37.594741799999994, 127.0728561],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.976046000000004, 126.705522],
[35.982751, 126.734844]],
'popup': 1,
'time': '2020-01-29'},
{'coordinates': [[37.5647424, 126.99496140000001],
[37.579669, 126.99897],
[35.964349, 126.959676],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.498415, 126.762864]],
'popup': 1,
'time': '2020-01-30'},
{'coordinates': [[35.964349, 126.959676],
[37.5673125, 126.9706395],
[37.579669, 126.99897],
[37.579669, 126.99897],
[37.561648, 126.7855822],
[37.481458, 126.7804963]],
'popup': 1,
'time': '2020-01-31'},
{'coordinates': [[37.351375, 127.123411],
[37.481458, 126.7804963],
[37.304349, 127.0079881],
[37.391714799999995, 127.147098]],
'popup': 1,
'time': '2020-02-01'},
{'coordinates': [[37.5672412, 127.00347020000001], [37.351375, 127.123411]],
'popup': 1,
'time': '2020-02-02'}]
下面是我的特征变量。
features
[{'geometry': {'coordinates': [[37.4725028, 126.4313798],
[37.478525899999994, 126.6663152],
[37.561648999999996, 126.79433700000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-19'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.679657, 126.763737],
[37.4725028, 126.4313798],
[37.0796065, 127.0561043],
[37.0220402, 126.8134938],
[37.557176, 127.00768799999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-20'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.673517, 126.7553],
[37.670964, 126.761146],
[37.679657, 126.763737],
[37.520878, 127.02286299999999],
[37.524661, 127.028002],
[37.503137, 127.04909099999999],
[37.0520115, 126.91724440000002],
[37.463504, 126.65055600000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-21'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.560362700000006, 126.776299],
[37.567226899999994, 126.75337079999998],
[37.549605299999996, 126.86608829999999],
[37.567226899999994, 126.75337079999998],
[37.5672454, 127.00347020000001],
[37.524661, 127.028002],
[37.530772, 127.031924],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.523118200000006, 127.03281489999999],
[37.555136, 126.97048899999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-22'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.524703, 127.015943],
[37.500735, 127.036373],
[37.494607, 127.06329199999999],
[37.503137, 127.04909099999999],
[37.0220402, 126.8134938],
[37.483702, 126.77811299999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-23'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.524661, 127.028002],
[37.658513, 126.832025],
[37.674671999999994, 126.776701],
[37.678166, 126.812165],
[37.0220402, 126.8134938],
[37.5616902, 126.97456809999998],
[37.266184, 126.999655],
[37.263417, 127.028654],
[37.361576, 126.935174]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-24'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.679657, 126.763737],
[37.642371999999995, 126.831253],
[37.0520115, 126.91724440000002],
[37.5616902, 126.97456809999998],
[37.483538, 127.032643],
[35.967625, 126.73678899999999],
[35.967625, 126.73678899999999],
[37.359123, 126.93095500000001],
[37.359123, 126.93095500000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-25'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.35132410000001, 127.12124329999999],
[37.5917891, 127.0164831],
[37.564001, 127.02953500000001],
[37.5903342, 127.01303200000001],
[37.590492100000006, 127.0119803],
[37.590611700000004, 126.9441293],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.9867, 126.70813000000001]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-26'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5920615, 127.01670959999998],
[37.590611700000004, 126.9441293],
[37.5921286, 126.98387890000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5863425, 126.99763390000001],
[37.5616902, 126.97456809999998],
[35.968089, 126.716128],
[37.557176, 127.00768799999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-27'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5916736, 127.016226],
[37.5854777, 127.08637140000002],
[37.5982157, 127.0797739],
[37.5236782, 127.04434930000001],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.954685, 126.71244399999999],
[37.483702, 126.77811299999999]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-28'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.594741799999994, 127.0728561],
[37.60656420000001, 127.09043],
[37.5616902, 126.97456809999998],
[35.976046000000004, 126.705522],
[35.982751, 126.734844]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-29'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5647424, 126.99496140000001],
[37.579669, 126.99897],
[35.964349, 126.959676],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.641158000000004, 126.791979],
[37.5863425, 126.99763390000001],
[37.498415, 126.762864]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-30'},
'type': 'Feature'},
{'geometry': {'coordinates': [[35.964349, 126.959676],
[37.5673125, 126.9706395],
[37.579669, 126.99897],
[37.579669, 126.99897],
[37.561648, 126.7855822],
[37.481458, 126.7804963]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-01-31'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.351375, 127.123411],
[37.481458, 126.7804963],
[37.304349, 127.0079881],
[37.391714799999995, 127.147098]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-02-01'},
'type': 'Feature'},
{'geometry': {'coordinates': [[37.5672412, 127.00347020000001],
[37.351375, 127.123411]],
'type': 'Point'},
'properties': {'icon': 'marker',
'iconstyle': {'iconSize': [20, 20],
'iconUrl': 'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'},
'id': 'house',
'popup': 1,
'time': '2020-02-02'},
'type': 'Feature'}]
我试着画了folium图
但是我在地图左下角的时间不起作用。
m = folium.Map([37.5650172,126.8494648], zoom_start = 10)
plugins.TimestampedGeoJson( { 'type': 'FeatureCollection', 'features': features },
period='P1D',
add_last_point=True,
auto_play=False,
loop=False,
max_speed=1,
loop_button=True,
date_options='YYYY-MM-DD',
time_slider_drag_update=True,
duration='P1D' ).add_to(m)
m
我遇到了同样的问题,在我的案例中解决了这个问题:
您描述的问题的发生可能是因为您的子字典关键字 "time"
不包含与每个 "feature"
中使用的 "coordinates"
长度相等的列表。
此外,我建议您将 "time"
重命名为 "times"
,您将在下面提到的 GitHub
上的原始 post 中看到。
此后,我根据您提供的功能列表做了一个最小的例子:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# * Example of correct feature list with length 1 * #
## Coordinates
coordinate_list1 = [[37.4725028, 126.4313798],
[37.478525899999994, 126.6663152],
[37.561648999999996, 126.79433700000001]]
## Times
# NOTE: if the same timestamp applies to all coordinates, create list with repeating timestamp of same length as coordinate list
times_list1 = ['2020-01-19'] * len(coordinate_list1)
## Features
# NOTE: fill in the coordinates and times, and name the associated time-keyword "times"
features = [{
'geometry': {
'coordinates': coordinate_list1,
'type': 'Point'
},
'properties': {
'icon': 'marker',
'iconstyle': {
'iconSize': [20, 20],
'iconUrl':
'http://downloadicons.net/sites/default/files/small-house-with-a-chimney-icon-70053.png'
},
'id': 'house',
'popup': 1,
'times': times_list1
},
'type': 'Feature'
}]
修复此问题,它应该可以正常工作。
解决方案引用自this discussion:
[...] the plugin requires each
feature
to have a property"times"
, which should be a list containing either unix epoch timestamps in ms or ISO format timestamps. See https://python-visualization.github.io/folium/plugins.html#folium.plugins.TimestampedGeoJson
df = pd.read_excel("file.xlsx")
IconUrl = "https://cdn.icon-icons.com/icons2/1465/PNG/128/604bullettrain_100995.png"
m = folium.Map([37.5650172,126.8494648], zoom_start = 10)
# step 1
TempFeature = []
# do the following command for each marker
temp_df = df.query(f"Marker_id == {1}")
TempFeature.append({ 'type': 'Feature',
'geometry': { 'type': 'LineString',
# example coordinates
# [
# (-3.049648, 53.4372116),
# (-3.04967139134615, 53.4372056616587),
# (-3.04972986971154, 53.4371908158053),
# .
# .
# .
# (-3.04972986971154, 53.4371908158053),
# ]
'coordinates': list(zip(temp_df['Longitude'],temp_df['Latitude']))
},
'properties':{
'icon': 'marker',
'iconstyle': {'iconUrl': IconUrl, 'iconSize': [20, 20], },
# time must be like the following format : '2018-12-01T05:53:00'
'times': temp_df['Timetable'] ,
'popup': '<html> <head></head> <body> comments </body> </html>'
}})
# step 2
TimestampedGeoJson({
'type': 'FeatureCollection',
'features': TempFeature,
}
, period='P1D'
).add_to(m)
m