[R-sig-Geo] Data conversion

Sarah Goslee @@r@h@go@|ee @end|ng |rom gm@||@com
Wed Aug 28 15:15:00 CEST 2019


Hi,

gdal_translate() by default returns NULL, but also writes your
destination tiff to the specified location, in this case
modisndvi.tiff in your working directory. Is that file not created?

>From ?gdal_translate:

Value:
     NULL or if(output_Raster), a RasterBrick.

So what you're seeing is exactly what I'd expect if everything worked
perfectly. Your commands don't load anything into R. If that's your
goal, you could set output_Raster=TRUE.

Here's an actual reproducible example.

library(rgdal)
library(gdalUtils)

hdf4_dataset <- system.file("external/test_modis.hdf", package="gdalUtils")
all.subsets <- get_subdatasets(hdf4_dataset)

# returns NULL as expected
gdalUtils::gdal_translate(src_dataset = all.subsets[1], dst_dataset =
"testfile.tiff")

# shows testfile.tiff in the working directory, as expected
list.files(pattern=".tiff")


If that reproducible example does not work on your system, and
testfile.tiff is not created, then we need more information, like the
output of sessionInfo(), and confirmation that you have a correctly
installed GDAL.

Sarah

On Tue, Aug 27, 2019 at 3:46 PM Fatih Kara <msfkara using yandex.com> wrote:
>
> Hi,
>
> I have a very simple problem which I couldn't solve nowadays: I can't convert '.hdf' files to '.tif' files.
>
> I use this code:
>
> install.packages("raster",dependencies = TRUE)
> install.packages("rgdal",dependencies = TRUE)
> install.packages("rgeos",dependencies = TRUE)
> install.packages("sp",dependencies = TRUE)
> install.packages("lwgeom", dependencies = TRUE)
> library(raster)
> library(lwgeom)
> library(maptools)
> library(rgdal)
> library(gdalUtils)
>
> subsets <- gdalUtils::get_subdatasets("modisndvi.hdf"[1])
> gdalUtils::gdal_translate(src_dataset = subsets[1], dst_dataset = "modisndvi.tiff")
>
> NULL
>
> What can I do?
>
> --
> Fatih Kara
>

-- 
Sarah Goslee (she/her)
http://www.numberwright.com



More information about the R-sig-Geo mailing list