GDAL – Installing JP2 Driver for Python and Anaconda

anacondagdaljpeg 2000pythonsentinel-2

I cannot open jp2-files with gdal:

This works fine (the Sentinel2 metadata):

~/copernicus/S2A_MSIL2A_20170111T100351_N0204_R122_T33UWP_20170111T100351.SAFE$ gdalinfo MTD_MSIL2A.xml

Driver: SENTINEL2/Sentinel 2
Files: MTD_MSIL2A.xml
Size is 512, 512
Coordinate System is `'
Metadata:
  AOT_RETRIEVAL_ACCURACY=0.0
  BARE_SOILS_PERCENTAGE=0.000388
  CLOUD_COVERAGE_ASSESSMENT=0.1018
  CLOUD_COVERAGE_PERCENTAGE=0.001909
  CLOUD_SHADOW_PERCENTAGE=0.389902
  DARK_FEATURES_PERCENTAGE=6.691170
[...]

But this not (one of the jp2 files):

~/copernicus/S2A_MSIL2A_20170111T100351_N0204_R122_T33UWP_20170111T100351.SAFE/GRANULE/L2A_T33UWP_A008127_20170111T100351/IMG_DATA/R10m$ gdalinfo L2A_T33UWP_20170111T100351_B02_10m.jp2
ERROR 4: `L2A_T33UWP_20170111T100351_B02_10m.jp2' not recognized as a supported file format.

gdalinfo failed - unable to open 'L2A_T33UWP_20170111T100351_B02_10m.jp2'.

I am using Anaconda 4.3.11 and created an environment with Python 2.7.13.
I want to open jp2-Files which are part of the Sentinel L2A-Product (converted from L1C with sen2cor).

I've installed openjpeg 2.1.0 and gdal 2.1.0 via "conda install":

> conda list

# packages in environment at /home/roland/anaconda2/envs/copernicus:
#
curl                      7.49.0                        1
gdal                      2.1.0                    py27_0
geos                      3.5.0                         0
geotiff                   1.4.1                         0
hdf4                      4.2.12                        0
hdf5                      1.8.17                        1
jbig                      2.1                           0
jpeg                      8d                            2
kealib                    1.4.6                         0
libgdal                   2.1.0                         0
libnetcdf                 4.4.1                         0
libpng                    1.6.27                        0
libtiff                   4.0.6                         2
mkl                       2017.0.1                      0
numpy                     1.12.0                   py27_0
openjpeg                  2.1.0                         5    sunpy
openssl                   1.0.2k                        0
pip                       9.0.1                    py27_1
proj4                     4.9.2                         0
python                    2.7.13                        0
readline                  6.2                           2
setuptools                27.2.0                   py27_0
sqlite                    3.13.0                        0
tk                        8.5.18                        0
wheel                     0.29.0                   py27_0
xerces-c                  3.1.4                         0
xz                        5.2.2                         1
zlib                      1.2.8                         3

The main problem seems to be that I don't manage to install the JPEG2000-driver:

> gdal-config --formats
gxf gtiff hfa aigrid aaigrid ceos ceos2 iso8211 xpm sdts raw dted mem jdem envisat elas fit vrt usgsdem l1b nitf bmp airsar rs2 ilwis rmf leveller sgi srtmhgt idrisi gsg ingr ers jaxapalsar dimap gff cosar pds adrg coasp tsx terragen blx msgn til r northwood saga xyz hf2 kmlsuperoverlay ctg e00grid zmap ngsgeoid iris map cals safe sentinel2 mrf wcs wms plmosaic wmts grib bsb netcdf kea hdf5 hdf4 gif jpeg png pcraster pcidsk rik ozi pdf arg

How can I do this?

Best Answer

It looks like this is a problem with the conda packaging of gdal. I see that the current gdal version on conda is 2.1.3, not 2.1.0, so hopefully this packaged version works. Consider removing the current gdal and reinstalling.

I looked at the contents of the gdal conda package I mentioned and for 64-bit linux python 2.7 numpy 1.12 the files gdaljp2abstractdataset.h, gdaljp2metadata.h, and gdaljp2metadatagenerator.h are included. Haven't installed it to confirm whether the driver exists.