folium
folium copied to clipboard
TimestampedGeoJson only works if using times that all have the same number of digits in their Unix epoch time
data = pd.DataFrame({ 'Latitude': [2, 7, 2, 2, -4.03, 2, 36.82, 2], 'Longitude': [49, 66, 49, 49, 5.33, 49, -1.29, 49], 'Count': [40, 12, 22, 3, 23, 30, 100, 200], 'Year': ["1997", "1998", "1998", "1999", "1999", "2002", "2003", "2004"] })
Since this uses dates both before and after ~2002, it doesn't work. It works if using only dates before 2002 or after 2002 but not both
I assume this is because the number of digits in a Unix epoch time goes up from 12 to 13 around 2002
Is there anything I can do to get it working for all dates?
I haven't tried your data, but it doesn't seem to match the specification in the docstring of TimestampedGeoJson. Furthermore the docstring says to pass your timestamps as ISO timestamps or as unix epoch timestamps in ms. Currently you pass only a year, if you change that does that fix your issue?
I haven't tried your data, but it doesn't seem to match the specification in the docstring of
TimestampedGeoJson. Furthermore the docstring says to pass your timestamps as ISO timestamps or as unix epoch timestamps in ms. Currently you pass only a year, if you change that does that fix your issue?
I've tried passing in all formats I could think of including unix epoch timestamps in ms and ISO timestamps but it only ever works if all dates are either before or after 2002.
My theory is that dates are converted to unix epoch timestamps and when it's dealing with timestamps that aren't the same number of digits it doesn't work
Alright, good to know. I'm quickly looking at the code in TimestampedGeoJson but don't see something truncating a timestamp string or something.
What would be helpful if you could provide a small, self-contained code snippet, including a bit of data, that produces your error.
Alright, good to know. I'm quickly looking at the code in
TimestampedGeoJsonbut don't see something truncating a timestamp string or something.What would be helpful if you could provide a small, self-contained code snippet, including a bit of data, that produces your error.
The code below works fine, but if I change any of these years to 2002 or later it doesn't work. However if all years are 2002 or later it works fine
import pandas as pd
from folium.plugins import TimestampedGeoJson
data = pd.DataFrame({
'Latitude': [2, 7, 2, 2, -4.03, 2, 36.82, 2],
'Longitude': [49, 66, 49, 49, 5.33, 49, -1.29, 49],
'Count': [40, 12, 22, 3, 23, 30, 100, 200],
'Year': ['1985', '1990', '1993', '1995', '1998', '2000', '2001', '2001']
})
features = create_geojson_features(data)
myMap = make_map(features, data)
myMap .save('locations.html')
def create_geojson_features(data):
features = []
for _, row in data.iterrows():
feature = {
'type': 'Feature',
'geometry': {
'type':'Point',
'coordinates':[row['Longitude'],row['Latitude']]
},
'properties': {
'time': row["Year"],
'style': {'color': "crimson"},
'icon': 'circle',
'iconstyle':{
'fillColor': "crimson",
'fillOpacity': 1,
'stroke': 'true',
'radius': row["Count"]/5
}
}
}
features.append(feature)
return features
def make_map(features, data):
myMap = folium.Map(location=[20, 0], tiles="OpenStreetMap", zoom_start=2)
TimestampedGeoJson(
{'type': 'FeatureCollection',
'features': features}
, period='P1M'
, add_last_point=True
, transition_time=200
, auto_play=True
, max_speed=1
, loop=True
, loop_button=True
, time_slider_drag_update=True
).add_to(myMap)
return myMap
For what it's worth, I was having the same issue until I stumbled on this discussion. I'd love to see how it worked out. I have the same issues, with sample data and real data. It all works fine if my years are all before 2002, or after 2002, but it crashes if the years span 2002.
This issue is still open. We need someone to figure out what’s causing it. And then someone making a PR with a fix.
I recently use TimestampedGeoJson plugin to show changes of data varying with time. I found this bug from the internally used leaflet-timedimension. The function sort_and_deduplicate in the minified version from cdn.jsdeliver.net caused the problem when sort the available time since it sorts time as strings.
Problem: sort_and_deduplicate: function(arr) { arr = arr.slice(0).sort();<--- Here is problem. var result = []; var last = null; for (var i = 0, l = arr.length; i < l; i++) { if (arr[i] !== last){ result.push(arr[i]); last = arr[i]; } } return result; }
Solution:
It can be solved by adding an anonymous function. It works as a local file along with the html.
arr = arr.slice(0).sort(function(a, b){return a-b;});
The source code of leaflet.timeddimension on GitHub had been used as this. It maybe some unknown reason that the function lost the argument( I am not sure!). It seems to be not solved yet.
I hope it helps.
myMap = make_map(features, data) myMap .save('locations.html')
when I try to run the above code, the plug shows "Time not available"...i have written the code for data that has 1 time per year for each country for 30 years and i get the same message and no simulation. I have tried converting the time format several times but didnt fix the issue
message
hi, anyone have a solution for this? I'm using the same code but for me the problem is with before and after 9/9/2001, i tried other libraries (but went back to folium because of the aesthetic) and they don't have a similar issue, can't figure this out for a week :(
@davecao Thanks for the debugging information. That was really helpful. Since it seems the issue is in the underlying socib/timedimension package, I will open an issue there.
Apparently it was already fixed in the source code of the underlying javascript package, but the new version was never released.
Hello,
I have used timestampedgeojson extensively and I could not find the way to troubleshoot the issue you mentioned. Up until now , there is no solution (at least that I am aware of) Have you tried leaflet.js overlay animations? There is a couple of options for markers animation and motion with progress …
Hope this helps. I’m not expert.
On Sun, 14 Apr 2024 at 2:38 PM BlueCrabsLover @.***> wrote:
hi, anyone have a solution for this? I'm using the same code but for me the problem is with before and after 9/9/2001, i tried other libraries (but went back to folium because of the aesthetic) and they don't have a similar issue, can't figure this out for a week :(
— Reply to this email directly, view it on GitHub https://github.com/python-visualization/folium/issues/1268#issuecomment-2054002872, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR5NF4DCVEBAXLR577QTO7LY5JMC7AVCNFSM4LCN4S62U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBVGQYDAMRYG4ZA . You are receiving this because you commented.Message ID: @.***>
thanks I'll check it out today, because it looks like I'll have to find another way to do this
Let us know how it goes … there is an example
With leaflet and timestampedgeojson for satellites flight coordinates visualization
https://stackoverflow.com/questions/73386025/merge-multiple-folium-timestampedgeojson-timedimensioncontrol-into-one
This is an animated leaflet map with time series , no timegeojson
https://apps.socib.es/Leaflet.TimeDimension/examples/example2.html
Let me know what you think and if any of these examples was helpful
On Tue, 16 Apr 2024 at 1:00 PM BlueCrabsLover @.***> wrote:
thanks I'll check it out today, because it looks like I'll have to find another way to do this
— Reply to this email directly, view it on GitHub https://github.com/python-visualization/folium/issues/1268#issuecomment-2058592309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR5NF4F6YF5RWD6MZNMC2TLY5TSEBAVCNFSM4LCN4S62U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBVHA2TSMRTGA4Q . You are receiving this because you commented.Message ID: @.***>