|
11 | 11 |
|
12 | 12 | import geopandas as gpd
|
13 | 13 | import pandas as pd
|
| 14 | +from dotenv import load_dotenv |
14 | 15 |
|
15 | 16 | from heal_bridges_osm import flows_from_hydrotable
|
16 | 17 | from utils.shared_functions import progress_bar_handler
|
17 | 18 |
|
18 | 19 |
|
| 20 | +load_dotenv('/foss_fim/src/bash_variables.env') |
| 21 | +DEFAULT_FIM_PROJECTION_CRS = os.getenv('DEFAULT_FIM_PROJECTION_CRS') |
| 22 | +ALASKA_CRS = os.getenv('ALASKA_CRS') |
| 23 | + |
| 24 | + |
19 | 25 | class HucDirectory(object):
|
20 | 26 | def __init__(self, fim_directory, huc_id, limit_branches=[]):
|
21 | 27 | self.fim_directory = fim_directory
|
@@ -205,7 +211,9 @@ def aggregate_bridge_pnts(self, branch_path, branch_id):
|
205 | 211 | if not os.path.isfile(bridge_filename):
|
206 | 212 | return
|
207 | 213 |
|
208 |
| - bridge_pnts = gpd.read_file(bridge_filename, dtype=self.bridge_dtypes) |
| 214 | + bridge_pnts = gpd.read_file(bridge_filename) |
| 215 | + for col, dtype in self.bridge_dtypes.items(): |
| 216 | + bridge_pnts[col] = bridge_pnts[col].astype(dtype) |
209 | 217 | if bridge_pnts.empty:
|
210 | 218 | return
|
211 | 219 | hydrotable_filename = join(branch_path, f'hydroTable_{branch_id}.csv')
|
@@ -289,6 +297,15 @@ def agg_function(
|
289 | 297 | ] = 1
|
290 | 298 | # Write file
|
291 | 299 | bridge_pnts = bridge_pnts.astype(self.bridge_dtypes, errors='ignore')
|
| 300 | + |
| 301 | + # Set the CRS if it is not already set |
| 302 | + huc2Identifier = huc_id[:2] |
| 303 | + if bridge_pnts.crs is None: |
| 304 | + # Alaska |
| 305 | + if huc2Identifier == '19': |
| 306 | + bridge_pnts.set_crs(ALASKA_CRS, inplace=True) |
| 307 | + else: |
| 308 | + bridge_pnts.set_crs(DEFAULT_FIM_PROJECTION_CRS, inplace=True) |
292 | 309 | bridge_pnts.to_file(bridge_pnts_file, index=False, engine='fiona')
|
293 | 310 |
|
294 | 311 | # print(f"agg_by_huc for huc id {huc_id} is done")
|
|
0 commit comments