TimestampedGeoJson 持续时间参数导致多边形消失
TimestampedGeoJson duration parameter causes polygons to disappear
我在修改 Plugins example notebook 中第二个 TimestampedGeoJson 示例的代码片段时遇到问题。
持续时间参数描述为 "period of time which the features will be shown on the map after their time has passed. If None, all previous times will be shown."
以两个多边形为例
import folium
from folium.plugins import TimestampedGeoJson
m = folium.Map(location=[52.467697, -2.548828], zoom_start=6)
polygon_1 = {
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [((
(-2.548828, 51.467697),
(-0.087891, 51.536086),
(-1.516113, 53.800651),
(-6.240234, 53.383328),
),)],
},
'properties': {
'style': {
'color': 'blue',
},
'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00',
'2015-09-22T00:00:00', '2015-10-22T00:00:00',
'2015-11-22T00:00:00', '2015-12-22T00:00:00']
}
}
polygon_2 = {
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [((
(-3.548828, 50.467697),
(-1.087891, 50.536086),
(-2.516113, 52.800651),
(-7.240234, 52.383328),
),)],
},
'properties': {
'style': {
'color': 'yellow',
},
'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00']
}
}
TimestampedGeoJson(
{'type': 'FeatureCollection', 'features': [polygon_1, polygon_2]},
period='P1M',
duration='P1M',
auto_play=False,
loop=False,
loop_button=True,
date_options='YYYY/MM/DD',
).add_to(m)
m
第一个多边形从 7 月到 12 月处于活动状态,因此我希望它在所有时间段都被绘制;第二个多边形仅在 7 月和 8 月处于活动状态,因此应在其最后一个月后的一个月内绘制:即 7 月、8 月和 9 月。
相反,我看到的是两个多边形都在第一个周期绘制,在第二个周期消失,然后第二个多边形在 9 月绘制并在 10 月再次消失。要明确:
预计
+-----------+----------+----------+
| Month | Polygon1 | Polygon2 |
+-----------+----------+----------+
| July | X | X |
| August | X | X |
| September | X | X |
| October | X | |
| November | X | |
| December | X | |
+-----------+----------+----------+
观察到
+-----------+----------+----------+
| Month | Polygon1 | Polygon2 |
+-----------+----------+----------+
| July | X | X |
| August | | |
| September | X | |
| October | | |
| November | | |
| December | | |
+-----------+----------+----------+
这是持续时间参数中的错误,还是我遗漏了什么?
我使用的是没有广告拦截器的 folium 0.6.0 版。这在 Jupyter 和 html 导出中都会发生。 #894.
中引入了duration参数
由于在GitHub和was also answered there上也有人问过同样的问题,我将按顺序复制粘贴GitHub-用户"andy23512"的答案帮助那些在 GitHub.
上意外找不到答案的人
引用的答案如下:
"According to the corresponding document of leaflet.js, (
https://github.com/socib/Leaflet.TimeDimension/tree/520cb80f645112e242c5160cb44b7d5f2cae380d#ltimedimensionlayergeojson
)
coordTimes, times or linestringTimestamps: array of times that can be
associated with a geometry (datestrings or ms). In the case of a
LineString, it must have as many items as coordinates in the
LineString.
That means if one want to show the polygon at those 6 timestamps, the
length of geometry coordinate list should be 6, in order to specify
the polygon to be shown at corresponding timestamp.
In you case, you want to show the same polygon (polygon1) at those 6
timestamps. You can add * 6 after the coordinate list to make copies.
So the code that meet your expectation would be:
import folium
from folium.plugins import TimestampedGeoJson
m = folium.Map(location=[52.467697, -2.548828], zoom_start=6)
polygon_1 = {
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [((
(-2.548828, 51.467697),
(-0.087891, 51.536086),
(-1.516113, 53.800651),
(-6.240234, 53.383328),
),)] * 6, # duplicatation for matching 6 timestamps
},
'properties': {
'style': {
'color': 'blue',
},
'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00',
'2015-09-22T00:00:00', '2015-10-22T00:00:00',
'2015-11-22T00:00:00', '2015-12-22T00:00:00']
}
}
polygon_2 = {
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [((
(-3.548828, 50.467697),
(-1.087891, 50.536086),
(-2.516113, 52.800651),
(-7.240234, 52.383328),
),)] * 2, # duplicatation for matching 2 timestamps
},
'properties': {
'style': {
'color': 'yellow',
},
'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00']
}
}
TimestampedGeoJson(
{'type': 'FeatureCollection', 'features': [polygon_1, polygon_2]},
period='P1M',
duration='P1M',
auto_play=False,
loop=False,
loop_button=True,
date_options='YYYY/MM/DD',
).add_to(m)
m
Hope that helps."
我在修改 Plugins example notebook 中第二个 TimestampedGeoJson 示例的代码片段时遇到问题。
持续时间参数描述为 "period of time which the features will be shown on the map after their time has passed. If None, all previous times will be shown."
以两个多边形为例
import folium
from folium.plugins import TimestampedGeoJson
m = folium.Map(location=[52.467697, -2.548828], zoom_start=6)
polygon_1 = {
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [((
(-2.548828, 51.467697),
(-0.087891, 51.536086),
(-1.516113, 53.800651),
(-6.240234, 53.383328),
),)],
},
'properties': {
'style': {
'color': 'blue',
},
'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00',
'2015-09-22T00:00:00', '2015-10-22T00:00:00',
'2015-11-22T00:00:00', '2015-12-22T00:00:00']
}
}
polygon_2 = {
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [((
(-3.548828, 50.467697),
(-1.087891, 50.536086),
(-2.516113, 52.800651),
(-7.240234, 52.383328),
),)],
},
'properties': {
'style': {
'color': 'yellow',
},
'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00']
}
}
TimestampedGeoJson(
{'type': 'FeatureCollection', 'features': [polygon_1, polygon_2]},
period='P1M',
duration='P1M',
auto_play=False,
loop=False,
loop_button=True,
date_options='YYYY/MM/DD',
).add_to(m)
m
第一个多边形从 7 月到 12 月处于活动状态,因此我希望它在所有时间段都被绘制;第二个多边形仅在 7 月和 8 月处于活动状态,因此应在其最后一个月后的一个月内绘制:即 7 月、8 月和 9 月。
相反,我看到的是两个多边形都在第一个周期绘制,在第二个周期消失,然后第二个多边形在 9 月绘制并在 10 月再次消失。要明确:
预计
+-----------+----------+----------+
| Month | Polygon1 | Polygon2 |
+-----------+----------+----------+
| July | X | X |
| August | X | X |
| September | X | X |
| October | X | |
| November | X | |
| December | X | |
+-----------+----------+----------+
观察到
+-----------+----------+----------+
| Month | Polygon1 | Polygon2 |
+-----------+----------+----------+
| July | X | X |
| August | | |
| September | X | |
| October | | |
| November | | |
| December | | |
+-----------+----------+----------+
这是持续时间参数中的错误,还是我遗漏了什么?
我使用的是没有广告拦截器的 folium 0.6.0 版。这在 Jupyter 和 html 导出中都会发生。 #894.
中引入了duration参数由于在GitHub和was also answered there上也有人问过同样的问题,我将按顺序复制粘贴GitHub-用户"andy23512"的答案帮助那些在 GitHub.
上意外找不到答案的人引用的答案如下:
"According to the corresponding document of leaflet.js, ( https://github.com/socib/Leaflet.TimeDimension/tree/520cb80f645112e242c5160cb44b7d5f2cae380d#ltimedimensionlayergeojson )
coordTimes, times or linestringTimestamps: array of times that can be associated with a geometry (datestrings or ms). In the case of a LineString, it must have as many items as coordinates in the LineString.
That means if one want to show the polygon at those 6 timestamps, the length of geometry coordinate list should be 6, in order to specify the polygon to be shown at corresponding timestamp.
In you case, you want to show the same polygon (polygon1) at those 6 timestamps. You can add * 6 after the coordinate list to make copies.
So the code that meet your expectation would be:
import folium from folium.plugins import TimestampedGeoJson m = folium.Map(location=[52.467697, -2.548828], zoom_start=6) polygon_1 = { 'type': 'Feature', 'geometry': { 'type': 'MultiPolygon', 'coordinates': [(( (-2.548828, 51.467697), (-0.087891, 51.536086), (-1.516113, 53.800651), (-6.240234, 53.383328), ),)] * 6, # duplicatation for matching 6 timestamps }, 'properties': { 'style': { 'color': 'blue', }, 'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00', '2015-09-22T00:00:00', '2015-10-22T00:00:00', '2015-11-22T00:00:00', '2015-12-22T00:00:00'] } } polygon_2 = { 'type': 'Feature', 'geometry': { 'type': 'MultiPolygon', 'coordinates': [(( (-3.548828, 50.467697), (-1.087891, 50.536086), (-2.516113, 52.800651), (-7.240234, 52.383328), ),)] * 2, # duplicatation for matching 2 timestamps }, 'properties': { 'style': { 'color': 'yellow', }, 'times': ['2015-07-22T00:00:00', '2015-08-22T00:00:00'] } } TimestampedGeoJson( {'type': 'FeatureCollection', 'features': [polygon_1, polygon_2]}, period='P1M', duration='P1M', auto_play=False, loop=False, loop_button=True, date_options='YYYY/MM/DD', ).add_to(m) m
Hope that helps."