Skip to content

Commit 811a254

Browse files
Merge pull request #18 from supathdhitalGEO/main
update the automatic finding the HUC8 ID with user defined boundary m…
2 parents 90554c4 + a2b8d2c commit 811a254

File tree

7 files changed

+1022
-921
lines changed

7 files changed

+1022
-921
lines changed

dist/fimserve-0.1.80-py3-none-any.whl

42.5 KB
Binary file not shown.

dist/fimserve-0.1.80.tar.gz

71.6 KB
Binary file not shown.

poetry.lock

Lines changed: 962 additions & 920 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fimserve"
3-
version = "0.1.79"
3+
version = "0.1.80"
44
description = "Framework which is developed with the purpose of quickly generating Flood Inundation Maps (FIM) for emergency response and risk assessment. It is developed under Surface Dynamics Modeling Lab (SDML)."
55
authors = ["Supath Dhital <sdhital@crimson.ua.edu>"]
66
license = "GPL-3.0"

src/fimserve/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@
2828

2929
# Statistics
3030
from .statistics.calculatestatistics import CalculateStatistics
31+
32+
#For intersected HUC8 boundary
33+
from .intersectedHUC import getIntersectedHUC8ID

src/fimserve/intersectedHUC.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import s3fs
3+
import tempfile
4+
from pathlib import Path
5+
import geopandas as gpd
6+
from io import BytesIO
7+
import fsspec
8+
9+
# Initialize anonymous S3 filesystem
10+
fs = s3fs.S3FileSystem(anon=True)
11+
12+
# FINDING THE INTERSECTED HUC8
13+
def find_intersecting_huc8ID(huc8_gdf, user_boundary_path):
14+
user_gdf = gpd.read_file(user_boundary_path)
15+
if user_gdf.crs != "EPSG:4326":
16+
user_gdf = user_gdf.to_crs("EPSG:4326")
17+
intersecting = gpd.overlay(huc8_gdf, user_gdf, how='intersection')
18+
19+
if intersecting.empty:
20+
return "No HUC8 region intersects with the user-defined boundary."
21+
22+
output = ["Your boundary falls within:\n----------------------------------"]
23+
for _, row in intersecting.iterrows():
24+
output.append(f"HUC8 - {row['HUC8']}\nNAME - {row['name']}\n")
25+
return "\n".join(output)
26+
27+
# GETTING THE HUC8 BOUNDARIES FROM S3
28+
def HUC8_inS3(fs, bucket, prefix="HUC8_boundaries/"):
29+
# List available files
30+
files = fs.ls(f"{bucket}/{prefix}")
31+
gpkg_key = next((f for f in files if f.endswith('.gpkg')), None)
32+
33+
if gpkg_key is None:
34+
raise FileNotFoundError(f"No .gpkg file found in s3://{bucket}/{prefix}")
35+
36+
# Read file into temporary file
37+
with fs.open(gpkg_key, 'rb') as s3file:
38+
with tempfile.NamedTemporaryFile(suffix=".gpkg", delete=False) as tmp_file:
39+
tmp_file.write(s3file.read())
40+
tmp_path = tmp_file.name
41+
42+
gdf = gpd.read_file(tmp_path)
43+
return gdf
44+
45+
# WRAPPING ALL FUNCTIONS
46+
def getIntersectedHUC8ID(user_boundary):
47+
bucket_name = "sdmlab"
48+
HUC8_gdf = HUC8_inS3(fs, bucket_name)
49+
HUC8 = find_intersecting_huc8ID(HUC8_gdf, user_boundary)
50+
return HUC8

tests/test_intersectedHUC8.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import fimserve as fm
2+
3+
user_boundary = '/Users/supath/Downloads/MSResearch/FIMpef/CodeUsage/SampleData/Data/Neuse/FIMEvaluatedExtent.shp'
4+
5+
summary = fm.getIntersectedHUC8ID(user_boundary)
6+
print(summary)

0 commit comments

Comments
 (0)