|
2 | 2 | import pandas as pd |
3 | 3 | from pyproj import CRS, Transformer |
4 | 4 | from pyproj.crs import CompoundCRS |
| 5 | +from shapely.geometry import LineString |
5 | 6 |
|
6 | 7 | from bedrock_ge.gi.schemas import BedrockGIDatabase, BedrockGIGeospatialDatabase |
7 | 8 |
|
8 | 9 |
|
9 | 10 | 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 | + ) |
12 | 49 |
|
13 | 50 |
|
14 | 51 | 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: |
45 | 82 | lon_lat_height_df = pd.concat(dfs, ignore_index=True) |
46 | 83 | return gpd.GeoDataFrame( |
47 | 84 | lon_lat_height_df, |
48 | | - crs=wgs84_egm2008_crs, |
49 | 85 | geometry=gpd.points_from_xy( |
50 | 86 | lon_lat_height_df["longitude"], |
51 | 87 | lon_lat_height_df["latitude"], |
52 | 88 | lon_lat_height_df["egm2008_ground_level_height"], |
53 | 89 | ), |
| 90 | + crs=wgs84_egm2008_crs, |
54 | 91 | ) |
0 commit comments