Skip to content

Commit

Permalink
add the reference area function to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaelicke committed Oct 22, 2024
1 parent 3937fe5 commit ca748bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from concurrent.futures import ThreadPoolExecutor as PoolExecutor

from json2args import get_parameter
from json2args.logger import logger
from dotenv import load_dotenv
from metacatalog import api
from tqdm import tqdm

from param import load_params
from loader import load_entry_data
from json2args.logger import logger
from clip import reference_area_to_file
from utils import reference_area_to_file
from version import __version__

# always load .env files
Expand Down
23 changes: 23 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from pathlib import Path

import geopandas as gpd
from json2args.logger import logger

from param import load_params

# define a handler for whiteboxgis tools verbose output
def whitebox_log_handler(msg: str):
# following https://www.whiteboxgeo.com/manual/wbt_book/python_scripting/tool_output.html
Expand All @@ -10,3 +15,21 @@ def whitebox_log_handler(msg: str):
logger.error(f"WhiteboxTools Errored: {msg}")
else:
logger.debug(f"WhiteboxTools info: {msg}")


def reference_area_to_file(add_ascii: bool = False) -> str:
params = load_params()

# create a geodataframe
df = gpd.GeoDataFrame.from_features([params.reference_area])

# save the reference area as a geojson file
path = Path(params.base_path) / 'reference_area.geojson'
df.to_file(path, driver='GeoJSON')

# save the coordinates to a ascii file
if add_ascii:
path = Path(params.base_path) / 'reference_area.ascii'
df.get_coordinates().to_csv(path, sep=' ', header=False, index=False)

return str(path)

0 comments on commit ca748bc

Please sign in to comment.