Skip to content Skip to sidebar Skip to footer

Timestampedgeojson Duration Parameter Causes Polygons To Disappear

I'm having trouble modifying a code snippet from the second TimestampedGeoJson example in the Plugins example notebook. The duration parameter is described as the 'period of time w

Solution 1:

Since the same question was asked on GitHub and was also answered there, I'm going to copy-paste the answer of GitHub-user "andy23512" hereafter in order to help out people who don't find the answer by accident on GitHub.

In the following the quoted answer is stated:

"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."

Post a Comment for "Timestampedgeojson Duration Parameter Causes Polygons To Disappear"