How to get Copernicus DEM GeoTIFFs for a bounding box using Python


According to AWS’s Copernicus Digital Elevation Model page,

The Copernicus DEM is a Digital Surface Model (DSM) which represents the surface of the Earth including buildings, infrastructure and vegetation. We provide two instances of Copernicus DEM named GLO-30 Public and GLO-90. […] Data is provided as Cloud Optimized GeoTIFFs.


I would like to access these GeoTIFFs, using Python. I would like to be able to specify a bounding box, and get those GeoTIFFs which overlap or intersect with that bounding box.

My attempts

1) Access AWS directly

After installing boto3 (with pip3 install boto3), I do,

import boto3
from botocore import UNSIGNED
from botocore.client import Config

s3 = boto3.client('s3', region_name='eu-central-1', config=Config(signature_version=UNSIGNED))

Then I query for list of objects in the bucket:

objects = s3.list_objects(Bucket='copernicus-dem-30m')

I get a dict, with keys:

# outputs: dict_keys(['ResponseMetadata', 'IsTruncated', 'Marker', 'Contents', 'Name', 'Prefix', 'MaxKeys', 'EncodingType'])

I access Contents, which is a list, so viewing the first element:


I get:

{'ETag': '"e0c8b05f7999eedd83ba85e5c94cb670"',
 'Key': 'Copernicus_DSM_COG_10_N00_00_E006_00_DEM/Copernicus_DSM_COG_10_N00_00_E006_00_DEM.tif',
 'LastModified': datetime.datetime(2020, 11, 25, 7, 51, 3, tzinfo=tzlocal()),
 'Size': 3706379,
 'StorageClass': 'STANDARD'}

Viewing objects['Contents'][0]['Key'] gives me Copernicus_DSM_COG_10_N00_00_E006_00_DEM/Copernicus_DSM_COG_10_N00_00_E006_00_DEM.tif, which is a string. So this didn’t got me much closer to accessing the actual TIFF data in a Python notebook.

2) Using the opentopography website

Googling “search in GLO-30 bucket” lead me to OpenTopography’s search map. After selecting a small region on the map & filling other other details (like email), and waiting a few moments, I get to a page where I can download a .tar.gz file. Upon extraction, I find a .tif file.

I believe this is an example of the files I am looking for, but this method does not use Pyhton at all, and it is not suitable for automated processes.


How do I access the TIF files using Python?

I am looking for a similar thing to this this:

geotiffs = client.search_geotiffs(bounding_box=[59,10,60,11])

where the returned geotiffs is a list of tiff files from the GLO-30, intersecting or overlapping with the bounding box defined by points 59N10E & 60N11E, for example.

Hi @pal, if you’re looking to use boto3, I think you’ll want to use S3 — Boto3 Docs 1.18.48 documentation in addition to the list objects. The Body property will give you the actual contents of the file. Cloud Optimized GeoTIFF (COG) with Python | by Abdishakur | Spatial Data Science | Medium and Rasterio: access to geospatial raster data — rasterio documentation may also be helpful links to check out.

1 Like