Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
can';t使用python rasterio、gdal打开jp2(来自sentinel)_Python_Rasterio - Fatal编程技术网

can';t使用python rasterio、gdal打开jp2(来自sentinel)

can';t使用python rasterio、gdal打开jp2(来自sentinel),python,rasterio,Python,Rasterio,我试图用python将jp2 rasters产品作为光栅打开,但在使用“raterio”和“gdal”包时没有成功。 我发现以下错误: RasterioIOError: 'b4.jp2' not recognized as a supported file format. RuntimeError: `b4.jp2' not recognized as a supported file format. 我确实设法用“glymur”包将它们作为常规矩阵打开,但随后我丢失了地理数据 如果有人知道其

我试图用python将jp2 rasters产品作为光栅打开,但在使用“raterio”和“gdal”包时没有成功。
我发现以下错误:

RasterioIOError: 'b4.jp2' not recognized as a supported file format.
RuntimeError: `b4.jp2' not recognized as a supported file format.
我确实设法用“glymur”包将它们作为常规矩阵打开,但随后我丢失了地理数据

如果有人知道其他pachage打开jp2作为光栅,我会很高兴知道

我试着遵循这个答案: 用康达安装菲奥娜 或: 并尝试安装:
conda create-n mynewenv-c conda forge gdal rasterio
但我还是会犯同样的错误

b4 = rasterio.open('b4.jp2')
b4 = rasterio.open('b4.jp2', driver= 'JP2OpenJPEG')

这与您尝试过的非常相似,但这个过程对我来说很有效。注意:我指定我想要一个Python3.7环境。从anaconda提示符:

conda create --name testing python=3.7
conda activate testing
conda install -c conda-forge gdal rasterio
rio env --formats
已验证正确安装:

(testing) C:\Users\dan>python
Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 22:01:29) [MSC v.1900 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rasterio
>>> import gdal
>>> gdal.VersionInfo()
'3000100'
>>> rasterio.gdal_version()
'3.0.1'
并检查以确保支持
.jp2
驱动程序。从anaconda提示符:

conda create --name testing python=3.7
conda activate testing
conda install -c conda-forge gdal rasterio
rio env --formats
它返回一个包含以下条目的长列表:

JML: OpenJUMP JML
JP2OpenJPEG: JPEG-2000 driver based on OpenJPEG library
JPEG: JPEG JFIF
这是从
conda env export
导出的内容:

name: testing
channels:
  - conda-forge
  - defaults
dependencies:
  - affine=2.3.0=py_0
  - attrs=19.3.0=py_0
  - boost-cpp=1.70.0=h6a4c333_2
  - bzip2=1.0.8=hfa6e2cd_1
  - ca-certificates=2019.9.11=hecc5488_0
  - certifi=2019.9.11=py37_0
  - cfitsio=3.470=hfa6e2cd_2
  - click=7.0=py_0
  - click-plugins=1.1.1=py_0
  - cligj=0.5.0=py_0
  - curl=7.65.3=h4496350_0
  - expat=2.2.5=he025d50_1004
  - freetype=2.10.0=h563cfd7_1
  - freexl=1.0.5=hd288d7e_1002
  - gdal=3.0.1=py37h2fee047_10
  - geos=3.7.2=he025d50_2
  - geotiff=1.5.1=h6e819c3_4
  - gettext=0.19.8.1=hb01d8f6_1002
  - glib=2.58.3=hc0c2ac7_1002
  - hdf4=4.2.13=hf8e6fe8_1002
  - hdf5=1.10.5=nompi_ha405e13_1104
  - icu=64.2=he025d50_1
  - jpeg=9c=hfa6e2cd_1001
  - kealib=1.4.10=hf7dc31f_1005
  - krb5=1.16.3=hdd46e55_1001
  - libblas=3.8.0=14_mkl
  - libcblas=3.8.0=14_mkl
  - libcurl=7.65.3=h4496350_0
  - libffi=3.2.1=h6538335_1006
  - libgdal=3.0.1=h2491c49_10
  - libiconv=1.15=hfa6e2cd_1005
  - libkml=1.3.0=h4ece8bf_1010
  - liblapack=3.8.0=14_mkl
  - libnetcdf=4.7.1=nompi_h8d74e2a_101
  - libpng=1.6.37=h7602738_0
  - libpq=11.5=hb0bdaea_1
  - libspatialite=4.3.0a=hee5a54d_1031
  - libssh2=1.8.2=h642c060_2
  - libtiff=4.0.10=h6512ee2_1003
  - libxml2=2.9.10=h9ce36c8_0
  - lz4-c=1.8.3=he025d50_1001
  - numpy=1.17.3=py37hc71023c_0
  - openjpeg=2.3.1=hb24c2e3_1
  - openssl=1.1.1c=hfa6e2cd_0
  - pcre=8.43=h6538335_0
  - poppler=0.67.0=h92819f6_7
  - poppler-data=0.4.9=1
  - postgresql=11.5=h06f7779_1
  - proj=6.2.0=ha7a8c7b_1
  - pyparsing=2.4.2=py_0
  - python=3.7.3=h510b542_1
  - rasterio=1.1.0=py37h2617b1b_0
  - snuggs=1.4.7=py_0
  - tbb=2018.0.5=he980bc4_0
  - tiledb=1.6.2=h30b6f50_1
  - tk=8.6.9=hfa6e2cd_1003
  - xerces-c=3.2.2=h6538335_1004
  - xz=5.2.4=h2fa13f4_1001
  - zlib=1.2.11=h2fa13f4_1006
  - zstd=1.4.0=hd8a0e53_0
  - intel-openmp=2019.4=245
  - m2w64-expat=2.1.1=2
  - m2w64-gcc-libgfortran=5.3.0=6
  - m2w64-gcc-libs=5.3.0=7
  - m2w64-gcc-libs-core=5.3.0=7
  - m2w64-gettext=0.19.7=2
  - m2w64-gmp=6.1.0=2
  - m2w64-libiconv=1.14=6
  - m2w64-libwinpthread-git=5.0.0.4634.697f757=2
  - m2w64-xz=5.2.2=2
  - mkl=2019.4=245
  - msys2-conda-epoch=20160418=1
  - pip=19.3.1=py37_0
  - setuptools=41.6.0=py37_0
  - sqlite=3.30.1=he774522_0
  - vc=14.1=h0510ff6_4
  - vs2015_runtime=14.16.27012=hf0eaf9b_0
  - wheel=0.33.6=py37_0
  - wincertstore=0.2=py37_0
prefix: C:\Anaconda2\envs\testing
证明它有效:

(testing) C:\Users\RDCRLDDH>python
Python 3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rasterio
>>> ds = rasterio.open(r"C:\Users\RDCRLDDH\Desktop\T36QVM_20191023T082009_B01.jp2")
>>> ds.crs
CRS.from_epsg(32636)
>>> ds.read(1)
array([[2372, 2344, 2312, ..., 1423, 1406, 1481],
       [2326, 2292, 2279, ..., 1492, 1462, 1495],
       [2317, 2271, 2261, ..., 1529, 1517, 1511],
       ...,
       [1958, 1946, 1947, ..., 1697, 1734, 1730],
       [1960, 1960, 1967, ..., 1714, 1758, 1721],
       [1959, 1957, 1960, ..., 1769, 1752, 1701]], dtype=uint16)
>>> ds.transform
Affine(60.0, 0.0, 399960.0,
       0.0, -60.0, 2700000.0)
>>>
在spyder中,您可以使用

import sys
print(sys.executable)
您应该看到如下内容:

C:\Anaconda2\envs\testing\pythonw.exe

安装目录
C:\Anaconda2\
将取决于您将anaconda安装到的位置,但后一部分
envs\testing\pythonw.exe
应相同

你能用
gdal.open()
打开它吗
rasterio.gdal\u version()
返回什么?不,我试过了,没用,gdal版本:'2.3.3'怎么样
gdal.VersionInfo()
gdal.VersionInfo()给出了'2030300'嗨,安装如这里所述,在提示我获取rio env时——格式化jp2条目(这很好,我以前没有得到)。和你的conda env export一样。但是在spyder编辑器中,gdal.VersionInfo()给出了'2030300',rasterio.gdal_version()给出了“2.3.3”。但是我仍然无法用rasterio.open打开jp2。我尝试了两个同时打开rasterio和gdal的jp2文件,但没有成功。我同意这很令人沮丧!嗨,也许还有另一个解决方案?噢,我刚刚重新阅读了你的第一条评论。将spyder安装到环境中
测试
pip安装spyder
n从那个环境运行spyder。嗨,我再次安装spyder,在conda激活测试之后,这就是你的意思吗?rasterio.gdal_version()仍然给出“2.3.3”。。