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

error when reading a file #450

Closed
nes123 opened this issue Nov 2, 2021 · 10 comments
Closed

error when reading a file #450

nes123 opened this issue Nov 2, 2021 · 10 comments

Comments

@nes123
Copy link

nes123 commented Nov 2, 2021

Hello, i have a tiff file that i can open with rasterio.

But i get the following error with COGReader:

File "/usr/local/lib/python3.9/site-packages/rio_tiler/io/cogeo.py", line 101, in attrs_post_init
self.nodata = self.nodata if self.nodata is not None else self.dataset.nodata
AttributeError: '_GeneratorContextManager' object has no attribute 'nodata'

@nes123
Copy link
Author

nes123 commented Nov 2, 2021

with rasterio.open(blob_in_bytes) as src:
print(src.profile)

results in this output:

{'driver': 'GTiff', 'dtype': 'uint16', 'nodata': 0.0, 'width': 590, 'height': 1478, 'count': 4, 'crs': CRS.from_epsg(32610), 'transform': Affine(3.0, 0.0, 540492.0,
0.0, -3.0, 4185945.0), 'blockxsize': 256, 'blockysize': 256, 'tiled': True, 'compress': 'lzw', 'interleave': 'pixel'}

@kylebarron
Copy link
Member

What version of rio-tiler are you using?

@nes123
Copy link
Author

nes123 commented Nov 2, 2021

rio-tiler-2.1.4

@kylebarron
Copy link
Member

Can you provide a reproducible example? You haven't even told us what command you're running. It's likely because the dataset attribute is something unexpected.

@nes123
Copy link
Author

nes123 commented Nov 2, 2021

I am reading from google storage:

bucket = client.bucket("bucket_name")
blob = bucket.blob(path-in-bucket)
blob_in_bytes = io.BytesIO(blob)
with COGReader(blob_in_bytes) as image:
print(image.dataset)

@kylebarron
Copy link
Member

kylebarron commented Nov 2, 2021

Refer to the COGReader documentation and (https://cogeotiff.github.io/rio-tiler/readers/#rio_tileriocogreader) on how to use it. Is blob_in_bytes actually the bytes of the file? I doubt it... bucket.blob I think references the file but doesn't download it. And the first argument of COGReader is input, which is "Cloud Optimized GeoTIFF path.". Alternatively you could provide a dataset argument with a rasterio dataset, but a blob is not a dataset.

@kylebarron
Copy link
Member

You should be able to pass a filepath that rasterio understands directly to rio-tiler. I.e.

COGReader('s3://bucket/path')

You should look up if you can do the same with GCS.

@nes123
Copy link
Author

nes123 commented Nov 2, 2021

When I am trying to read directly from the cloud i get:

rasterio.errors.RasterioIOError: CPLRSASHA256Sign() not implemented: GDAL must be built against libcrypto++ or libcrypto (openssl)

@nes123
Copy link
Author

nes123 commented Nov 2, 2021

saving the file locally and then opening it solved the problem. Thank you for your help.

@vincentsarago
Copy link
Member

vincentsarago commented Nov 3, 2021

Thanks for reporting the issue @nes123.

There might be something at rasterio level 🤷

what you could do is

with rasterio.open(blob_in_bytes) as src:
     with COGReader(None, dataset=src) as cog:
          ....

The issue is that when you pass blob_in_bytes to COGReader we are not using a context manager https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/io/cogeo.py#L114 but a simple dataset = rasterio.open(input).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants