1
1
import os
2
2
import warnings
3
3
from numbers import Number
4
+ from os import PathLike
4
5
5
6
import geopandas as gpd
6
7
import numpy as np
22
23
def cell_based_association (
23
24
cell_size : int ,
24
25
geodata : List [gpd .GeoDataFrame ],
25
- output_path : str ,
26
+ output_path : Union [ str , PathLike ] ,
26
27
column : Optional [List [str ]] = None ,
27
28
subset_target_attribute_values : Optional [List [Union [None , list , str ]]] = None ,
28
29
add_name : Optional [List [Union [str , None ]]] = None ,
@@ -39,7 +40,8 @@ def cell_based_association(
39
40
cell_size: Size of the cells.
40
41
geodata: GeoDataFrame to create the CBA matrix. Additional
41
42
GeoDataFrame(s) can be imputed to add to the CBA matrix.
42
- output_path: Name of the saved .tif file.
43
+ output_path: Name of the saved .tif file. Include file extension (.tif)
44
+ in the path.
43
45
column: Name of the column of interest. If no attribute is specified,
44
46
then an artificial attribute is created representing the presence
45
47
or absence of the geometries of this file for each cell of the CBA
@@ -528,14 +530,14 @@ def _to_csv(cba: gpd.GeoDataFrame, output_path: str) -> None:
528
530
529
531
530
532
@beartype
531
- def _to_raster (cba : gpd .GeoDataFrame , output_path : str , nan_val : int = - 9999 ) -> None :
533
+ def _to_raster (cba : gpd .GeoDataFrame , output_path : Union [ str , PathLike ] , nan_val : int = - 9999 ) -> None :
532
534
"""Intermediate utility.
533
535
534
536
Saves the object as a raster TIFF file.
535
537
536
538
Args:
537
539
cba: CBA matrix to save.
538
- output_path: Name of the saved file.
540
+ output_path: Name of the saved file, include file extension (.tif) .
539
541
nan_val: values taken by cells with no values in them (outside the study
540
542
area).
541
543
@@ -579,7 +581,7 @@ def _to_raster(cba: gpd.GeoDataFrame, output_path: str, nan_val: int = -9999) ->
579
581
transform = rasterio .transform .from_bounds (min_x , min_y , max_x , max_y , width = width , height = height )
580
582
581
583
with rasterio .open (
582
- output_path + ".tif" ,
584
+ output_path ,
583
585
mode = "w" ,
584
586
driver = "GTiff" ,
585
587
height = height ,
0 commit comments