3

I have a raster file on a google cloud storage bucket and I want to open it with GDAL. I am trying this:

from osgeo import gdal
from google.cloud import storage
from google.cloud import client

#ensure file exists
name = '1.tif'
storage_client = storage.Client()
bucket_name = 'my-bucket'
bucket = storage_client.bucket(bucket_name)
stats = storage.Blob(bucket=bucket, name=name).exists(storage_client)
print(stats)

This returns True and the full path is gs://my-bucket/1.tif

But when I do this

gdal.Open('gs://my-bucket/1.tif')

it returns None

I can open the file correctly just fine when I read it from my google drive, so this seems to be an issue only on google cloud storage

2

1 Answer 1

7

GCS buckets are implemented as a GDAL virtual filesystem, so you'll want to update the filepath to:

gdal.Open('/vsigs/my-bucket/1.tif')

But as @Kartograaf mentions, you may also need to set some additional configuration parameters if your bucket requires authentication.

Alternatively, rasterio appears to handle the gs:// notation.

1
  • 3
    Thanks, @James. In case it's useful to others, I found the configuration parameters for authentication here: gdal.org/user/… Commented Sep 19, 2022 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.