Skip to content

Commit 3ffa714

Browse files
authored
#167 enable Exceptions GDAL OGR Py bindings plus text chanegs (#171)
1 parent 2dba764 commit 3ffa714

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

workshop/jupyter/content/notebooks/04-vector-data.ipynb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@
479479
"cell_type": "markdown",
480480
"metadata": {},
481481
"source": [
482-
"### Buffer\n",
483-
"First we need to open the *Data Source*, printing the number of Layers."
482+
"### Basic programming patterns\n",
483+
"First, we open a *Data Source* and print its number of *Layers*. Note that we also globally enable GDAL Exceptions. By default, the GDAL/OGR Python bindings do not raise exceptions when errors occur. Instead, they return an error value such as `None` and write an error message to `sys.stdout`. You can enable exceptions by calling the `UseExceptions()` function. This is a recommended practice. See [this tutorial](https://pcjericks.github.io/py-gdalogr-cookbook/gdal_general.html#enable-python-exceptions)."
484484
]
485485
},
486486
{
@@ -493,7 +493,11 @@
493493
},
494494
"outputs": [],
495495
"source": [
496-
"from osgeo import ogr\n",
496+
"from osgeo import ogr, gdal\n",
497+
"\n",
498+
"# Exceptions will get raised on anything >= gdal.CE_Failure\n",
499+
"gdal.UseExceptions()\n",
500+
"\n",
497501
"ds = ogr.Open('../data/countries.gpkg')\n",
498502
"print(ds)\n",
499503
"print(ds.GetLayerCount())"
@@ -502,10 +506,7 @@
502506
{
503507
"cell_type": "markdown",
504508
"metadata": {},
505-
"source": [
506-
"Next we have to fetch and open the *Layer*. NB for files, there is usually just one layer, index `0`, \n",
507-
"within the Data Source (DS), but for example for a database DS, a Layer is refers to a concrete table)."
508-
]
509+
"source": "Next we fetch and open a *Layer*. NB for files like GeoJSON, there is usually just one layer, at index 0, within the Data Source (DS). Datasources like GeoPackages and databases in general may have multiple Layers, where a Layer refers to a concrete table."
509510
},
510511
{
511512
"cell_type": "code",
@@ -525,9 +526,7 @@
525526
{
526527
"cell_type": "markdown",
527528
"metadata": {},
528-
"source": [
529-
"Show the schema of the layer and the definition of its geometry type:"
530-
]
529+
"source": "Show the schema of the Layer and the definition of its geometry type:"
531530
},
532531
{
533532
"cell_type": "code",
@@ -1772,7 +1771,7 @@
17721771
"name": "python",
17731772
"nbconvert_exporter": "python",
17741773
"pygments_lexer": "ipython3",
1775-
"version": "3.11.4"
1774+
"version": "3.10.12"
17761775
},
17771776
"vscode": {
17781777
"interpreter": {
@@ -1781,5 +1780,5 @@
17811780
}
17821781
},
17831782
"nbformat": 4,
1784-
"nbformat_minor": 2
1783+
"nbformat_minor": 4
17851784
}

0 commit comments

Comments
 (0)