Skip to content

Commit 142f000

Browse files
committed
Implement location_gis_geometry function
1 parent ef22666 commit 142f000

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

examples/hk_kaitak_ags3/hk_kaitak_ags3_to_brgi_geodb.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,17 @@ def _():
291291

292292
@app.cell
293293
def _(brgi_db):
294-
from bedrock_ge.gi.geospatial import create_lon_lat_height_table
294+
from bedrock_ge.gi.geospatial import create_lon_lat_height_table, location_gis_geometry
295295

296296
lon_lat_height_gdf = create_lon_lat_height_table(brgi_db)
297297
lon_lat_height_gdf.explore()
298+
return (location_gis_geometry,)
299+
300+
301+
@app.cell
302+
def _(brgi_db, location_gis_geometry):
303+
location_gdf = location_gis_geometry(brgi_db)
304+
location_gdf.explore()
298305
return
299306

300307

src/bedrock_ge/gi/geospatial.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,50 @@
22
import pandas as pd
33
from pyproj import CRS, Transformer
44
from pyproj.crs import CompoundCRS
5+
from shapely.geometry import LineString
56

67
from bedrock_ge.gi.schemas import BedrockGIDatabase, BedrockGIGeospatialDatabase
78

89

910
def location_gis_geometry(brgi_db: BedrockGIDatabase) -> gpd.GeoDataFrame:
10-
location_gdf = brgi_db.Location
11-
return location_gdf
11+
# TODO: Implement logic to handle multiple CRS'es in the input GI data:
12+
# 1. Create WKT geometry for each location in original CRS
13+
# 2. Convert to WGS84 + EGM2008 orthometric height EPSG:9518
14+
# 3. Interpolate InSituTest and Sample geospatial vector geometry from active geometry column
15+
hor_crs = brgi_db.Project["horizontal_crs_wkt"]
16+
vert_crs = brgi_db.Project["vertical_crs_wkt"]
17+
if hor_crs.nunique() > 1 or vert_crs.nunique() > 1:
18+
raise ValueError(
19+
"All projects must have the same horizontal and vertical CRS (Coordinate Reference System).\n"
20+
"Raise an issue on GitHub in case you need to be able to combine GI data that was acquired in multiple different CRSes."
21+
)
22+
23+
hor_crs = CRS.from_wkt(hor_crs.iat[0])
24+
vert_crs = CRS.from_wkt(vert_crs.iat[0])
25+
compound_crs = CompoundCRS(
26+
name=f"{hor_crs.name} + {vert_crs.name}",
27+
components=[hor_crs, vert_crs],
28+
)
29+
30+
# TODO: Implement logic such that inclined borholes are handled correctly.
31+
# All boreholes are now assumed to be vertical.
32+
location_df = brgi_db.Location.copy()
33+
location_df["elevation_at_base"] = (
34+
location_df["ground_level_elevation"] - location_df["depth_to_base"]
35+
)
36+
return gpd.GeoDataFrame(
37+
brgi_db.Location.copy(),
38+
geometry=location_df.apply(
39+
lambda row: LineString(
40+
[
41+
(row["easting"], row["northing"], row["ground_level_elevation"]),
42+
(row["easting"], row["northing"], row["elevation_at_base"]),
43+
]
44+
),
45+
axis=1,
46+
),
47+
crs=compound_crs,
48+
)
1249

1350

1451
def create_lon_lat_height_table(brgi_db: BedrockGIDatabase) -> gpd.GeoDataFrame:
@@ -45,10 +82,10 @@ def create_lon_lat_height_table(brgi_db: BedrockGIDatabase) -> gpd.GeoDataFrame:
4582
lon_lat_height_df = pd.concat(dfs, ignore_index=True)
4683
return gpd.GeoDataFrame(
4784
lon_lat_height_df,
48-
crs=wgs84_egm2008_crs,
4985
geometry=gpd.points_from_xy(
5086
lon_lat_height_df["longitude"],
5187
lon_lat_height_df["latitude"],
5288
lon_lat_height_df["egm2008_ground_level_height"],
5389
),
90+
crs=wgs84_egm2008_crs,
5491
)

0 commit comments

Comments
 (0)