COG Conversion¶
geoembed.images.cog
¶
Cloud Optimised GeoTIFF (COG) conversion pipeline.
Converts standard GeoTIFFs to COGs with internal tiling, compression, and overviews for efficient cloud-based partial reads (HTTP range requests).
Includes a Spark-based pipeline for distributed conversion on Databricks.
FileSystemAdapter
¶
Bases: ABC
Abstract filesystem operations for testability.
LocalFileSystem
¶
ImageConverter
¶
Bases: ABC
Abstract interface for image format conversion.
RioCogConverter(compression='deflate', blocksize=512, overview_resampling='nearest')
¶
Bases: ImageConverter
Converts GeoTIFFs to COGs optimised for high-throughput GPU inference.
Based on Microsoft's COG throughput findings (Zaytar et al., 2025):
Compression choice depends on storage type: - LOCAL STORAGE: "none" (uncompressed) is 1.3-1.6x faster because CPU decompression is the bottleneck when reading from fast local disk/SSD. - REMOTE/CLOUD STORAGE: "lerc_zstd" is optimal — balances network transfer reduction (good compression ratio) with fast CPU decompression. - "deflate" is a safe middle ground for mixed local/remote workflows.
Tiling: - 512x512 internal tiles enable tile-aligned reads. A 224px chip falls entirely within one tile, requiring exactly one decompression. - Misaligned reads force decompression of up to 4 adjacent tiles.
Overviews: - Embedded reduced-resolution pyramids for fast wide-area previews.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compression
|
str
|
Compression codec. Recommendations: - "none": Fastest local reads (no decompression overhead). Largest files. - "deflate": Good default. Moderate compression + decode speed. - "lerc_zstd": Best for remote/cloud (high compression, fast decode). - "lzw": Legacy option, similar to deflate. |
'deflate'
|
blocksize
|
int
|
Internal tile size. Must be 256 or 512 for tile-aligned reads. 512 recommended — a 224px chip fits within one tile. |
512
|
overview_resampling
|
str
|
Resampling for overviews. "nearest" preserves spectral accuracy; "average" for smoother visual previews. |
'nearest'
|
Source code in src/geoembed/images/cog.py
convert(src, dst)
¶
Convert a GeoTIFF to a GPU-cloud-friendly COG.
Generates a COG with internal 512x512 tiling, compression, and overviews.
Source code in src/geoembed/images/cog.py
CogConfig(input_table, output_table, dst_root, compression='deflate', blocksize=512, files_per_task=10)
dataclass
¶
Configuration for the COG conversion pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
input_table |
str
|
Source table with image metadata (path column required). |
output_table |
str
|
Table to log conversion results. |
dst_root |
str
|
Destination directory for COG files. |
compression |
str
|
Compression codec. |
blocksize |
int
|
Internal tile size. |
files_per_task |
int
|
Files to process per Spark task. |
CogTaskHandler(converter=None, fs=None, dst_root='/tmp/cog_output')
¶
Handles COG conversion for a batch of files.
Writes to a unique local temp directory (NVMe /local_disk0 on Databricks), then copies the validated COG to the UC Volume destination.
Source code in src/geoembed/images/cog.py
process_file(src_path)
¶
Convert a single file to COG.
Uses a unique temp directory per file to avoid collisions when multiple Spark tasks run concurrently on the same executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_path
|
str
|
Path to the source GeoTIFF. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys: src, status, error. |
Source code in src/geoembed/images/cog.py
SparkCogWorker(config)
¶
SparkCogPipeline(spark, config)
¶
Distributed COG conversion pipeline for Databricks.
Scans a volume for GeoTIFFs, distributes conversion across Spark workers using mapInPandas, and writes COGs to a destination volume.
Usage
from geoembed.images.cog import SparkCogPipeline, CogConfig
config = CogConfig( input_table="catalog.schema.imagery_metadata", output_table="catalog.schema.cog_log", dst_root="/Volumes/catalog/data/processed/COG", compression="deflate", ) pipeline = SparkCogPipeline(spark, config) pipeline.run()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spark
|
Any
|
Active SparkSession. |
required |
config
|
CogConfig
|
COG conversion configuration. |
required |
Source code in src/geoembed/images/cog.py
run()
¶
Run COG conversion from an existing metadata table.
Reads image_path column from config.input_table.
Source code in src/geoembed/images/cog.py
run_from_volume(volume_path, glob_pattern='*.tif')
¶
Run COG conversion by scanning a Unity Catalog Volume for GeoTIFFs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume_path
|
str
|
Path to the UC Volume. |
required |
glob_pattern
|
str
|
File glob pattern (default: "*.tif"). |
'*.tif'
|