Is there any way I can open Sentinel 2 JPEG2000 file (.jp2
) using R? Or more specifically with the {raster}
package in R? I keep getting the Error message that .jp2
is:
not recognised as a supported file format.
Do you know if this file format will be added to the raster package any time soon, or how to open it in R without converting it to .tif
first?
Answer
You should use the rgdal
package and ensure that your version of GDAL has the JPEG2000 Driver. For instance:
library(rgdal)
Loading required package: sp
rgdal: version: 1.1-10, (SVN revision 622)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
Path to GDAL shared files: /usr/share/gdal/1.11
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files: (autodetected)
Linking to sp version: 1.2-3
Then read in the jp2 file:
> s2a <- readGDAL('S2A_OPER_MSI_L1C_TL_SGS__20151221T173303_A002594_T29UMT_B12.jp2')
S2A_OPER_MSI_L1C_TL_SGS__20151221T173303_A002594_T29UMT_B12.jp2 has GDAL driver JPEG2000
and has 5490 rows and 5490 columns
Check the output:
summary(s2a)
Object of class SpatialGridDataFrame
Coordinates:
min max
x 399960 509760
y 5690220 5800020
Is projected: TRUE
proj4string :
[+proj=utm +zone=29 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0]
Grid attributes:
cellcentre.offset cellsize cells.dim
x 399970 20 5490
y 5690230 20 5490
Data attributes:
band1
Min. : 0
1st Qu.: 198
Median : 606
Mean : 1080
3rd Qu.: 1430
Max. :28000
No comments:
Post a Comment