Skip to content

Commit f0740dd

Browse files
Tutorial 2: Change "gdf" to "gpd" in variable name | Show output of ".head()" and ".crs" explicitly (#39)
1 parent e529a19 commit f0740dd

File tree

2 files changed

+80
-19
lines changed

2 files changed

+80
-19
lines changed

book/tut01_firstfigure.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@
522522
"name": "python",
523523
"nbconvert_exporter": "python",
524524
"pygments_lexer": "ipython3",
525-
"version": "3.12.6"
525+
"version": "3.12.7"
526526
},
527527
"panel-cell-order": [
528528
"eb4b43cc-dc76-45d1-a370-7266bd943910",

book/tut02_spe_pd_gpd.ipynb

+79-18
Original file line numberDiff line numberDiff line change
@@ -258,33 +258,94 @@
258258
"metadata": {},
259259
"outputs": [],
260260
"source": [
261-
"gpd_rivers_org = gpd.read_file(\n",
261+
"gdf_rivers_org = gpd.read_file(\n",
262262
" \"https://www.eea.europa.eu/data-and-maps/data/wise-large-rivers-and-large-lakes/\"\n",
263263
" + \"zipped-shapefile-with-wise-large-rivers-vector-line/zipped-shapefile-with-wise-large-rivers-vector-line/\"\n",
264264
" + \"at_download/file/wise_large_rivers.zip\"\n",
265265
")\n",
266-
"# gpd_rivers_org = pd.read_file(\"wise_large_rivers.zip\")\n",
267-
"gpd_rivers_org.head()"
266+
"# gdf_rivers_org = gpd.read_file(\"wise_large_rivers.zip\")"
268267
]
269268
},
270269
{
271270
"cell_type": "markdown",
272271
"id": "f8db1757-f80d-4cc3-b650-83109eecc390",
273272
"metadata": {},
274273
"source": [
275-
"Have a look at the values in the geometry column. The coordinates are currently not given in the geographic coordinate reference system (longitude/latitude) and have to be converted. This can be done directly with `GeoPandas`."
274+
"Have a look at the data and especially at the values in the geometry column:"
276275
]
277276
},
278277
{
279278
"cell_type": "code",
280279
"execution_count": null,
281-
"id": "cc67a58c-45f3-4819-9df4-04e5aa9d06f7",
280+
"id": "926955ee-3859-468b-9b41-0398ed6c7b99",
282281
"metadata": {},
283282
"outputs": [],
284283
"source": [
285-
"gpd_rivers_org.crs\n",
286-
"gpd_rivers = gpd_rivers_org.to_crs(\"EPSG:4326\")\n",
287-
"gpd_rivers.head()"
284+
"gdf_rivers_org.head()"
285+
]
286+
},
287+
{
288+
"cell_type": "markdown",
289+
"id": "b868d284-23ff-4607-a950-de47da71f7cd",
290+
"metadata": {},
291+
"source": [
292+
"The coordinates are currently not given in the geographic coordinate reference system (longitude/latitude):"
293+
]
294+
},
295+
{
296+
"cell_type": "code",
297+
"execution_count": null,
298+
"id": "f033930d-fe1c-4883-a27c-6a768bb29598",
299+
"metadata": {},
300+
"outputs": [],
301+
"source": [
302+
"gdf_rivers_org.crs"
303+
]
304+
},
305+
{
306+
"cell_type": "markdown",
307+
"id": "59edb4bf-9466-41a9-9cf6-f2ae3d7a5a0d",
308+
"metadata": {},
309+
"source": [
310+
"Thus, they have to be converted which can be done directly with `GeoPandas`."
311+
]
312+
},
313+
{
314+
"cell_type": "code",
315+
"execution_count": null,
316+
"id": "c6a07d4d-ec70-4624-836b-41f713218f11",
317+
"metadata": {},
318+
"outputs": [],
319+
"source": [
320+
"gdf_rivers = gdf_rivers_org.to_crs(\"EPSG:4326\")"
321+
]
322+
},
323+
{
324+
"cell_type": "markdown",
325+
"id": "cd9b9f2b-d15b-4336-b2ee-4370bb6ffb25",
326+
"metadata": {},
327+
"source": [
328+
"Again have a look at the coordinate system and the data:"
329+
]
330+
},
331+
{
332+
"cell_type": "code",
333+
"execution_count": null,
334+
"id": "06124f49-4dc7-4518-8ceb-b85257a30920",
335+
"metadata": {},
336+
"outputs": [],
337+
"source": [
338+
"gdf_rivers.crs"
339+
]
340+
},
341+
{
342+
"cell_type": "code",
343+
"execution_count": null,
344+
"id": "537e141d-6f64-4b99-9e30-75e1c217d3c5",
345+
"metadata": {},
346+
"outputs": [],
347+
"source": [
348+
"gdf_rivers.head()"
288349
]
289350
},
290351
{
@@ -314,7 +375,7 @@
314375
" frame=True,\n",
315376
")\n",
316377
"\n",
317-
"fig.plot(data=gpd_rivers, pen=\"0.5p,steelblue,solid\")\n",
378+
"fig.plot(data=gdf_rivers, pen=\"0.5p,steelblue,solid\")\n",
318379
"\n",
319380
"fig.show(dpi=img_dpi)"
320381
]
@@ -341,8 +402,8 @@
341402
"# Split the dataset into two subsets of shorter and longer rivers\n",
342403
"# Feel free to play around with the limit\n",
343404
"len_limit = 700000 # in meters\n",
344-
"gpd_rivers_short = gpd_rivers[gpd_rivers[\"Shape_Leng\"] < len_limit]\n",
345-
"gpd_rivers_long = gpd_rivers[gpd_rivers[\"Shape_Leng\"] > len_limit]\n",
405+
"gdf_rivers_short = gdf_rivers[gdf_rivers[\"Shape_Leng\"] < len_limit]\n",
406+
"gdf_rivers_long = gdf_rivers[gdf_rivers[\"Shape_Leng\"] > len_limit]\n",
346407
"\n",
347408
"\n",
348409
"fig = pygmt.Figure()\n",
@@ -357,11 +418,11 @@
357418
"\n",
358419
"# Plot the subsets differently and specify the text for the legend entries\n",
359420
"fig.plot(\n",
360-
" data=gpd_rivers_short,\n",
421+
" data=gdf_rivers_short,\n",
361422
" pen=\"0.5p,orange\",\n",
362423
" label=f\"shorter {len_limit} m+Hriver length+f9p\",\n",
363424
")\n",
364-
"fig.plot(data=gpd_rivers_long, pen=\"0.5p,darkred\", label=f\"longer {len_limit} m\")\n",
425+
"fig.plot(data=gdf_rivers_long, pen=\"0.5p,darkred\", label=f\"longer {len_limit} m\")\n",
365426
"\n",
366427
"# Place the legend at the Top Left corner with an offset of 0.1 centimeters from the map frame\n",
367428
"# Add a box with semi-transparent (@30) white fill (+g) and a 0.1-points thick gray outline (+p)\n",
@@ -520,14 +581,14 @@
520581
")\n",
521582
"\n",
522583
"pygmt.makecpt(\n",
523-
" cmap=\"SCM/oslo\", series=[gpd_rivers.Shape_Leng.min(), 1500000], reverse=True\n",
584+
" cmap=\"SCM/oslo\", series=[gdf_rivers.Shape_Leng.min(), 1500000], reverse=True\n",
524585
")\n",
525586
"fig.colorbar(frame=[\"x+lriver length\", \"y+lm\"], position=\"+ef0.2c\")\n",
526587
"\n",
527-
"for i_river in range(len(gpd_rivers)):\n",
588+
"for i_river in range(len(gdf_rivers)):\n",
528589
" fig.plot(\n",
529-
" data=gpd_rivers[gpd_rivers.index == i_river],\n",
530-
" zvalue=gpd_rivers.loc[i_river, \"Shape_Leng\"],\n",
590+
" data=gdf_rivers[gdf_rivers.index == i_river],\n",
591+
" zvalue=gdf_rivers.loc[i_river, \"Shape_Leng\"],\n",
531592
" pen=\"0.5p\",\n",
532593
" cmap=True,\n",
533594
" )\n",
@@ -552,7 +613,7 @@
552613
"name": "python",
553614
"nbconvert_exporter": "python",
554615
"pygments_lexer": "ipython3",
555-
"version": "3.12.6"
616+
"version": "3.12.7"
556617
}
557618
},
558619
"nbformat": 4,

0 commit comments

Comments
 (0)