def test_utils_py_0(): for b in (False, 'False', 'OfF', 'no'): assert not base.is_true(b) for b in (True, 'TruE', 'ON', 'yes'): assert base.is_true(b) assert base.enum_to_str(Extent.UNION) == 'UNION' assert base.enum_to_str('UNION') == 'UNION' filename = Path('abc') / Path('def') / Path('a.txt') assert base.is_path_like(Path(filename)) assert base.is_path_like(str(filename)) assert not base.is_path_like(None) assert not base.is_path_like([filename]) assert base.get_suffix(filename) == '.txt' assert base.get_extension(filename) == 'txt' for idx, b in enumerate((0x23, 0xc1, 0xab, 0x00)): byte = base.get_byte(0xab_c1_23, idx) assert byte == b assert base.path_join(filename, 'a', 'b') == str(filename / 'a' / 'b') assert base.num(42) == 42 assert base.num('42') == 42 assert isinstance(base.num('42'), int) assert base.num(42.0) == 42.0 assert base.num('42.0') == 42.0 assert isinstance(base.num('42.0'), float) assert base.num('42.') == 42.0 assert isinstance(base.num('42.'), float) assert base.num(42.5) == 42.5 assert base.num('42.5') == 42.5 assert base.num_or_none('') is None assert base.num_or_none(None) is None assert base.num_or_none('1a') is None assert base.num_or_none('42') == 42 assert base.num_or_none('42.0') == 42.0
def gdalos_make_vrt( filenames: MaybeSequence[PathOrDS], filenames_expand: Optional[bool] = None, vrt_path=None, kind=None, resampling_alg=..., overwrite=True, vrt_options: Optional[dict] = None, logger=None, ): if gdalos_util.is_list_like(filenames): flatten_filenames = gdalos_util.flatten_and_expand_file_list(filenames, do_expand_glob=filenames_expand) else: flatten_filenames = [filenames] flatten_filenames = [str(f) if isinstance(f, Path) else f for f in flatten_filenames] if not flatten_filenames: return None first_filename = flatten_filenames[0] if vrt_path is None: vrt_path = f'/vsimem/{uuid.uuid4()}.vrt' elif vrt_path is ...: vrt_path = first_filename + ".vrt" else: vrt_path = str(vrt_path) is_vsimem = vrt_path.startswith('/vsimem/') if not is_vsimem: if os.path.isdir(vrt_path): vrt_path = os.path.join(vrt_path, os.path.basename(first_filename) + ".vrt") if do_skip_if_exists(vrt_path, overwrite, logger): return vrt_path if os.path.isfile(vrt_path): raise Exception("could not delete vrt file: {}".format(vrt_path)) os.makedirs(os.path.dirname(vrt_path), exist_ok=True) vrt_options = dict(vrt_options or dict()) if resampling_alg is None: if kind in [None, ...]: kind = RasterKind.guess(first_filename) resampling_alg = kind.resampling_alg_by_kind(kind) if resampling_alg is not ...: vrt_options["resampleAlg"] = enum_to_str(resampling_alg) vrt_options = gdal.BuildVRTOptions(**vrt_options) ds = gdal.BuildVRT(vrt_path, flatten_filenames, options=vrt_options) return vrt_path, ds
def get_ext_by_of(of: str): ext = enum_to_str(of).lower() if ext in ['gtiff', 'cog', 'mem']: ext = 'tif' return '.' + ext