Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions examples/geopackage/inspect_gpkg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "folium==0.19.5",
# "mapclassify==2.8.1",
# "matplotlib==3.9.4",
# "pandas==2.2.3",
# "shapely==2.0.7",
# ]
# ///

import marimo

__generated_with = "0.13.2"
app = marimo.App(width="medium")


@app.cell(hide_code=True)
def _():
from pathlib import Path

import geopandas as gpd
import marimo as mo
import pandas as pd
import pyogrio
from shapely import Point

return Path, Point, gpd, mo, pd, pyogrio


@app.cell
def _(Path):
gpkg_path = Path(
r"S:\Shared drives\Bedrock\Case Studies\A2TunnelMaastricht\data\A2_Maastricht.gpkg"
)
return (gpkg_path,)


@app.cell(hide_code=True)
def _(gpd, gpkg_path, pyogrio):
gpkg_layers = gpd.list_layers(gpkg_path)

brgi_geodb = {}
for layer in gpkg_layers["name"]:
brgi_geodb[layer] = pyogrio.read_dataframe(gpkg_path, layer=layer)

gpkg_layers
return (brgi_geodb,)


@app.cell(hide_code=True)
def _(brgi_geodb, mo):
sel_brgi_table = mo.ui.dropdown(brgi_geodb, value="Project")
mo.md(f"Select the Bedrock GI table you want to explore: {sel_brgi_table}")
return (sel_brgi_table,)


@app.cell(hide_code=True)
def _(pd, sel_brgi_table):
df = pd.DataFrame(sel_brgi_table.value.copy())
if "geometry" in df.columns:
df = df.assign(geometry=df.geometry.astype(str))

df
return


@app.cell(hide_code=True)
def _(Point, sel_brgi_table):
if "geometry" in sel_brgi_table.value.columns:
gdf = sel_brgi_table.value.copy()
gdf = gdf["geometry"].apply(lambda geom: Point(geom.coords[0]))
map = gdf.explore()
else:
map = f"The {sel_brgi_table.selected_key} table doesn't contain GIS geometry."

map
return


if __name__ == "__main__":
app.run()
2 changes: 1 addition & 1 deletion examples/hk_kaitak_ags3/hk_kaitak_ags3_to_brgi_geodb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "bedrock-ge==0.3.1",
# "bedrock-ge==0.3.2",
# "folium==0.20.0",
# "geopandas==1.1.0",
# "mapclassify==2.9.0",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bedrock-ge"
version = "0.3.1"
version = "0.3.2"
description = "Bedrock's Python library for geotechnical engineering."
authors = [
{name = "Bedrock", email = "[email protected]"}
Expand Down
2 changes: 1 addition & 1 deletion src/bedrock_ge/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Bedrock, the open source foundation for ground engineering."""

__version__ = "0.3.1"
__version__ = "0.3.2"
13 changes: 6 additions & 7 deletions src/bedrock_ge/gi/ags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ def ags_to_brgi_db_mapping(
"""Map AGS 3 or AGS 4 data to the Bedrock GI data model.

Args:
source (str | Path | IO[str] | IO[bytes] | bytes): The AGS file (str or Path)
or a file-like object that represents the AGS file.
projected_crs (CRS): Projected Coordinate Reference System (CRS). For example:
source: The AGS file (str or Path) or a file-like object that represents the AGS file.
projected_crs: Projected Coordinate Reference System (CRS). For example:
- OSGB36 / British National Grid: `pyproj.CRS("EPSG:27700")`
- Hong Kong 1980 Grid System: `pyproj.CRS("EPSG:2326")`
vertical_crs (CRS, optional): Vertical CRS. Defaults to EGM2008 height, EPSG:3855
vertical_crs: Vertical CRS. Defaults to EGM2008 height, EPSG:3855,
which measures the orthometric height w.r.t. the Earth Gravitational Model 2008.
- Ordnance Datum Newlyn (ODN) Height: `pyproj.CRS("EPSG:5701")`
- Hong Kong Principle Datum (HKPD) Height: `pyproj.CRS("EPSG:5738")`
encoding (str | None, optional): Encoding of the text file or bytes stream.
Defaults to None. An attempt at detecting the encoding will be made if None.
encoding: Encoding of the text file or bytes stream. Defaults to None.
An attempt at detecting the encoding will be made if None.

Raises:
ValueError: If the data does not match AGS 3 or AGS 4 format.

Returns:
BedrockGIDatabaseMapping: Object that maps AGS 3 or AGS 4 data to Bedrock GI data model.
Object that maps AGS 3 or AGS 4 data to Bedrock GI data model.
"""
if not encoding:
encoding = detect_encoding(source)
Expand Down
29 changes: 15 additions & 14 deletions src/bedrock_ge/gi/ags3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ def ags3_to_dfs(
make the rest of the code more generic.

Args:
source (str | Path | IO[str] | IO[bytes] | bytes): The AGS 3 file (str or Path)
or a file-like object that represents the AGS 3 file.
encoding (str): Encoding of file or object.
source: The AGS 3 file (str or Path) or a file-like object that represents the AGS 3 file.
encoding: Encoding of the text file or bytes stream.

Returns:
dict[str, pd.DataFrame]: A dictionary of pandas DataFrames, i.e. a database,
where each key is an AGS 3 group, and the corresponding value is
a pandas DataFrame containing the data for that group.
A dictionary of pandas DataFrames, i.e. a database, where each key is
an AGS 3 group, and the corresponding value is a pandas DataFrame
containing the data for that group.
"""
# Initialize dictionary and variables used in the AGS 3 read loop
ags3_dfs = {}
Expand Down Expand Up @@ -134,16 +133,18 @@ def ags3_to_brgi_db_mapping(
"""Map AGS 3 data to the Bedrock GI data model.

Args:
ags3_db (dict[str, pd.DataFrame]): A dictionary of pandas DataFrames, i.e. database,
where each key is an AGS 3 group, and the corresponding value is
a pandas DataFrame containing the data for that group.
projected_crs (CRS): Projected coordinate reference system (CRS).
vertical_crs (CRS, optional): Vertical CRS. Defaults to EGM2008 height, EPSG:3855
source: The AGS 3 file (str or Path) or a file-like object that represents the AGS 3 file.
projected_crs: Projected Coordinate Reference System (CRS). For example:
- OSGB36 / British National Grid: `pyproj.CRS("EPSG:27700")`
- Hong Kong 1980 Grid System: `pyproj.CRS("EPSG:2326")`
vertical_crs: Vertical CRS. Defaults to EGM2008 height, EPSG:3855,
which measures the orthometric height w.r.t. the Earth Gravitational Model 2008.
encoding (str): Encoding of the text file or bytes stream.
- Ordnance Datum Newlyn (ODN) Height: `pyproj.CRS("EPSG:5701")`
- Hong Kong Principle Datum (HKPD) Height: `pyproj.CRS("EPSG:5738")`
encoding: Encoding of the text file or bytes stream.

Returns:
BedrockGIDatabaseMapping: Object that maps AGS 3 data to Bedrock GI data model.
Object that maps AGS 3 data to Bedrock GI data model.
"""
ags3_dfs = ags3_to_dfs(source, encoding)

Expand Down Expand Up @@ -269,7 +270,7 @@ def _get_depth_columns(group: str, headers: list[str]) -> tuple[str | None, str
base_depth = None
if not top_depth and not base_depth:
raise ValueError(
'The in-situ test group "{group}" group in this AGS 3 file does not contain a top or base depth heading!'
f'The in-situ test group "{group}" group in this AGS 3 file does not contain a top or base depth heading!'
)

return top_depth, base_depth
Loading