[R-sig-Geo] Problem in extracting data from GRIB files

Miluji Sb milujisb at gmail.com
Fri Jul 28 18:21:05 CEST 2017


Dear all,

I have a set of coordinates for cities:

structure(list(lon = c(3.7174243, 3.2246995, 2.928656, 33.3822764,
10.40237, 24.7535746, 7.2619532, -0.370679, -4.486076, -4.097899
), lat = c(51.0543422, 51.209348, 51.21543, 35.1855659, 55.403756,
59.4369608, 43.7101728, 49.182863, 48.390394, 47.997542)), .Names =
c("lon",
"lat"), na.action = structure(c(5L, 6L, 31L, 55L, 59L, 61L, 67L,
68L), .Names = c("5", "6", "31", "55", "59", "61", "67", "68"
), class = "omit"), row.names = c(1L, 2L, 3L, 4L, 7L, 8L, 9L,
10L, 11L, 12L), class = "data.frame")

I am trying to extract climatic data from GLDAS climatic data (1 degree x 1
degree) GRIB files with the following code:

# Convert to spatial points
pts_dams <- SpatialPoints(lonlat,proj4string=CRS("+proj=longlat"))

# Extract
 filelist<-list.files(pattern=".grb$")

    data<-stack(filelist[1])
    data at layers<-sapply(filelist, function(x) raster(x,band=12))
    data_dams_size<-extract(data,pts_dams)
    DF_data_dams_size<- as.data.frame(data_dams_size)

Unfortunately, I get mostly NAs for the data, it seems that there's an
issue with the CRS projections for the city coordinates. Is there a
specific projection for city level coordinates? Or am I doing something
completely wrong? Thank you!

Sincerely,

Milu

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list