Data conversion

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Data conversion

Fatih Kara
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

_______________________________________________
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: Data conversion

Sarah Goslee
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 <[hidden email]> 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

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