question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TimestampedGeoJson duration parameter causes polygons to disappear

See original GitHub issue

Hi all - I’m having trouble modifying a code snippet from the second TimestampedGeoJson example in the Plugins example notebook.

import folium
from folium.plugins import TimestampedGeoJson

m = folium.Map(location=[52.467697, -2.548828], zoom_start=6)

polygon = {
    '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']
    }
}

TimestampedGeoJson(
    {'type': 'FeatureCollection', 'features': [polygon]},
    period='P1M',
    duration='P1M',
    auto_play=False,
    loop=False,
    loop_button=True,
    date_options='YYYY/MM/DD',
).add_to(m)
    
m

The duration parameter is described as the “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.”

I expect this geometry to be shown on the map for all three time periods, but instead I see it disappear after the first time period.

I’m using folium version 0.6.0 without an ad-blocker. This happens in both Jupyter and html export. The duration parameter was introduced in #894.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
andy23512commented, Sep 29, 2020

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, # duplication 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, # duplication 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.

0reactions
Celtics33commented, Jan 17, 2021

how do you read a file of multipolygons from a geodataframe?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TimestampedGeoJson duration parameter causes polygons to ...
The duration parameter is described as the "period of time which the features will be shown on the map after their time has...
Read more >
python-visualization/folium - Gitter
Another question: Is there an easy way to overlay labels for each polygon in a folium.feature.GeoJson , say by specifying the column on...
Read more >
2021年08月_weixin_39786534的博客_CSDN博客
TimestampedGeoJson duration parameter causes polygons to disappear. 2021-01-12 ... Build failed on ARMv7: c++: error: missing argument to '-march='.
Read more >
TimestampedGeoJson duration parameter causes po...anycodings
TimestampedGeoJson duration parameter causes polygons to disappear I'm having trouble modifying a code snippet anycod ...
Read more >
Python Data. Leaflet.js Maps. - PythonRepo
Maps with complex polygon layers not rendering in Jupyter Lab/Notebook ... This is a major time waster and makes a bad impression on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found