Sentienl 2 gdal translate

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Sentienl 2 gdal translate

Miguel Castro Gómez
Hi,

I have Sentinel 2 images (jp2) that I want to convert to GTiff using gdal_translate in R (from gdalutils package). Here is the code I’m using

Image_Path<-“/path/to/wd“

S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")

for (i in 1:length(S2_JP2_List)) {
gdal_translate(src_dataset = S2_JP2_List[[i]], dst_dataset = paste("Band", i , "tif"), ot = "UInt16", of = “GTiff")
    }

When running this code, the process starts without any error but its never ending neither producing any output

I've tried to do it in gdal and the same code works, except that it is necessary to skip  the default driver since it cannot manage large jp2 files.

gdal_translate -of GTiff /path/to/input/S2_b1.jp2  /path/to/output/S2_b1converted.tif --config GDAL_SKIP JP2ECW

Any idea how could I run this in R?

Thanks
M



        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Sentienl 2 gdal translate

Loïc Dutrieux-2
Hi,

I tried your code with some S2 images I had lying around, and it works
on my system. I modified it a bit to write the output layers to the same
directory and not to my working directory.

library(gdalUtils)
library(raster)

Image_Path<-'/path/to/images/'

S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")

for (file in S2_JP2_List) {
  out_file <- extension(file, 'tif')
  gdal_translate(src_dataset = file, dst_dataset = out_file, ot =
"UInt16", of = "GTiff")
}

gdal has a sentinel 2 driver, but it's not extremely old, therefore it's
possible that your installation doesn't have it; you can check with:

gdal-config --formats | grep sentinel2

Cheers,
Loïc



On 15/03/17 12:49, Miguel Castro Gómez wrote:

> Hi,
>
> I have Sentinel 2 images (jp2) that I want to convert to GTiff using gdal_translate in R (from gdalutils package). Here is the code I’m using
>
> Image_Path<-“/path/to/wd“
>
> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")
>
> for (i in 1:length(S2_JP2_List)) {
> gdal_translate(src_dataset = S2_JP2_List[[i]], dst_dataset = paste("Band", i , "tif"), ot = "UInt16", of = “GTiff")
>     }
>
> When running this code, the process starts without any error but its never ending neither producing any output
>
> I've tried to do it in gdal and the same code works, except that it is necessary to skip  the default driver since it cannot manage large jp2 files.
>
> gdal_translate -of GTiff /path/to/input/S2_b1.jp2  /path/to/output/S2_b1converted.tif --config GDAL_SKIP JP2ECW
>
> Any idea how could I run this in R?
>
> Thanks
> M
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Sentienl 2 gdal translate

Miguel Castro Gómez
Hi Loïc,

I have tried your code but it does not work yet. It just produces one tif file for the first band but this file is not correct (8 kb just). The R process keep working for a long time without any other output

Here are the versions I’m using

R version: 3.3.2
gdalUtils: v 2.0.1.7
raster: 2.5-8
gdal: 2.1.2, released 2016/10/24

When checking for the sentinel 2 driver in gdal (see red)

 gdal-config --formats | grep sentinel2
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 webp wcs wms plmosaic wmts dods grib bsb openjpeg jpeg2000 netcdf hdf5 hdf4 ogdi gif jpeg gta png pcraster fits pcidsk rik ozi rasterlite mbtiles postgisraster arg

I think the problem is the driver that is used to manage the jp2 file. Any idea how can I include in the R code the --config GDAL_SKIP JP2ECW option.

Cheers,
M

> El 15 mar 2017, a las 23:13, Loïc Dutrieux <[hidden email]> escribió:
>
> Hi,
>
> I tried your code with some S2 images I had lying around, and it works
> on my system. I modified it a bit to write the output layers to the same
> directory and not to my working directory.
>
> library(gdalUtils)
> library(raster)
>
> Image_Path<-'/path/to/images/'
>
> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")
>
> for (file in S2_JP2_List) {
>  out_file <- extension(file, 'tif')
>  gdal_translate(src_dataset = file, dst_dataset = out_file, ot =
> "UInt16", of = "GTiff")
> }
>
> gdal has a sentinel 2 driver, but it's not extremely old, therefore it's
> possible that your installation doesn't have it; you can check with:
>
> gdal-config --formats | grep sentinel2
>
> Cheers,
> Loïc
>
>
>
> On 15/03/17 12:49, Miguel Castro Gómez wrote:
>> Hi,
>>
>> I have Sentinel 2 images (jp2) that I want to convert to GTiff using gdal_translate in R (from gdalutils package). Here is the code I’m using
>>
>> Image_Path<-“/path/to/wd“
>>
>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")
>>
>> for (i in 1:length(S2_JP2_List)) {
>> gdal_translate(src_dataset = S2_JP2_List[[i]], dst_dataset = paste("Band", i , "tif"), ot = "UInt16", of = “GTiff")
>>    }
>>
>> When running this code, the process starts without any error but its never ending neither producing any output
>>
>> I've tried to do it in gdal and the same code works, except that it is necessary to skip  the default driver since it cannot manage large jp2 files.
>>
>> gdal_translate -of GTiff /path/to/input/S2_b1.jp2  /path/to/output/S2_b1converted.tif --config GDAL_SKIP JP2ECW
>>
>> Any idea how could I run this in R?
>>
>> Thanks
>> M
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Sentienl 2 gdal translate

Loïc Dutrieux-2
Hi Miguel,

Briefly looking at the help and source code of
gdalUtils::gdal_translate(), I don't see any way to pass additional
options. Your best shot is therefore probably to build the expression
yourself and pass it via a system call.

library(raster)

Image_Path<-'/path/to/images/'

S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")

for (file in S2_JP2_List) {
  out_file <- extension(file, 'tif')
  system2('gdal_translate', args = c('-of GTiff', file, out_file,
'--config GDAL_SKIP JPECW'))
}

But the real question here is why the simple gdal_translate call without
--config GDAL_SKIP JPECW did not work for you while you clearly have the
sentinel2 driver...

Cheers,
Loïc

On 16/03/17 06:02, Miguel Castro Gómez wrote:

> Hi Loïc,
>
> I have tried your code but it does not work yet. It just produces one
> tif file for the first band but this file is not correct (8 kb just).
> The R process keep working for a long time without any other output
>
> Here are the versions I’m using
>
> R version: 3.3.2
> gdalUtils: v 2.0.1.7
> raster: 2.5-8
> gdal: 2.1.2, released 2016/10/24
>
> When checking for the sentinel 2 driver in gdal (see red)
>
>  gdal-config --formats | grep sentinel2
> 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 webp wcs wms plmosaic wmts dods grib bsb openjpeg jpeg2000 netcdf
> hdf5 hdf4 ogdi gif jpeg gta png pcraster fits pcidsk rik ozi rasterlite
> mbtiles postgisraster arg
>
> I think the problem is the driver that is used to manage the jp2 file.
> Any idea how can I include in the R code the --config GDAL_SKIP JP2ECW
> option.
>
> Cheers,
> M
>
>> El 15 mar 2017, a las 23:13, Loïc Dutrieux
>> <[hidden email] <mailto:[hidden email]>>
>> escribió:
>>
>> Hi,
>>
>> I tried your code with some S2 images I had lying around, and it works
>> on my system. I modified it a bit to write the output layers to the same
>> directory and not to my working directory.
>>
>> library(gdalUtils)
>> library(raster)
>>
>> Image_Path<-'/path/to/images/'
>>
>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern =
>> ".jp2$")
>>
>> for (file in S2_JP2_List) {
>>  out_file <- extension(file, 'tif')
>>  gdal_translate(src_dataset = file, dst_dataset = out_file, ot =
>> "UInt16", of = "GTiff")
>> }
>>
>> gdal has a sentinel 2 driver, but it's not extremely old, therefore it's
>> possible that your installation doesn't have it; you can check with:
>>
>> gdal-config --formats | grep sentinel2
>>
>> Cheers,
>> Loïc
>>
>>
>>
>> On 15/03/17 12:49, Miguel Castro Gómez wrote:
>>> Hi,
>>>
>>> I have Sentinel 2 images (jp2) that I want to convert to GTiff using
>>> gdal_translate in R (from gdalutils package). Here is the code I’m using
>>>
>>> Image_Path<-“/path/to/wd“
>>>
>>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern =
>>> ".jp2$")
>>>
>>> for (i in 1:length(S2_JP2_List)) {
>>> gdal_translate(src_dataset = S2_JP2_List[[i]], dst_dataset =
>>> paste("Band", i , "tif"), ot = "UInt16", of = “GTiff")
>>>    }
>>>
>>> When running this code, the process starts without any error but its
>>> never ending neither producing any output
>>>
>>> I've tried to do it in gdal and the same code works, except that it
>>> is necessary to skip  the default driver since it cannot manage large
>>> jp2 files.
>>>
>>> gdal_translate -of GTiff /path/to/input/S2_b1.jp2
>>>  /path/to/output/S2_b1converted.tif --config GDAL_SKIP JP2ECW
>>>
>>> Any idea how could I run this in R?
>>>
>>> Thanks
>>> M
>>>
>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> [hidden email] <mailto:[hidden email]>
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [hidden email] <mailto:[hidden email]>
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> Email secured by Check Point
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Sentienl 2 gdal translate

Miguel Castro Gómez
Hi Loïc,

Thanks for your help,

When trying the system2 option this is what happens:

Image_Path<- “path/to/images/"

S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")

for (file in S2_JP2_List) {
    out_file <- extension(file, 'tif')
    system2('gdal_translate', args = c('-of GTiff', file, out_file,
                                       '--config GDAL_SKIP JPECW'))
}

sh: gdal_translate: command not found


I have been checking and the problem may be that R cannot find the gdal_translate command. Here are the paths:

Sys.getenv('R_HOME’)
"/Library/Frameworks/R.framework/Resources"
Sys.getenv('PATH')
"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin”

In terminal:
user$ echo $PATH
/Library/Frameworks/GDAL.framework/Programs:/Library/Frameworks/GDAL.framework/Programs:/Library/Frameworks/GDAL.framework/Programs:/Users/Miguel/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin


I think it has to match but not sure how can I change the path that R is using to find the command gdal_translate

Regarding sentinel2 driver, any idea why is not working? Any help on that

Cheers
M


> El 16 mar 2017, a las 19:21, Loïc Dutrieux <[hidden email]> escribió:
>
> Hi Miguel,
>
> Briefly looking at the help and source code of
> gdalUtils::gdal_translate(), I don't see any way to pass additional
> options. Your best shot is therefore probably to build the expression
> yourself and pass it via a system call.
>
> library(raster)
>
> Image_Path<-'/path/to/images/'
>
> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")
>
> for (file in S2_JP2_List) {
>  out_file <- extension(file, 'tif')
>  system2('gdal_translate', args = c('-of GTiff', file, out_file,
> '--config GDAL_SKIP JPECW'))
> }
>
> But the real question here is why the simple gdal_translate call without
> --config GDAL_SKIP JPECW did not work for you while you clearly have the
> sentinel2 driver...
>
> Cheers,
> Loïc
>
> On 16/03/17 06:02, Miguel Castro Gómez wrote:
>> Hi Loïc,
>>
>> I have tried your code but it does not work yet. It just produces one
>> tif file for the first band but this file is not correct (8 kb just).
>> The R process keep working for a long time without any other output
>>
>> Here are the versions I’m using
>>
>> R version: 3.3.2
>> gdalUtils: v 2.0.1.7
>> raster: 2.5-8
>> gdal: 2.1.2, released 2016/10/24
>>
>> When checking for the sentinel 2 driver in gdal (see red)
>>
>> gdal-config --formats | grep sentinel2
>> 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 webp wcs wms plmosaic wmts dods grib bsb openjpeg jpeg2000 netcdf
>> hdf5 hdf4 ogdi gif jpeg gta png pcraster fits pcidsk rik ozi rasterlite
>> mbtiles postgisraster arg
>>
>> I think the problem is the driver that is used to manage the jp2 file.
>> Any idea how can I include in the R code the --config GDAL_SKIP JP2ECW
>> option.
>>
>> Cheers,
>> M
>>
>>> El 15 mar 2017, a las 23:13, Loïc Dutrieux
>>> <[hidden email] <mailto:[hidden email]> <mailto:[hidden email] <mailto:[hidden email]>>>
>>> escribió:
>>>
>>> Hi,
>>>
>>> I tried your code with some S2 images I had lying around, and it works
>>> on my system. I modified it a bit to write the output layers to the same
>>> directory and not to my working directory.
>>>
>>> library(gdalUtils)
>>> library(raster)
>>>
>>> Image_Path<-'/path/to/images/'
>>>
>>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern =
>>> ".jp2$")
>>>
>>> for (file in S2_JP2_List) {
>>> out_file <- extension(file, 'tif')
>>> gdal_translate(src_dataset = file, dst_dataset = out_file, ot =
>>> "UInt16", of = "GTiff")
>>> }
>>>
>>> gdal has a sentinel 2 driver, but it's not extremely old, therefore it's
>>> possible that your installation doesn't have it; you can check with:
>>>
>>> gdal-config --formats | grep sentinel2
>>>
>>> Cheers,
>>> Loïc
>>>
>>>
>>>
>>> On 15/03/17 12:49, Miguel Castro Gómez wrote:
>>>> Hi,
>>>>
>>>> I have Sentinel 2 images (jp2) that I want to convert to GTiff using
>>>> gdal_translate in R (from gdalutils package). Here is the code I’m using
>>>>
>>>> Image_Path<-“/path/to/wd“
>>>>
>>>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern =
>>>> ".jp2$")
>>>>
>>>> for (i in 1:length(S2_JP2_List)) {
>>>> gdal_translate(src_dataset = S2_JP2_List[[i]], dst_dataset =
>>>> paste("Band", i , "tif"), ot = "UInt16", of = “GTiff")
>>>>   }
>>>>
>>>> When running this code, the process starts without any error but its
>>>> never ending neither producing any output
>>>>
>>>> I've tried to do it in gdal and the same code works, except that it
>>>> is necessary to skip  the default driver since it cannot manage large
>>>> jp2 files.
>>>>
>>>> gdal_translate -of GTiff /path/to/input/S2_b1.jp2
>>>> /path/to/output/S2_b1converted.tif --config GDAL_SKIP JP2ECW
>>>>
>>>> Any idea how could I run this in R?
>>>>
>>>> Thanks
>>>> M
>>>>
>>>>
>>>>
>>>> [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> [hidden email] <mailto:[hidden email]> <mailto:[hidden email] <mailto:[hidden email]>>
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo <https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>>>>
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> [hidden email] <mailto:[hidden email]> <mailto:[hidden email] <mailto:[hidden email]>>
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo <https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>>
>>
>>
>> Email secured by Check Point


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Sentienl 2 gdal translate

Loïc Dutrieux-2
Hi Miguel,

Do you have more than one installation of gdal? That could potentially
explain why your first try with gdal_translate() did not work.

library(gdalUtils)
length(getOption("gdalUtils_gdalPath"))

should give you the number of installations you have on your system.

If more than 1, gdal_chooseInstallation(hasDrivers=c("SENTINEL2"))
should set the correct path for gdal_translate().

Cheers,
Loïc

On 17/03/17 05:45, Miguel Castro Gómez wrote:

> Hi Loïc,
>
> Thanks for your help,
>
> When trying the system2 option this is what happens:
>
> Image_Path<- “path/to/images/"
>
> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern = ".jp2$")
>
> for (file in S2_JP2_List) {
>     out_file <- extension(file, 'tif')
>     system2('gdal_translate', args = c('-of GTiff', file, out_file,
>                                        '--config GDAL_SKIP JPECW'))
> }
>
> sh: gdal_translate: command not found
>
>
> I have been checking and the problem may be that R cannot find the
> gdal_translate command. Here are the paths:
>
> Sys.getenv('R_HOME’)
> "/Library/Frameworks/R.framework/Resources"
> Sys.getenv('PATH')
> "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin”
>
> In terminal:
> user$ echo $PATH
> /Library/Frameworks/GDAL.framework/Programs:/Library/Frameworks/GDAL.framework/Programs:/Library/Frameworks/GDAL.framework/Programs:/Users/Miguel/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
>
>
> I think it has to match but not sure how can I change the path that R is
> using to find the command gdal_translate
>
> Regarding sentinel2 driver, any idea why is not working? Any help on that
>
> Cheers
> M
>
>
>> El 16 mar 2017, a las 19:21, Loïc Dutrieux
>> <[hidden email] <mailto:[hidden email]>>
>> escribió:
>>
>> Hi Miguel,
>>
>> Briefly looking at the help and source code of
>> gdalUtils::gdal_translate(), I don't see any way to pass additional
>> options. Your best shot is therefore probably to build the expression
>> yourself and pass it via a system call.
>>
>> library(raster)
>>
>> Image_Path<-'/path/to/images/'
>>
>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern =
>> ".jp2$")
>>
>> for (file in S2_JP2_List) {
>>  out_file <- extension(file, 'tif')
>>  system2('gdal_translate', args = c('-of GTiff', file, out_file,
>> '--config GDAL_SKIP JPECW'))
>> }
>>
>> But the real question here is why the simple gdal_translate call without
>> --config GDAL_SKIP JPECW did not work for you while you clearly have the
>> sentinel2 driver...
>>
>> Cheers,
>> Loïc
>>
>> On 16/03/17 06:02, Miguel Castro Gómez wrote:
>>> Hi Loïc,
>>>
>>> I have tried your code but it does not work yet. It just produces one
>>> tif file for the first band but this file is not correct (8 kb just).
>>> The R process keep working for a long time without any other output
>>>
>>> Here are the versions I’m using
>>>
>>> R version: 3.3.2
>>> gdalUtils: v 2.0.1.7
>>> raster: 2.5-8
>>> gdal: 2.1.2, released 2016/10/24
>>>
>>> When checking for the sentinel 2 driver in gdal (see red)
>>>
>>> gdal-config --formats | grep sentinel2
>>> 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 webp wcs wms plmosaic wmts dods grib bsb openjpeg jpeg2000 netcdf
>>> hdf5 hdf4 ogdi gif jpeg gta png pcraster fits pcidsk rik ozi rasterlite
>>> mbtiles postgisraster arg
>>>
>>> I think the problem is the driver that is used to manage the jp2 file.
>>> Any idea how can I include in the R code the --config GDAL_SKIP JP2ECW
>>> option.
>>>
>>> Cheers,
>>> M
>>>
>>>> El 15 mar 2017, a las 23:13, Loïc Dutrieux
>>>> <[hidden email]
>>>> <mailto:[hidden email]> <mailto:[hidden email]>>
>>>> escribió:
>>>>
>>>> Hi,
>>>>
>>>> I tried your code with some S2 images I had lying around, and it works
>>>> on my system. I modified it a bit to write the output layers to the same
>>>> directory and not to my working directory.
>>>>
>>>> library(gdalUtils)
>>>> library(raster)
>>>>
>>>> Image_Path<-'/path/to/images/'
>>>>
>>>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern =
>>>> ".jp2$")
>>>>
>>>> for (file in S2_JP2_List) {
>>>> out_file <- extension(file, 'tif')
>>>> gdal_translate(src_dataset = file, dst_dataset = out_file, ot =
>>>> "UInt16", of = "GTiff")
>>>> }
>>>>
>>>> gdal has a sentinel 2 driver, but it's not extremely old, therefore it's
>>>> possible that your installation doesn't have it; you can check with:
>>>>
>>>> gdal-config --formats | grep sentinel2
>>>>
>>>> Cheers,
>>>> Loïc
>>>>
>>>>
>>>>
>>>> On 15/03/17 12:49, Miguel Castro Gómez wrote:
>>>>> Hi,
>>>>>
>>>>> I have Sentinel 2 images (jp2) that I want to convert to GTiff using
>>>>> gdal_translate in R (from gdalutils package). Here is the code I’m
>>>>> using
>>>>>
>>>>> Image_Path<-“/path/to/wd“
>>>>>
>>>>> S2_JP2_List <- list.files(Image_Path, full.names = TRUE, pattern =
>>>>> ".jp2$")
>>>>>
>>>>> for (i in 1:length(S2_JP2_List)) {
>>>>> gdal_translate(src_dataset = S2_JP2_List[[i]], dst_dataset =
>>>>> paste("Band", i , "tif"), ot = "UInt16", of = “GTiff")
>>>>>   }
>>>>>
>>>>> When running this code, the process starts without any error but its
>>>>> never ending neither producing any output
>>>>>
>>>>> I've tried to do it in gdal and the same code works, except that it
>>>>> is necessary to skip  the default driver since it cannot manage large
>>>>> jp2 files.
>>>>>
>>>>> gdal_translate -of GTiff /path/to/input/S2_b1.jp2
>>>>> /path/to/output/S2_b1converted.tif --config GDAL_SKIP JP2ECW
>>>>>
>>>>> Any idea how could I run this in R?
>>>>>
>>>>> Thanks
>>>>> M
>>>>>
>>>>>
>>>>>
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>> _______________________________________________
>>>>> R-sig-Geo mailing list
>>>>> [hidden email]
>>>>> <mailto:[hidden email]> <mailto:[hidden email]>
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> [hidden email]
>>>> <mailto:[hidden email]> <mailto:[hidden email]>
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>>
>>>
>>> Email secured by Check Point
>
>
>
> Email secured by Check Point
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo