Reading binary raster files in R

I want to read binary integers in R and convert them to raster grids. The following charterers are in the files:

NCols= 4320
NRows= 2160
pixel-size: 1/12=0.833 degrees
upper-left-lat: 90.0-1/24
upper-left-lon: -180.0+1/24
lower-right-lat: -90.0+1/24
lower-right-lon: 180.0
nodata= -5000
scale-factor= 10000
datatype: 16-bit signed integer
byte-order: big endian

That's what I'm doing:

file <-"http://nasanex.s3.amazonaws.com/AVHRR/GIMMS/3G/1980s/geo81aug15a.n07-VI3g"
dat <- readBin(file,what="integer", size=4, signed = TRUE, n = NRows * NCols, endian = "big")
r <- raster(nrow=2160, ncol=4320)
r[] <- dat

But this does not seem right, I appreciate any suggestions. .

+4
source share
2 answers

You can read such files with package greenbrownR.

Set it to R with

install.packages("greenbrown", repos="http://R-Forge.R-project.org")

, , , , greenbrown. , "": install.packages on Kendall, bfast, strucchange.

URL- , :

library(greenbrown)
r <- ReadVI3g("http://nasanex.s3.amazonaws.com/AVHRR/GIMMS/3G/1980s/geo81aug15a.n07-VI3g")

, greenbrown::ReadVI3g, RasterLayer.

plot(r)

enter image description here

+2

greenbrown ( , GitHub), , .

system.time(
  r1 <- ReadVI3g("http://nasanex.s3.amazonaws.com/AVHRR/GIMMS/3G/1980s/geo81aug15a.n07-VI3g")
)

#   user  system elapsed 
#  3.252   0.973 143.846

gimms, , , CRAN. , ReadVI3g , . overlay .

# install.packages("gimms")
library(gimms)

system.time({
  ## download file, see ?downloadGimms for further options
  f <- updateInventory()
  f <- downloadGimms(f[3], overwrite = TRUE) # download 3rd file in 'f', viz. geo81aug15a.n07-VI3g

  ## rasterize ndvi and flags
  ndvi <- rasterizeGimms(f)
  flag <- rasterizeGimms(f, flag = TRUE)

  ## perform quality control
  r2 <- overlay(ndvi, flag, fun = function(x, y) {
    x[y[] > 1] <- NA
    return(x)
  })
})

#   user  system elapsed 
#  4.538   3.894  26.781

, ,

> unique(r1 - r2, na.rm = TRUE)
[1] 0

, , gimms . , ( doParallel), .

+4

Source: https://habr.com/ru/post/1608866/


All Articles