mapchete.io package

Submodules

Module contents

Functions for reading and writing data.

mapchete.io.absolute_path(path=None, base_dir=None)

Return absolute path if path is local.

Parameters
pathpath to file
base_dirbase directory used for absolute path
Returns
absolute path
mapchete.io.copy(src_path, dst_path, src_fs=None, dst_fs=None, overwrite=False)

Copy path from one place to the other.

mapchete.io.fs_from_path(path, timeout=5, session=None, username=None, password=None, **kwargs)

Guess fsspec FileSystem from path and initialize using the desired options.

mapchete.io.get_best_zoom_level(input_file, tile_pyramid_type)

Determine the best base zoom level for a raster.

“Best” means the maximum zoom level where no oversampling has to be done.

Parameters
input_filepath to raster file
tile_pyramid_typeTilePyramid projection (geodetic or``mercator``)
Returns
zoominteger
mapchete.io.get_boto3_bucket(bucket_name)

Return boto3.Bucket object from bucket name.

mapchete.io.get_gdal_options(opts, is_remote=False, allowed_remote_extensions=[])

Return a merged set of custom and default GDAL/rasterio Env options.

If is_remote is set to True, the default GDAL_HTTP_OPTS are appended.

Parameters
optsdict or None

Explicit GDAL options.

is_remotebool

Indicate whether Env is for a remote file.

Returns
dictionary
mapchete.io.get_segmentize_value(input_file=None, tile_pyramid=None)

Return the recommended segmentation value in input file units.

It is calculated by multiplyling raster pixel size with tile shape in pixels.

Parameters
input_filestr

location of a file readable by rasterio

tile_pyramiedTilePyramid or BufferedTilePyramid

tile pyramid to estimate target tile size

Returns
segmenize valuefloat

length suggested of line segmentation to reproject file bounds

mapchete.io.makedirs(path, fs=None)

Silently create all subdirectories of path if path is local.

Parameters
pathpath
mapchete.io.path_exists(path, fs=None, **kwargs)

Check if file exists either remote or local.

Parameters
pathpath to file
Returns
existsbool
mapchete.io.path_is_remote(path, s3=True)

Determine whether file path is remote or local.

Parameters
pathpath to file
Returns
is_remotebool
mapchete.io.read_json(path, fs=None, **kwargs)

Read local or remote.

mapchete.io.relative_path(path=None, base_dir=None)

Return relative path if path is local.

Parameters
pathpath to file
base_dirdirectory where path sould be relative to
Returns
relative path
mapchete.io.tile_to_zoom_level(tile, dst_pyramid=None, matching_method='gdal', precision=8)

Determine the best zoom level in target TilePyramid from given Tile.

Parameters
tileBufferedTile
dst_pyramidBufferedTilePyramid
matching_methodstr (‘gdal’ or ‘min’)
gdal: Uses GDAL’s standard method. Here, the target resolution is calculated by

averaging the extent’s pixel sizes over both x and y axes. This approach returns a zoom level which may not have the best quality but will speed up reading significantly.

min: Returns the zoom level which matches the minimum resolution of the extent’s

four corner pixels. This approach returns the zoom level with the best possible quality but with low performance. If the tile extent is outside of the destination pyramid, a TopologicalError will be raised.

precisionint

Round resolutions to n digits before comparing.

Returns
zoomint
mapchete.io.tiles_exist(config=None, output_tiles=None, output_tiles_batches=None, process_tiles=None, process_tiles_batches=None, **kwargs)

Yield tiles and whether their output already exists or not.

Either “output_tiles” or “process_tiles” have to be provided.

The S3 part of the function are loosely inspired by https://alexwlchan.net/2019/07/listing-s3-keys/

Parameters
configmapchete.config.MapcheteConfig
process_tilesiterator
Yields
tuple(tile, exists)
mapchete.io.write_json(path, params, fs=None, **kwargs)

Write local or remote.