Skip to content

Commit

Permalink
Ajoute une option filename
Browse files Browse the repository at this point in the history
  • Loading branch information
linogaliana committed Sep 19, 2024
1 parent 4787a60 commit de80660
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cartiflette/api/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def download_from_cartiflette_inner(
provider: str = "IGN",
dataset_family: str = "ADMINEXPRESS",
source: str = "EXPRESS-COG-TERRITOIRE",
filename: str = "raw",
return_as_json: bool = False,
*args,
**kwargs,
) -> typing.Union[gpd.GeoDataFrame, str]:
"""
Downloads and aggregates official geographic datasets using the Cartiflette API
Expand Down Expand Up @@ -97,6 +100,7 @@ def download_from_cartiflette_inner(
year=year,
crs=crs,
simplification=simplification,
filename=filename,
)
gdf_list.append(gdf_single)

Expand All @@ -123,6 +127,7 @@ def download_cartiflette_single(
value: typing.Union[str, int, float] = "28",
crs: typing.Union[list, str, int, float] = 2154,
simplification: typing.Union[str, int, float] = None,
filename: str = "raw",
*args,
**kwargs,
):
Expand All @@ -148,6 +153,7 @@ def download_cartiflette_single(
"dataset_family": dataset_family,
"source": source,
"simplification": simplification,
"filename": filename
}
)

Expand Down
8 changes: 6 additions & 2 deletions cartiflette/utils/create_path_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ConfigDict(TypedDict):
year: str
crs: Optional[int]
value: str
filename: Optional[str]


def create_path_bucket(config: ConfigDict) -> str:
Expand Down Expand Up @@ -55,13 +56,16 @@ def create_path_bucket(config: ConfigDict) -> str:
value = config.get("value")
crs = config.get("crs", 2154)
simplification = config.get("simplification", 0)
filename = config.get("filename")

if simplification is None:
simplification = 0

simplification = int(simplification)

filename = config.get("filename")
# Un hack pour modifier la valeur si jamais le pattern du filename n'est pas raw.{vectorfile_format}
if filename == "value":
filename = value

write_path = (
f"{bucket}/{path_within_bucket}"
Expand All @@ -78,7 +82,7 @@ def create_path_bucket(config: ConfigDict) -> str:
).replace("'", "")

if filename:
write_path += f"/{filename}"
write_path += f"/{filename}.{vectorfile_format}"
elif vectorfile_format == "shp":
write_path += "/"
else:
Expand Down

0 comments on commit de80660

Please sign in to comment.