docker run --name titiler -v /home/sia/workspace/titiler/data/COG/1:/scenes \\
-p 8000:8000 \\
--env PORT=8000 \\
--env WORKERS_PER_CORE=1 \\
--rm -it ghcr.io/developmentseed/titiler:latest
git clone <https://github.com/developmentseed/titiler.git>
pip install titiler
cd titiler/src/
uvicorn titiler.application.main:app
preview
<http://localhost:8000/cog/preview.tif?url=file:///{scene_path}>
thumbnail
<http://localhost:8000/cog/thumbnail?url=file:///{scene_path}>
WMTS
<http://localhost:8000/cog/WMTSCapabilities.xml?url=file:///{scene_path}>
from rio_cogeo.cogeo import cog_translate, cog_validate
from rio_cogeo.profiles import cog_profiles
import time
import os
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def translate_to_cog(
src_path: str,
member_id: str,
scene_root_path: str = SCENE_ROOT_PATH,
cog_local_directory: str = SCENE_COG_LOCAL_DIRECTORY,
profile: str = "deflate",
profile_options: dict = dict(),
**options,
) -> str:
start_time = time.time()
src_file_name, src_file_ext = os.path.splitext(os.path.basename(src_path))
dst_file_name = src_file_name + "_COG" + src_file_ext
dst_path = os.path.join(scene_root_path, cog_local_directory, member_id)
if os.path.exists(dst_path) == False:
try:
os.makedirs(dst_path)
except FileExistsError:
pass
dst_path = os.path.join(dst_path, dst_file_name)
if os.path.exists(dst_path):
logger.warning(
f"COG file with the same name [{dst_file_name}] already exists and will be overwritten"
)
os.remove(dst_path)
logger.info(f"COG translation of file [{dst_file_name}] begins")
try:
# Format creation option (see gdalwarp `-co` option)
output_profile = cog_profiles.get(profile)
output_profile.update(dict(BIGTIFF="IF_SAFER"))
output_profile.update(profile_options)
# Dataset Open option (see gdalwarp `-oo` option)
config = dict(
GDAL_NUM_THREADS="ALL_CPUS",
GDAL_TIFF_INTERNAL_MASK=False,
GDAL_TIFF_OVR_BLOCKSIZE="128",
)
cog_translate(
src_path,
dst_path,
output_profile,
config=config,
in_memory=False,
quiet=False,
**options,
)
dest_path_lib = Path(dst_path)
is_valid, errors, warnings = cog_validate(dest_path_lib)
if not is_valid:
if len(errors) > 0:
dest_path_lib.unlink()
raise FailToValidateCog(errors, warnings)
except Exception as e:
remark = traceback.format_exc()
logger.error(remark)
finally:
logger.info(
f"Scene {src_path} translated to COG in ### {time.time() - start_time} ### sec."
)
return dst_path
SCENE_ROOT_PATH = '/nas/k8s/dev/data/workspace-hkb/data'
SCENE_COG_LOCAL_DIRECTORY = 'cog'
src_path = 'scene_path'
member_id = '1'
dst_path = translate_to_cog(src_path, member_id)
print(dst_path)