Minimal working examples of bugs
This notebook demonstrates the current development version of MovingPandas.
For tutorials using the latest release visit https://github.com/movingpandas/movingpandas-examples.
import urllib
import os
import pandas as pd
import geopandas as gpd
from geopandas import GeoDataFrame, read_file
from shapely.geometry import Point, LineString, Polygon
from datetime import datetime, timedelta
from matplotlib import pyplot as plt
import sys
sys.path.append("..")
import movingpandas as mpd
mpd.show_versions()
df = pd.DataFrame([
{'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)},
{'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)},
{'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},
{'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}
]).set_index('t')
gdf = GeoDataFrame(df, crs=31256)
toy_traj = mpd.Trajectory(gdf, 1)
toy_traj.df
xmin, xmax, ymin, ymax = 2, 8, -10, 5
polygon = Polygon([(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin), (xmin, ymin)])
polygon_gdf = GeoDataFrame(pd.DataFrame([{'geometry':polygon, 'id':1}]), crs=4326)
intersections = toy_traj.clip(polygon)
intersections
toy_traj.add_speed()#overwrite=True)
intersections = toy_traj.clip(polygon)
intersections
ax = toy_traj.plot()
polygon_gdf.plot(ax=ax, color='lightgray')
intersections.plot(ax=ax, color='red', linewidth=5)
toy_traj.add_speed(overwrite=True)
toy_traj.df.plot()
toy_traj.plot(width=7)
toy_traj.plot(column="speed", linewidth=5)
toy_traj.hvplot(line_width=5)
toy_traj.hvplot(c='speed', line_width=7)
gdf = read_file('data/demodata_geolife.gpkg')
traj_collection = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')
generalized = mpd.MinDistanceGeneralizer(traj_collection).generalize(tolerance=100)
generalized.hvplot(tiles=None)
generalized.hvplot(tiles=None, line_width=1, marker_size=0)