Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wrapper to rasterio.open with env? #3

Open
j08lue opened this issue Nov 22, 2019 · 0 comments
Open

add wrapper to rasterio.open with env? #3

j08lue opened this issue Nov 22, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@j08lue
Copy link
Contributor

j08lue commented Nov 22, 2019

Directly reading from object storage with rasterio is a very nice thing and people have gotten this to work with the following code (from the forums):

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/T31TCG_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', AWS_VIRTUAL_HOSTING='FALSE') as env:
    print(env.options)
    with rasterio.open('/vsis3/{}/{}'.format(BUCKET, KEY), 'r') as ds:
        array = ds.read(1)

print(array.shape)

Since everything here is static except for the key, we could consider adding a little convenience context manager, that allows you to do like

with eodata_rasterio_open(key) as ds:
    pass
@j08lue j08lue added the enhancement New feature or request label Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant