{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Debugging\n", "\n", "\n", "\n", "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/movingpandas/movingpandas/main?filepath=tutorials/0-debug.ipynb)\n", "\n", "Minimal working examples of bugs\n", "\n", "**

This notebook demonstrates the current development version of MovingPandas.

**\n", "\n", "For tutorials using the latest release visit https://github.com/movingpandas/movingpandas-examples.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import urllib\n", "import os\n", "import pandas as pd\n", "import geopandas as gpd\n", "from geopandas import GeoDataFrame, read_file\n", "from shapely.geometry import Point, LineString, Polygon\n", "from datetime import datetime, timedelta\n", "from matplotlib import pyplot as plt\n", "\n", "import sys\n", "sys.path.append(\"..\")\n", "import movingpandas as mpd\n", "mpd.show_versions()\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Creating a trajectory from scratch\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame([\n", " {'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)},\n", " {'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)},\n", " {'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},\n", " {'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}\n", "]).set_index('t')\n", "gdf = GeoDataFrame(df, crs=31256)\n", "toy_traj = mpd.Trajectory(gdf, 1)\n", "toy_traj.df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "xmin, xmax, ymin, ymax = 2, 8, -10, 5\n", "polygon = Polygon([(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin), (xmin, ymin)])\n", "polygon_gdf = GeoDataFrame(pd.DataFrame([{'geometry':polygon, 'id':1}]), crs=4326)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "intersections = toy_traj.clip(polygon)\n", "intersections" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toy_traj.add_speed()#overwrite=True)\n", "intersections = toy_traj.clip(polygon)\n", "intersections" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = toy_traj.plot()\n", "polygon_gdf.plot(ax=ax, color='lightgray')\n", "intersections.plot(ax=ax, color='red', linewidth=5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toy_traj.add_speed(overwrite=True)\n", "toy_traj.df.plot()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toy_traj.plot(width=7)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toy_traj.plot(column=\"speed\", linewidth=5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toy_traj.hvplot(line_width=5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "toy_traj.hvplot(c='speed', line_width=7)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gdf = read_file('data/demodata_geolife.gpkg')\n", "traj_collection = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')\n", "generalized = mpd.MinDistanceGeneralizer(traj_collection).generalize(tolerance=100)\n", "generalized.hvplot(tiles=None)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "generalized.hvplot(tiles=None, line_width=1, marker_size=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "movingpandas2", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" }, "vscode": { "interpreter": { "hash": "82848d59fcdc131fde282c5d2ad74af4ffdc817ad1bf2bd8f241be92d19a1d9a" } } }, "nbformat": 4, "nbformat_minor": 4 }