0

I have three numeric vectors which describes:

  • lat - lattitude
  • long - longitute
  • value - value for specified point (for point in specific location defined by pai lat and long)

How can I create from them a raster object? I've tried to use cbind to combine them:

# I prefer pacman::p_load(raster) to load package
library('raster')

# Sample very small subset of data:
lat <- c(84.6564178466797, 84.6564178466797, 83.3252105712891, 82.2175979614258, 
80.3753433227539, 78.830451965332, 83.3252105712891)
long <- c(-145.316390991211, -70.6275939941406, -135.606842041016, -113.573654174805, 
-102.370330810547, -104.610992431641, -79.5902481079102)
value <- c(0.379887759685516, 0.297680675983429, 0.259096682071686, 0.195639669895172, 
0.259653329849243, 0.278579145669937, 0.333345)

myMatrix <- cbind(lat,long,value)

#this raster seems to be *incorrect*, because it shows: values: -145.3164, 84.65642  (min, max)
raster(myMatrix)

#Following causes an error (x cell sizes are not regular):
rasterFromXYZ(myMatrix)

but created object stores incorrect values.

Will I need to create a matrix first as described in this topic?

Community
  • 1
  • 1
matandked
  • 1,527
  • 4
  • 26
  • 51
  • 2
    perhaps [this](http://stackoverflow.com/questions/19627344/how-to-create-a-raster-from-a-data-frame-in-r) could help – akrun Aug 13 '16 at 13:09
  • @akrun Thank you, but intervals between my coordinates are not equal. I receive an error message when I try your suggested solution: gridded(spg) <- TRUE suggested tolerance minimum: 0.944784 Błąd w poleceniu 'points2grid(points, tolerance, round)': dimension 1 : coordinate intervals are not constant should I process my data firstly (guess using interpolation method) – matandked Aug 13 '16 at 20:51
  • There's exactly the same issue when calling rasterFromXYZ: rasterFromXYZ(cbind(lat,long,value)) Błąd w poleceniu 'rasterFromXYZ(cbind(lat, long, moisture))': x cell sizes are not regular – matandked Aug 13 '16 at 20:54

0 Answers0