Dear All,
I am trying to read from S3 using rasterio and the /vsis3 driver (part of GDAL, on which rasterio is based), using the following script:
123456789101112131415161718192021 | import boto3 import rasterio from rasterio.session import AWSSession import numpy as np
BUCKET = 'DIAS'
KEY='Sentinel-2/MSI/L2A/2018/08/09/S2A_MSIL2A_20180809T105031_N0208_R051_T31TCG_20180809T141746.SAFE/GRANULE/L2A_T31TCG_A016350_20180809T105627/IMG_DATA/R10m/T3 1TCG_20180809T105031_B03_10m.jp2'
access_key='anystring' secret_key='anystring'
session = boto3.Session(aws_access_key_id=access_key, aws_secret_access_key=secret_key)
with rasterio.Env(AWSSession(session), AWS_S3_ENDPOINT='data.cloudferro.com', AWS_HTTPS='NO') as env: print(env.options) with rasterio.open('/vsis3//{}/{}'.format(BUCKET, KEY), 'r') as ds: array = ds.read(1)
print(array.shape) |
This fails with the following error:
123456 | Traceback (most recent call last): File "rasterio/_base.pyx", line 198, in rasterio._base.DatasetBase.__init__ File "rasterio/_shim.pyx", line 64, in rasterio._shim.open_dataset File "rasterio/_err.pyx", line 205, in rasterio._err.exc_wrap_pointer
rasterio._err.CPLE_FileIOError: Cannot open file '/vsis3//DIAS/Sentinel-2/MSI/L2A/2018/08/09/S2A_MSIL2A_20180809T105031_N0208_R051_T31TCG_20180809T141746.SAFE/GRANULE/L2A_T31TCG_A016350_20180809T105627/IMG_DATA/R10m/T31TCG_20180809T105031_B03_10m.jp2/product.xml' |
i.e. for some unknown reason, rasterio seems to look for a product.xml file, which does not exist.
If I change to the use of /vsis3_streaming I get the following error:
12345 | Traceback (most recent call last): File "rasterio/_base.pyx", line 198, in rasterio._base.DatasetBase.__init__ File "rasterio/_shim.pyx", line 64, in rasterio._shim.open_dataset File "rasterio/_err.pyx", line 205, in rasterio._err.exc_wrap_pointer rasterio._err.CPLE_OpenFailedError: '/vsis3_streaming//DIAS/Sentinel-2/MSI/L2A/2018/08/09/S2A_MSIL2A_20180809T105031_N0208_R051_T31TCG_20180809T141746.SAFE/GRANULE/L2A_T31TCG_A016350_20180809T105627/IMG_DATA/R10m/T31TCG_20180809T105031_B03_10m.jp2' not recognized as a supported file format. |
i.e. this time, it tries to access the right file, but can't recognise the format (same happens if I provide a known GeoTIFF file).
Anyone working on this nd encountering similar problems? rasterio and S3 access is extremely poorly documented, so any clues would help.
My mid-term goal is to work with VRT files that can handle /vsis3.
Guido