Python3.7 rasterio library cant open jp2

不想你离开。 提交于 2021-01-27 17:09:38

问题


I want to open a jp2 image from sentinel2 but when I read the image

band = rasterio.open(imagetest, driver= 'JP2OpenJPEG')

I get the next error

'D:\DataStorage\00_sentinel_data\L1C_T29SQB_A013147_20171228T111919\IMG_DATA\T29SQB_20171228T111451_B02.jp2' not recognized as a supported file format.

I have installed GDAL with OSGeo4W and I can see the driver when I use the gdalinfo --formats command

JP2OpenJPEG -raster,vector- (rwv): JPEG-2000 driver based on OpenJPEG library

The only thing that I see that could be the problem is that when I see the gdal formats that I have using python, the JP2OpenJPEG driver does not exist.

from osgeo import gdal
for i in range(gdal.GetDriverCount()):
    drv = gdal.GetDriver(i)
    if drv.GetMetadataItem(gdal.DCAP_RASTER):
        print(drv.GetMetadataItem(gdal.DMD_LONGNAME), drv.GetMetadataItem(gdal.DMD_EXTENSIONS))

Any ideas about what is happening??

Python version: 3.7 Gdal version: 2.3.3 Rasterio version: 1.0.21

Thanks


回答1:


I had the same issue. It looks like this is a problem in Anaconda's GDAL. Here is one way to fix the problem:

https://gis.stackexchange.com/a/250837/149170

Unfortunately, upgrading/downgrading the base package in Anaconda did not work for me.

I was finding that installing the package "fiona" with pip was downgrading gdal for me. I finally fixed the issue of downgrading gdal by installing fiona using conda:

conda install fiona


来源:https://stackoverflow.com/questions/56611197/python3-7-rasterio-library-cant-open-jp2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!