1212 BedrockGIDatabase ,
1313 BedrockGIGeospatialDatabase ,
1414 InSituTestSchema ,
15+ LocationSchema ,
1516)
1617
1718
1819def create_brgi_geospatial_database (
1920 brgi_db : BedrockGIDatabase ,
2021) -> BedrockGIGeospatialDatabase :
22+ """Creates a Bedrock GI geospatial database from a Bedrock GI database.
23+
24+ Creates a Bedrock GI geospatial database by performing the following steps:
25+ 1. Creates a geospatial DataFrame for the Location table using the
26+ `create_location_geodf` function.
27+ 2. Creates a geospatial DataFrame for the LonLatHeight table using the
28+ `create_lon_lat_height_geodf` function.
29+ 3. Creates a dictionary of geospatial DataFrames for the In-Situ test tables
30+ using the `interpolate_gi_geometry` function.
31+ 4. Creates a geospatial DataFrame for the Sample table using the
32+ `interpolate_gi_geometry` function, if the Sample table exists.
33+ 5. Returns a BedrockGIGeospatialDatabase object.
34+
35+ Args:
36+ brgi_db (BedrockGIDatabase): The Bedrock GI database to be converted.
37+
38+ Returns:
39+ BedrockGIGeospatialDatabase: The resulting Bedrock GI geospatial database.
40+ """
2141 location_geodf = create_location_geodf (brgi_db )
2242 lon_lat_height_geodf = create_lon_lat_height_geodf (brgi_db )
2343 insitu_test_geodfs = {}
@@ -44,6 +64,23 @@ def create_brgi_geospatial_database(
4464
4565
4666def create_location_geodf (brgi_db : BedrockGIDatabase ) -> gpd .GeoDataFrame :
67+ """Creates a geospatial DataFrame for the Location table from a Bedrock GI database.
68+
69+ This function generates a GeoDataFrame for the Location table using the input
70+ Bedrock GI database. It assumes the boreholes are vertical (for now) and calculates
71+ elevation at the base of each borehole. It raises an error if multiple
72+ horizontal or vertical coordinate reference systems (CRS) are found in the
73+ project data.
74+
75+ Args:
76+ brgi_db (BedrockGIDatabase): The Bedrock GI database containing location
77+ data and project CRS information.
78+
79+ Returns:
80+ gpd.GeoDataFrame: A GeoDataFrame with LineString geometries representing
81+ vertical boreholes, using the compound CRS derived from the project's
82+ horizontal and vertical CRS.
83+ """
4784 # TODO: Implement logic to handle multiple CRS'es in the input GI data:
4885 # 1. Create WKT geometry for each location in original CRS
4986 # 2. Convert to WGS84 + EGM2008 orthometric height EPSG:9518
@@ -85,6 +122,23 @@ def create_location_geodf(brgi_db: BedrockGIDatabase) -> gpd.GeoDataFrame:
85122
86123
87124def create_lon_lat_height_geodf (brgi_db : BedrockGIDatabase ) -> gpd .GeoDataFrame :
125+ """Creates GeoDataFrame with (lon, lat, height) for each location in a Bedrock GI database.
126+
127+ This function processes all GI locations in a Bedrock GI database, transforming the
128+ (easting, northing, ground level elevation) coordinates to WGS84 (lon, lat)
129+ + EGM2008 orthometric height coordinates, which have coordinate reference system EPSG:9518.
130+ It returns a GeoDataFrame with the transformed longitude, latitude, and
131+ EGM2008 ground level height, along with the corresponding point geometries in EPSG:9518.
132+
133+ Args:
134+ brgi_db (BedrockGIDatabase): The source Bedrock Ground Investigation database
135+ containing location and project information.
136+
137+ Returns:
138+ gpd.GeoDataFrame: A GeoDataFrame with the transformed longitude, latitude,
139+ and EGM2008 ground level height, along with the corresponding point
140+ geometries in EPSG:9518.
141+ """
88142 wgs84_egm2008_crs = CRS ("EPSG:9518" )
89143 crs_lookup = brgi_db .Project .set_index ("project_uid" )
90144 dfs = []
@@ -128,11 +182,30 @@ def create_lon_lat_height_geodf(brgi_db: BedrockGIDatabase) -> gpd.GeoDataFrame:
128182
129183
130184def interpolate_gi_geometry (
131- insitu_test_df : DataFrame [InSituTestSchema ], location_geodf : gpd .GeoDataFrame
185+ insitu_test_df : DataFrame [InSituTestSchema ],
186+ location_geodf : DataFrame [LocationSchema ],
132187) -> gpd .GeoDataFrame :
188+ """Interpolates the geospatial geometry for a given In-Situ test DataFrame using its corresponding GI Location GeoDataFrame.
189+
190+ This function takes an In-Situ test DataFrame and a GI Location GeoDataFrame and
191+ returns a GeoDataFrame with its geometry interpolated from the location GeoDataFrame.
192+ The In-Situ test geometry is always a LineString or Point, depending on whether the
193+ In-Situ test is performed at a specific depth or over a depth interval inside a borehole.
194+ The geometry is calculated by linearly interpolating the depth values for each
195+ In-Situ test row between the top and bottom of the corresponding location's LineString geometry.
196+
197+ Args:
198+ insitu_test_df (DataFrame[InSituTestSchema]): The In-Situ test DataFrame
199+ containing the depth values to be interpolated.
200+ location_geodf (DataFrame[LocationSchema]): The location GeoDataFrame containing the
201+ location geometry to be used for interpolation.
202+
203+ Returns:
204+ gpd.GeoDataFrame: A GeoDataFrame containing the interpolated geospatial geometry
205+ for the In-Situ test DataFrame.
206+ """
133207 # TODO: implement a warning when interpolating GI geospatial geometry when
134208 # TODO: a single GI location has waaay too many rows in a certain In-Situ test.
135-
136209 geodf = location_geodf [["location_uid" , "geometry" ]].merge (
137210 insitu_test_df ,
138211 how = "right" ,
0 commit comments