[GIS] Handle .JP2 Sentinel data

jpeg 2000sentinel-2

I have downloaded several Sentinel 2 granules, with single bands raster data in .jp2 format, and I want to create true and false color composite images out of them. Using ArcGIS I could not open any single band raster (error says "invalid dataset"). Using QGIS I can open them but I cannot composite (I have tried using both "merge" and "create virtual raster" tool). I also tried to convert into geotiff using python scripts, but I am not that good in python, thus it did not work and probably I would need step by step guidance to do that. Does anyone have some ideas to solve the problem?

Best Answer

The latest version of GDAL (2.1) has the ability to read Sentinel 2 data (see http://gdal.org/frmt_sentinel2.html) in the SAFE file structure. It reads as sub-datasets so you need to run gdalinfo first on the main XML file to show all subdatasets (one for each resolution and UTM zone) then to select the one you want. You can then create a GeoTiff from the selected dataset using the following command:

gdal_translate SENTINEL2_L1C:S2A_OPER_MTD_SAFL1C_PDMC_20150818T101440_R022_V20150813T102406_20150813T102406.xml:10m:EPSG_32632 \
             output_10m.tif

(Example from GDAL website). The GeoTiff will be a mosaic of all .jp2 tiles within the given UTM zone comprising all bands for the selected resolution and can be loaded into QGIS/ArcMap.

Rather than using gdalinfo you can get a list of all the subdatasets using the GDAL Python bindings:

from osgeo import gdal
dataset = gdal.Open('S2/S2.xml', gdal.GA_ReadOnly)
subdatasets = dataset.GetSubDatasets()
dataset = None

Then pass each to gdal_translate. I used a similar approach in a script I wrote (see https://spectraldifferences.wordpress.com/2016/08/16/convert-sentinel-2-data-using-gdal/ for more details.)

You can install the latest version of GDAL under Windows (or Linux and OS X) using conda (http://conda.pydata.org/miniconda.html) through the conda-forge channel. Once miniconda has been installed run the following steps.

conda create -n gdal2 -c conda-forge gdal
source activate gdal2
Related Question