2

I need to convert a sgrd file to tif or ascii using R. I converted a big sgrd file (1.4 GB, 376521831 pixels) to ascii using the package RSAGAbut it takes too long (approx. 45 minutes):

rsaga.sgrd.to.esri(in.sgrds = "path\\dem_filename", 
                 out.grids = "output_filename", 
                 out.path = "path\\foldername", 
                 format = "ascii",
                 georef = "corner", 
                 prec = 5,
                 env = work_env)

How could I convert sgrd format with rgdal or other R packages?

2
  • How big is "big" and how long is "too long"? Can you please edit your question to give the approximate size of your raster (1000 x 1000 pixels? 10,000,000 x 10,000,000 pixels?) and how long the conversion takes, or how long you waited before giving up.
    – Spacedman
    Commented Jul 5, 2018 at 6:43
  • 1
    I edited my question and added the size of the file and the approximate processing time.
    – yPennylane
    Commented Jul 6, 2018 at 9:06

2 Answers 2

3

You probably have .sdat file along with .sgrd(header) file.

library(raster)
x <- raster("C:\\path\\file.sdat")
writeRaster(x, filename = "C:\\path\\file.asc", format= "ascii")

[EDIT] - if you need only down to 5 decimal places, round(raster(),5) (as below) will reduce the file size, and the processing will become faster.

library(raster)
x <- round(raster("C:\\path\\file.sdat"), 5)
writeRaster(x, filename = "C:\\path\\file.asc", format= "ascii")
2
  • Thank you, it works. It only takes 17.70 minutes for converting the 1.4 GB file. Unfortunately the resulting ascii file has 4.57 GB, where as the file produced with rsaga.sgrd.to.esri has only 3.7 GB.
    – yPennylane
    Commented Jul 6, 2018 at 15:00
  • @yPennylane Thank you for your feed back. I noticed you have set prec = 5 option in rsaga.sgrd.to.esri. Please see my edit to reflect it.
    – Kazuhito
    Commented Jul 6, 2018 at 16:38
2

In RSAGA you can also use the "GDAL: Export Raster" module in library "io_gdal". Take a look at the output of rsaga.get.usage("io_gdal", 1, env = work_env), and then use the rsaga.geoprocessor to call this module. This might be faster than the rsaga.sgrd.to.esri call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.