|
10 | 10 | "\n",
|
11 | 11 | "[](https://mybinder.org/v2/gh/anitagraser/movingpandas/master?filepath=tutorials/1-getting-started.ipynb)\n",
|
12 | 12 | "\n",
|
13 |
| - "MovingPandas provides a trajectory datatype based on GeoPandas.\n", |
14 |
| - "The project home is at https://github.com/anitagraser/movingpandas\n", |
| 13 | + "This notebook demonstrates the current development version of MovingPandas.\n", |
15 | 14 | "\n",
|
16 |
| - "This tutorial presents some of the trajectory manipulation and visualization functions implemented in MovingPandas.\n", |
17 |
| - "\n", |
18 |
| - "After following this tutorial, you will have a basic understanding of what MovingPandas is and what it can be used for. You'll be ready to dive into application examples presented in the the follow-up tutorials:\n", |
19 |
| - "\n", |
20 |
| - "Tutorials for specific functionality:\n", |
21 |
| - "\n", |
22 |
| - "* [Trajectory aggregation (flow maps)](2-generalization-and-aggregation.ipynb)\n", |
23 |
| - "* [Stop detection](3-stop-detection.ipynb)" |
24 |
| - ] |
25 |
| - }, |
26 |
| - { |
27 |
| - "cell_type": "markdown", |
28 |
| - "metadata": {}, |
29 |
| - "source": [ |
30 |
| - "## Introduction\n", |
31 |
| - "\n", |
32 |
| - "MovingPandas follows the **trajectories = timeseries with geometries** approach of modeling movement data.\n", |
33 |
| - "\n", |
34 |
| - "A MovingPandas trajectory can be interpreted as either a time series of points or a time series of line segments.\n", |
35 |
| - "The line-based approach has many advantages for trajectory analysis and visualization. (For more detail, see e.g. Westermeier (2018))\n", |
36 |
| - "\n", |
37 |
| - "\n", |
38 |
| - "\n", |
39 |
| - "\n", |
40 |
| - "\n", |
41 |
| - "\n", |
42 |
| - "### References\n", |
43 |
| - "\n", |
44 |
| - "* Graser, A. (2019). MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science 2019, 1-2019, 54-68. doi:10.1553/giscience2019_01_s54. URL: https://www.austriaca.at/rootcollection?arp=0x003aba2b\n", |
45 |
| - "* Westermeier, E.M. (2018). Contextual Trajectory Modeling and Analysis. Master Thesis, Interfaculty Department of Geoinformatics, University of Salzburg.\n" |
46 |
| - ] |
47 |
| - }, |
48 |
| - { |
49 |
| - "cell_type": "markdown", |
50 |
| - "metadata": {}, |
51 |
| - "source": [ |
52 |
| - "## Jupyter notebook setup" |
53 |
| - ] |
54 |
| - }, |
55 |
| - { |
56 |
| - "cell_type": "code", |
57 |
| - "execution_count": null, |
58 |
| - "metadata": {}, |
59 |
| - "outputs": [], |
60 |
| - "source": [ |
61 |
| - "%matplotlib inline" |
62 |
| - ] |
63 |
| - }, |
64 |
| - { |
65 |
| - "cell_type": "code", |
66 |
| - "execution_count": null, |
67 |
| - "metadata": {}, |
68 |
| - "outputs": [], |
69 |
| - "source": [ |
70 |
| - "from IPython.core.display import display, HTML\n", |
71 |
| - "display(HTML(\"<style>.container { width:100% !important; }</style>\"))" |
| 15 | + "**For tutorials using the latest release visit https://github.com/anitagraser/movingpandas-examples.**\n" |
72 | 16 | ]
|
73 | 17 | },
|
74 | 18 | {
|
|
91 | 35 | "sys.path.append(\"..\")\n",
|
92 | 36 | "import movingpandas as mpd\n",
|
93 | 37 | "print(mpd.__version__)\n",
|
| 38 | + "import holoviews\n", |
| 39 | + "print(holoviews.__version__)\n", |
| 40 | + "import geoviews\n", |
| 41 | + "print(geoviews.__version__)\n", |
94 | 42 | "\n",
|
95 | 43 | "import warnings\n",
|
96 | 44 | "#warnings.simplefilter(\"ignore\")"
|
97 | 45 | ]
|
98 | 46 | },
|
99 |
| - { |
100 |
| - "cell_type": "code", |
101 |
| - "execution_count": null, |
102 |
| - "metadata": {}, |
103 |
| - "outputs": [], |
104 |
| - "source": [ |
105 |
| - "CRS_METRIC = from_epsg(31256)" |
106 |
| - ] |
107 |
| - }, |
108 | 47 | {
|
109 | 48 | "cell_type": "markdown",
|
110 | 49 | "metadata": {},
|
111 | 50 | "source": [
|
112 |
| - "## Creating a trajectory from scratch\n", |
113 |
| - "\n", |
114 |
| - "Trajectory objects consist of a trajectory ID and a GeoPandas GeoDataFrame with a DatetimeIndex. The data frame therefore represents the trajectory data as a Pandas time series with associated point locations (and optional further attributes).\n", |
115 |
| - "\n", |
116 |
| - "Let's create a small toy trajectory to see how this works:" |
| 51 | + "## Creating a trajectory from scratch\n" |
117 | 52 | ]
|
118 | 53 | },
|
119 | 54 | {
|
|
128 | 63 | " {'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},\n",
|
129 | 64 | " {'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}\n",
|
130 | 65 | "]).set_index('t')\n",
|
131 |
| - "geo_df = GeoDataFrame(df, crs=None)\n", |
| 66 | + "geo_df = GeoDataFrame(df, crs=31256)\n", |
132 | 67 | "toy_traj = mpd.Trajectory(geo_df, 1)\n",
|
133 | 68 | "toy_traj.df"
|
134 | 69 | ]
|
|
252 | 187 | "## Analyzing trajectories"
|
253 | 188 | ]
|
254 | 189 | },
|
255 |
| - { |
256 |
| - "cell_type": "markdown", |
257 |
| - "metadata": {}, |
258 |
| - "source": [ |
259 |
| - "MovingPandas provides many functions for trajectory analysis. \n", |
260 |
| - "\n", |
261 |
| - "To see all available functions of the MovingPandas.Trajectory class use:" |
262 |
| - ] |
263 |
| - }, |
264 |
| - { |
265 |
| - "cell_type": "code", |
266 |
| - "execution_count": null, |
267 |
| - "metadata": {}, |
268 |
| - "outputs": [], |
269 |
| - "source": [ |
270 |
| - "dir(mpd.Trajectory)" |
271 |
| - ] |
272 |
| - }, |
273 |
| - { |
274 |
| - "cell_type": "markdown", |
275 |
| - "metadata": {}, |
276 |
| - "source": [ |
277 |
| - "Functions that start with an underscore (e.g. ```__str__```) should not be called directly. All other functions are free to use." |
278 |
| - ] |
279 |
| - }, |
280 | 190 | {
|
281 | 191 | "cell_type": "markdown",
|
282 | 192 | "metadata": {},
|
|
286 | 196 | "For example, let's have a look at the get_position_at() function:"
|
287 | 197 | ]
|
288 | 198 | },
|
289 |
| - { |
290 |
| - "cell_type": "code", |
291 |
| - "execution_count": null, |
292 |
| - "metadata": {}, |
293 |
| - "outputs": [], |
294 |
| - "source": [ |
295 |
| - "help(mpd.Trajectory.get_position_at)" |
296 |
| - ] |
297 |
| - }, |
298 |
| - { |
299 |
| - "cell_type": "markdown", |
300 |
| - "metadata": {}, |
301 |
| - "source": [ |
302 |
| - "When we call this method, the resulting point is directly rendered:" |
303 |
| - ] |
304 |
| - }, |
305 | 199 | {
|
306 | 200 | "cell_type": "code",
|
307 | 201 | "execution_count": null,
|
|
401 | 295 | "outputs": [],
|
402 | 296 | "source": [
|
403 | 297 | "intersections = toy_traj.clip(polygon)\n",
|
404 |
| - "print(intersections[0])" |
405 |
| - ] |
406 |
| - }, |
407 |
| - { |
408 |
| - "cell_type": "code", |
409 |
| - "execution_count": null, |
410 |
| - "metadata": {}, |
411 |
| - "outputs": [], |
412 |
| - "source": [ |
413 |
| - "intersections[0].plot(linewidth=5, capstyle='round')" |
| 298 | + "intersections" |
414 | 299 | ]
|
415 | 300 | },
|
416 | 301 | {
|
|
419 | 304 | "metadata": {},
|
420 | 305 | "outputs": [],
|
421 | 306 | "source": [
|
422 |
| - "for index, row in toy_traj.df.iterrows():\n", |
423 |
| - " print(index - datetime(2000,1,1))" |
| 307 | + "intersections.trajectories[0].plot(linewidth=5, capstyle='round')" |
424 | 308 | ]
|
425 | 309 | },
|
426 | 310 | {
|
|
584 | 468 | "my_traj.hvplot(c='speed', width=700, height=400, line_width=7.0, tiles='StamenTonerBackground', cmap='Viridis', colorbar=True, clim=(0,20))"
|
585 | 469 | ]
|
586 | 470 | },
|
587 |
| - { |
588 |
| - "cell_type": "code", |
589 |
| - "execution_count": null, |
590 |
| - "metadata": {}, |
591 |
| - "outputs": [], |
592 |
| - "source": [ |
593 |
| - "import holoviews\n", |
594 |
| - "print(holoviews.__version__)\n", |
595 |
| - "import geoviews\n", |
596 |
| - "print(geoviews.__version__)" |
597 |
| - ] |
598 |
| - }, |
599 | 471 | {
|
600 | 472 | "cell_type": "code",
|
601 | 473 | "execution_count": null,
|
|
0 commit comments