Cloud Optimized Geotiff to H3 Cell
This script processes Cloud Optimized GeoTIFFs (COGs) and converts them to H3 hexagonal grids, storing the results in a PostgreSQL database. It supports multi-band rasters, resampling, and various processing options.
Features
- Download and process COGs from URLs
- Convert raster data to H3 hexagons
- Support for multi-band rasters
- Customizable H3 resolution
- Various resampling methods
- Option to preserve raster value range during resampling
- Efficient database storage using PostgreSQL
Prerequisites
-
Python 3.7+
-
PostgreSQL database
-
Ensure your input COG is in WGS 1984 projection. If not, reproject it using gdalwarp
gdalwarp -overwrite input.tif output.tif -s_srs EPSG:32645 -t_srs EPSG:4326
- Set nodata values to 0 using
gdalwarp,
gdalwarp -dstnodata 0 input.tif output.tif
- Convert a GeoTIFF to COG format:
gdal_translate -of COG input.tif output_cog.tif
This all preprocessing step is included in ./pre.sh bash script
Environment Variables
Set the following environment variables or use default values:
DATABASE_URL: PostgreSQL connection string (default: "postgresql://postgres:postgres@localhost:5432/postgres")STATIC_DIR: Directory to store downloaded COGs (default: "static")
Example:
export DATABASE_URL="postgresql://user:password@host:port/database"
export STATIC_DIR="/path/to/cog/storage"
Usage
Run the script with the following command:
python cog2h3.py --cog <COG_URL> --table <TABLE_NAME> [OPTIONS]
Required Arguments:
--cog: URL of the Cloud Optimized GeoTIFF (must be in WGS84 projection)--table: Name of the database table to store results
Optional Arguments:
--res: H3 resolution level (default: 8)--preserve_range: Preserve the value range of the raster while resampling--multiband: Process all bands of a multi-band raster--sample_by: Resampling method (default: "bilinear")
Available resampling methods: nearest, bilinear, cubic, cubic_spline, lanczos, average, mode, gauss, max, min, med, q1, q3, sum, rms
Example:
python cog2h3.py --cog my-cog.tif --table cog_h3 --res 8
Contribute
Contributions are Welcome ! स्वागतम
Metadata
Release files for cog2h3 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cog2h3-0.0.3.tar.gz | 17.9 kB | Without provenance | Details for cog2h3-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cog2h3-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for cog2h3-0.0.3-py3-none-any.whl |
Total release size: 36.6 kB
Release files / cog2h3-0.0.3.tar.gz
| Download URL | cog2h3-0.0.3.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19f70660052ba640dad0d8f4fd71a24ccff83fc3f7d1d3c1302ceff0ace210e6
|
|
BLAKE2b-256 checksum How to use checksums |
f0c8c011489625de432fb629a41ea2ac4f205607dc85610ce9249c99805a6a86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / cog2h3-0.0.3-py3-none-any.whl
| Download URL | cog2h3-0.0.3-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
284abd3f85a1c1148e119d7ad5966fe9b5a7fd25ae80eab344a0e0d8a8d22fe9
|
|
BLAKE2b-256 checksum How to use checksums |
516a80a39f9c07accc8a4423c6ff261019a133f06625b201acf3faca11a78e47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Security for cog2h3 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.