Skip to content

Commit 5e46801

Browse files
committed
Tweak example
1 parent 12dcfcd commit 5e46801

File tree

1 file changed

+54
-27
lines changed

1 file changed

+54
-27
lines changed

examples/a2_maastricht_gef/a2_maastricht_gef_to_brgi_geodb.py

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
# "pygef==0.13.0",
1414
# "pandas==2.3.3",
1515
# "pyarrow==21.0.0",
16+
# "anthropic==0.73.0",
17+
# "numpy==2.3.5",
1618
# ]
1719
# ///
1820

1921
import marimo
2022

21-
__generated_with = "0.17.6"
23+
__generated_with = "0.17.8"
2224
app = marimo.App(
2325
width="medium",
2426
app_title="Maastricht A2 Tunnel GEF-BORE data to a Bedrock GI Geospatial Database",
@@ -30,7 +32,7 @@ def _(mo):
3032
mo.md("""
3133
# GEF Data for A2 Tunnel Maastricht
3234
33-
<img src="https://bedrock.engineer/Bedrock_TextRight.png" alt="Bedrock logo" width="180" />
35+
<a href="https://bedrock.engineer"><img src="https://bedrock.engineer/Bedrock_TextRight.png" alt="Bedrock logo" width="180" /></a>
3436
3537
This notebook demonstrates how to
3638
@@ -43,12 +45,12 @@ def _(mo):
4345
<details>
4446
<summary>What are GEF files?</summary>
4547
<p>
46-
<abbr>Geotechnical Exchange Format (GEF)</abbr> is a standardized,
48+
<abbr>[Geotechnical Exchange Format](http://localhost:4321/reference/formats/gef/gef/) (GEF)</abbr> is a standardized,
4749
text-based format designed to facilitate the reliable exchange and archiving
4850
of geotechnical investigation data, particularly CPT results, across
4951
different organizations and software platforms. GEF can also be used for
5052
other types of soil tests, like <a href="https://bedrock.engineer/reference/formats/gef/gef-cpt/">CPTs</a>. It is widely used in the
51-
Netherlands in ground investigation.
53+
Netherlands and Belgium in ground investigation.
5254
</p>
5355
</details>
5456
@@ -113,7 +115,7 @@ def _(Path, pygef):
113115

114116
@app.cell(hide_code=True)
115117
def _(mo):
116-
mo.md("pygef uses [polars](https://pola.rs/) for DataFrames, for consistency we will convert them to [Pandas](http://pandas.pydata.org/) DataFrames in this notebook.").callout("warn")
118+
mo.md("pygef uses [polars](https://pola.rs/) for DataFrames, for consistency, we convert them to [Pandas](http://pandas.pydata.org/) DataFrames in this notebook.").callout("warn")
117119
return
118120

119121

@@ -128,6 +130,7 @@ def _(boreholes, mo):
128130
@app.cell(hide_code=True)
129131
def _(multiselect):
130132
index = multiselect.value or 0
133+
index
131134
return (index,)
132135

133136

@@ -148,11 +151,11 @@ def _(mo):
148151
mo.md(r"""
149152
## Converting multiple GEF files to a relational database
150153
151-
Rather than dealing with a folder of files in a format that very few software can handle, we would like to combine all of these files into a single database with spatial information. This is where `bedrock-ge` comes in.
154+
Rather than dealing with a folder of files in a format that not much software can handle, we would like to combine all of these files into a single database with spatial information. This is where `bedrock-ge` comes in.
152155
153156
### Relational Databases
154157
155-
A [relational database](https://observablehq.com/blog/databases-101-basics-data-analysts#what-are-relational-databases) is a database with multiple tables that are linked to each other with relations. This type of database is ideal for storing GI data, given its [hierarchical structure](https://bedrock.engineer/docs/#hierarchical-nature-of-gi-data).
158+
A [relational database](https://observablehq.com/blog/databases-101-basics-data-analysts#what-are-relational-databases) is a database with multiple tables that are linked to each other with relations. This type of database is ideal for storing GI data, given its [hierarchical structure](https://bedrock.engineer/explanation/hierarchical-structure/).
156159
157160
In Python it's convenient to represent a relational database as a dictionary of DataFrames.
158161
@@ -166,9 +169,9 @@ def _(mo):
166169
@app.cell
167170
def _(CRS, boreholes):
168171
code = {bore.delivered_location.srs_name for bore in boreholes}.pop()
169-
orig_crs = CRS(code)
170-
orig_crs
171-
return (orig_crs,)
172+
projected_crs = CRS(code)
173+
projected_crs
174+
return (projected_crs,)
172175

173176

174177
@app.cell(hide_code=True)
@@ -177,7 +180,7 @@ def _(mo):
177180
The data is in EPSG:28992, which is the [Rijksdriehoekscoördinaten (NL)](https://nl.wikipedia.org/wiki/Rijksdriehoeksco%C3%B6rdinaten) system, also called "Amersfoort / RD New". This reference system does not include elevation.
178181
179182
To represent GI data spatially in 3D geometry we need a CRS **with elevation**. That's why we will use
180-
EPSG:5709 NAP height as the vertical CS.
183+
[EPSG:5709](https://epsg.org/crs_5709/NAP-height.html) "Normaal Amsterdams Peil (NAP) height" as the vertical reference system.
181184
""")
182185
return
183186

@@ -201,10 +204,10 @@ def _():
201204

202205

203206
@app.cell
204-
def _(orig_crs, pd, project_uid, vertical_crs):
207+
def _(pd, project_uid, projected_crs, vertical_crs):
205208
project = pd.DataFrame({
206209
"project_uid": [project_uid], # primary key
207-
"horizontal_crs_wkt": orig_crs.to_wkt(),
210+
"horizontal_crs_wkt": projected_crs.to_wkt(),
208211
"vertical_crs_wkt": vertical_crs.to_wkt(),
209212
})
210213
return (project,)
@@ -250,7 +253,7 @@ def _(locations_df):
250253
@app.cell(hide_code=True)
251254
def _(mo):
252255
mo.md(r"""
253-
Here we create a DataFrame for the In-Situ data of all GI locations. To relate the in-situ data to locations and the project, we add foreign keys.
256+
Here we create a DataFrame for the In-Situ data of all GI locations. To relate the in-situ data to locations and the project, we add foreign keys to each row.
254257
""")
255258
return
256259

@@ -277,12 +280,20 @@ def _(BedrockGIDatabase, insitu, locations_df, project):
277280
brgi_db = BedrockGIDatabase(
278281
Project=project,
279282
Location=locations_df.drop(columns=["data"]),
280-
InSituTests={"interpretation":insitu},
283+
InSituTests={"interpretation": insitu},
281284
)
282285
brgi_db
283286
return (brgi_db,)
284287

285288

289+
@app.cell(hide_code=True)
290+
def _(mo):
291+
mo.md(r"""
292+
Now let's convert the various tables (`Location`, `LonLatHeight`, `In-SituTests` ) into geospatial DataFrames with interpolated geometry data using `bedrock-ge`'s `create_brgi_geodb`.
293+
""")
294+
return
295+
296+
286297
@app.cell
287298
def _(brgi_db, create_brgi_geodb):
288299
brgi_geodb = create_brgi_geodb(brgi_db)
@@ -319,20 +330,22 @@ def _(mo):
319330
320331
321332
The reason for creating the `LonLatHeight` table is that vertical lines in projected Coordinate Reference Systems (CRS) are often not rendered nicely by default in all web-mapping software. Vertical lines are often not visible when looking at a map from above, and not all web-mapping software is capable of handling geometry in non-WGS84, i.e. (Lon, Lat) coordinates.
333+
334+
`brgi_geodb.LonLatHeight` is a GeoPandas GeoDataFrame, which has an `.explore()` utility method to view the data on a webmap.
322335
""")
323336
return
324337

325338

326339
@app.cell
327340
def _(brgi_geodb):
328-
brgi_geodb.LonLatHeight
341+
map = brgi_geodb.LonLatHeight.explore(marker_kwds={"radius":5})
342+
map
329343
return
330344

331345

332346
@app.cell
333347
def _(brgi_geodb):
334-
map = brgi_geodb.LonLatHeight.explore(marker_kwds={"radius":5})
335-
map
348+
brgi_geodb.LonLatHeight
336349
return
337350

338351

@@ -341,29 +354,41 @@ def _(mo):
341354
mo.md(r"""
342355
## Saving the GI geospatial database as a GeoPackage (.gpkg)
343356
344-
Finally, we'll write it to an actual geospatial database file, a [GeoPackage](https://www.geopackage.org/), so we can share our GI data with others, for example, to reuse it in other computational notebooks, create dashboards, access the GI data in QGIS or ArcGIS, and more...
357+
Finally, we'll write it to an actual geospatial database file, a [GeoPackage](https://www.geopackage.org/), so we can share our GI data with others, for example, to reuse it in other computational notebooks, create dashboard apps, access the GI data in QGIS or ArcGIS, and more...
358+
359+
A GeoPackage is an <abbr title="Open Geospatial Consortium">OGC-standardized</abbr> extension of SQLite, a relational database in a single file. SQLite is the most deployed database in the world, it's probably on every device you own.
345360
346-
A GeoPackage is an <abbr title="Open Geospatial Consortium">OGC-standardized</abbr> extension of SQLite (a relational database in a single file, .sqlite or .db) that allows you to store any type of GIS data (both raster as well as vector data) in a single file that has the .gpkg extension. Therefore, many (open-source) GIS software packages support GeoPackage!
361+
GeoPackage allows you to store any type of GIS data (both raster as well as vector data) in a single file that has the `.gpkg` extension. Therefore, many (open-source) GIS software packages support GeoPackage!
347362
""")
348363
return
349364

350365

351-
@app.cell
352-
def _(brgi_db, check_brgi_geodb):
353-
check_brgi_geodb(brgi_db)
366+
@app.cell(hide_code=True)
367+
def _(mo):
368+
mo.md(r"""
369+
`check_brgi_geodb` checks that all tables in the BedrockGI geospatial database conform to their respective schemas and that all foreign key relationships are properly maintained.
370+
""")
354371
return
355372

356373

357374
@app.cell
358-
def _(brgi_db, write_brgi_db_to_file):
359-
write_brgi_db_to_file(brgi_db, path="./output/A2_Maastricht.gpkg", driver="GPKG")
375+
def _(brgi_geodb, check_brgi_geodb):
376+
check_brgi_geodb(brgi_geodb)
360377
return
361378

362379

363380
@app.cell
381+
def _(brgi_geodb, os, write_brgi_db_to_file):
382+
os.makedirs('./output', exist_ok=True)
383+
384+
write_brgi_db_to_file(brgi_geodb, path="./output/A2_Maastricht.gpkg", driver="GPKG")
385+
return
386+
387+
388+
@app.cell(hide_code=True)
364389
def _(mo):
365390
mo.md(r"""
366-
## Visualising the Data in a 3D Webmap
391+
## Visualising the Data
367392
368393
As standardized geospatial data, we can visualize our GI in a wealth of ways.
369394
@@ -374,7 +399,7 @@ def _(mo):
374399
375400
### 3D Webmap with Cesium.js
376401
377-
View the data from this example interactively in a 3D webmap.
402+
View the data from this example interactively in a [3D webmap using CesiumJS](https://www.bedrock.engineer/maastricht-a2).
378403
""")
379404
return
380405

@@ -392,6 +417,7 @@ def _():
392417
import pyarrow
393418
import folium
394419
import mapclassify
420+
import numpy as np
395421
from shapely.geometry import Point, LineString
396422

397423
from bedrock_ge.gi.schemas import BedrockGIDatabase
@@ -410,6 +436,7 @@ def _():
410436
check_brgi_geodb,
411437
create_brgi_geodb,
412438
mo,
439+
os,
413440
pd,
414441
plot_bore,
415442
pygef,

0 commit comments

Comments
 (0)