Skip to content

Commit

Permalink
Coastal buffer now using DEP Coastline.
Browse files Browse the repository at this point in the history
  • Loading branch information
sopac committed Feb 5, 2025
1 parent bea2de5 commit f0ce29d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ def get_s2_ls(
def get_buffered_coastlines(ds, buffer) -> GeoDataFrame:
# coastal buffer
pyogrio.set_gdal_config_options({"OGR_GEOJSON_MAX_OBJ_SIZE": 0})
url = f"https://dep-public-staging.s3.us-west-2.amazonaws.com/aoi/country_lines_{str(buffer)}.geojson"
geojson = f"country_lines_{str(buffer)}.geojson"
download_if_not_exists(url, geojson)
buffer = gpd.read_file(geojson)
# url = f"https://dep-public-staging.s3.us-west-2.amazonaws.com/aoi/country_lines_{str(buffer)}.geojson"
url = f"https://dep-public-staging.s3.us-west-2.amazonaws.com/aoi/dep_country_lines_{str(buffer)}.gpkg"
geopkg = f"dep_country_lines_{str(buffer)}.gpkg"
download_if_not_exists(url, geopkg)
buffer = gpd.read_file(geopkg)
buffer = buffer.to_crs(4326)
ds = ds.rio.clip(buffer.geometry.values, buffer.crs, drop=True, invert=False)
return ds
Expand Down Expand Up @@ -192,7 +193,7 @@ def download_if_not_exists(url, filepath):
with open(filepath, mode="wb") as file:
for chunk in response.iter_content(chunk_size=10 * 1024):
file.write(chunk)
print(f"GeoJSON file downloaded and saved to: {filepath}")
print(f"Geo file downloaded and saved to: {filepath}")
except requests.exceptions.RequestException as e:
print(f"Error downloading JSON: {e}")
except Exception as e: # Catch other potential errors (like file writing)
Expand Down

0 comments on commit f0ce29d

Please sign in to comment.