|
29 | 29 | "import geopandas as gpd\n", |
30 | 30 | "import movingpandas as mpd\n", |
31 | 31 | "import shapely as shp\n", |
32 | | - "import hvplot.pandas \n", |
| 32 | + "import hvplot.pandas\n", |
33 | 33 | "\n", |
34 | 34 | "from geopandas import GeoDataFrame, read_file\n", |
35 | 35 | "from shapely.geometry import Point, LineString, Polygon\n", |
36 | 36 | "from datetime import datetime, timedelta\n", |
37 | 37 | "from holoviews import opts\n", |
38 | 38 | "\n", |
39 | 39 | "import warnings\n", |
40 | | - "warnings.filterwarnings('ignore')\n", |
41 | 40 | "\n", |
42 | | - "opts.defaults(opts.Overlay(active_tools=['wheel_zoom'], frame_width=500, frame_height=400))\n", |
| 41 | + "warnings.filterwarnings(\"ignore\")\n", |
| 42 | + "\n", |
| 43 | + "opts.defaults(\n", |
| 44 | + " opts.Overlay(active_tools=[\"wheel_zoom\"], frame_width=500, frame_height=400)\n", |
| 45 | + ")\n", |
43 | 46 | "\n", |
44 | 47 | "mpd.show_versions()" |
45 | 48 | ] |
|
62 | 65 | "metadata": {}, |
63 | 66 | "outputs": [], |
64 | 67 | "source": [ |
65 | | - "df = pd.DataFrame([\n", |
66 | | - " {'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)},\n", |
67 | | - " {'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)},\n", |
68 | | - " {'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},\n", |
69 | | - " {'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}\n", |
70 | | - "]).set_index('t')\n", |
| 68 | + "df = pd.DataFrame(\n", |
| 69 | + " [\n", |
| 70 | + " {\"geometry\": Point(0, 0), \"t\": datetime(2018, 1, 1, 12, 0, 0)},\n", |
| 71 | + " {\"geometry\": Point(6, 0), \"t\": datetime(2018, 1, 1, 12, 6, 0)},\n", |
| 72 | + " {\"geometry\": Point(6, 6), \"t\": datetime(2018, 1, 1, 12, 10, 0)},\n", |
| 73 | + " {\"geometry\": Point(9, 9), \"t\": datetime(2018, 1, 1, 12, 15, 0)},\n", |
| 74 | + " ]\n", |
| 75 | + ").set_index(\"t\")\n", |
71 | 76 | "gdf = GeoDataFrame(df, crs=31256)\n", |
72 | 77 | "toy_traj = mpd.Trajectory(gdf, 1)\n", |
73 | 78 | "toy_traj" |
|
131 | 136 | "metadata": {}, |
132 | 137 | "outputs": [], |
133 | 138 | "source": [ |
134 | | - "df = pd.read_csv('../data/geolife_small.csv', delimiter=';')\n", |
| 139 | + "df = pd.read_csv(\"../data/geolife_small.csv\", delimiter=\";\")\n", |
135 | 140 | "df" |
136 | 141 | ] |
137 | 142 | }, |
|
141 | 146 | "metadata": {}, |
142 | 147 | "outputs": [], |
143 | 148 | "source": [ |
144 | | - "traj_collection = mpd.TrajectoryCollection(df, 'trajectory_id', t='t', x='X', y='Y')\n", |
| 149 | + "traj_collection = mpd.TrajectoryCollection(df, \"trajectory_id\", t=\"t\", x=\"X\", y=\"Y\")\n", |
145 | 150 | "print(traj_collection)" |
146 | 151 | ] |
147 | 152 | }, |
|
151 | 156 | "metadata": {}, |
152 | 157 | "outputs": [], |
153 | 158 | "source": [ |
154 | | - "traj_collection.plot(column='trajectory_id', legend=True, figsize=(9,5))" |
| 159 | + "traj_collection.plot(column=\"trajectory_id\", legend=True, figsize=(9, 5))" |
155 | 160 | ] |
156 | 161 | }, |
157 | 162 | { |
|
168 | 173 | "metadata": {}, |
169 | 174 | "outputs": [], |
170 | 175 | "source": [ |
171 | | - "gdf = read_file('../data/geolife_small.gpkg')\n", |
| 176 | + "gdf = read_file(\"../data/geolife_small.gpkg\")\n", |
172 | 177 | "gdf" |
173 | 178 | ] |
174 | 179 | }, |
|
186 | 191 | "metadata": {}, |
187 | 192 | "outputs": [], |
188 | 193 | "source": [ |
189 | | - "traj_collection = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')\n", |
| 194 | + "traj_collection = mpd.TrajectoryCollection(gdf, \"trajectory_id\", t=\"t\")\n", |
190 | 195 | "print(traj_collection)" |
191 | 196 | ] |
192 | 197 | }, |
|
196 | 201 | "metadata": {}, |
197 | 202 | "outputs": [], |
198 | 203 | "source": [ |
199 | | - "traj_collection.plot(column='trajectory_id', legend=True, figsize=(9,5))" |
| 204 | + "traj_collection.plot(column=\"trajectory_id\", legend=True, figsize=(9, 5))" |
200 | 205 | ] |
201 | 206 | }, |
202 | 207 | { |
|
208 | 213 | "traj_collection.plot()" |
209 | 214 | ] |
210 | 215 | }, |
| 216 | + { |
| 217 | + "cell_type": "markdown", |
| 218 | + "metadata": {}, |
| 219 | + "source": [ |
| 220 | + "To visualize trajectories in their geographical context, we can also create interactive plots with basemaps:" |
| 221 | + ] |
| 222 | + }, |
| 223 | + { |
| 224 | + "cell_type": "code", |
| 225 | + "execution_count": null, |
| 226 | + "metadata": {}, |
| 227 | + "outputs": [], |
| 228 | + "source": [ |
| 229 | + "traj_collection.explore(column=\"trajectory_id\", cmap=\"plasma\", tiles=\"CartoDB positron\")" |
| 230 | + ] |
| 231 | + }, |
211 | 232 | { |
212 | 233 | "attachments": {}, |
213 | 234 | "cell_type": "markdown", |
|
232 | 253 | "metadata": {}, |
233 | 254 | "outputs": [], |
234 | 255 | "source": [ |
235 | | - "my_traj.plot(linewidth=5, capstyle='round', figsize=(9,3))" |
| 256 | + "my_traj.plot(linewidth=5, capstyle=\"round\", figsize=(9, 3))" |
236 | 257 | ] |
237 | 258 | }, |
238 | 259 | { |
239 | 260 | "attachments": {}, |
240 | 261 | "cell_type": "markdown", |
241 | 262 | "metadata": {}, |
242 | 263 | "source": [ |
243 | | - "To visualize trajectories in their geographical context, we can also create interactive plots with basemaps:" |
| 264 | + "To visualize trajectories in their geographical context, we can again create interactive plots with basemaps:" |
| 265 | + ] |
| 266 | + }, |
| 267 | + { |
| 268 | + "cell_type": "code", |
| 269 | + "execution_count": null, |
| 270 | + "metadata": {}, |
| 271 | + "outputs": [], |
| 272 | + "source": [ |
| 273 | + "my_traj.hvplot(line_width=7.0, tiles=\"OSM\")" |
244 | 274 | ] |
245 | 275 | }, |
246 | 276 | { |
|
249 | 279 | "metadata": {}, |
250 | 280 | "outputs": [], |
251 | 281 | "source": [ |
252 | | - "my_traj.hvplot(line_width=7.0, tiles='OSM')" |
| 282 | + "my_traj.explore(tiles=\"CartoDB positron\", style_kwds={\"weight\": 4})" |
253 | 283 | ] |
254 | 284 | }, |
255 | 285 | { |
|
274 | 304 | " }\n", |
275 | 305 | ")\n", |
276 | 306 | "gdf = gpd.GeoDataFrame(df, crs=4326)\n", |
277 | | - "tc = mpd.TrajectoryCollection(gdf, traj_id_col='trajectory_id', t='t')\n", |
| 307 | + "tc = mpd.TrajectoryCollection(gdf, traj_id_col=\"trajectory_id\", t=\"t\")\n", |
278 | 308 | "tc" |
279 | 309 | ] |
280 | 310 | }, |
|
0 commit comments