I am having issues with Folium and using TimestampedGeoJson
. I have the following dataframe structure below. I am trying to display this data with Folium and a time slider to be used on the date field:
Date Geometry
0 2016-03-09 POLYGON ((10.00000 25.00000, 10.00000 25.00000, 10.00000
26.00000, 12.00000 26.00000, 18.00000 25.00000,
17.00000 25.00000))
I am trying to follow this tutorial below and still not working:
https://towardsdatascience.com/visualizing-nyc-bike-data-on-interactive-and-animated-maps-with-folium-plugins-c2d7645cd19b
def create_geojson_features(df):
features = []
for _, row in df.iterrows():
features = []
feature = {
'type': 'Features',
'geometry': {
'type':'MultiPolygon',
'coordinates':(row['Geometry'])
},
'properties': {
'times':(pd.to_datetime(row['Date'])),
}
}
features.append(feature)
return features
df1 = create_geojson_features(df)
world_map = folium.Map(location=[10,0],tiles="cartodbposition",zoom_start=2,max_zoom=6,min_zoom=3)
TimestampedGeoJson(
df1
, 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
).add_to(world_map)
The geometry and times are not being read correctly via the function and/or the TimestampedGeoJson
. Also, in the coordinates field is a shapely object once the function create_geojson_features
is executed.
Best Answer
I think the best way to transform geodataframe to geojson is using this function:
Source