[R-sig-Geo] Extract points from raster brick by both location and a matching attributes.

Robert J. Hijmans r.hijmans at gmail.com
Thu Sep 11 18:07:44 CEST 2014


I would extract all values and select the ones I need after that. The
alternative is to extract values layer by layer, that is probably less
efficient.
Robert

On Mon, Sep 8, 2014 at 1:55 AM, Kristin <nessnjor at gmail.com> wrote:
> Hi
>
> I have a raster brick of 464 layers, each layer representing time defined as
> number from 1 to 464.
> The numbers are stored here:
> rasterbrick at z$days
>
> and have values from 1 to 464
>
> Then I have 2800 space time locations of field data sampling. These are both
> irregular sampling locations and some irregular sampling dates at same
> sampling locations. Dates are also defined as numbers from 1 to 464. Each
> individual point is then identified by lat and lon at different times.
> This is what my dataframe looks like:
>
> Lat, Lon, days
> 64   -21    23
> 63   -19    52
> 63   -19    53
> 66   -25    23
> ....
>
> So what I want to do is to extract values from the raster brick at a certain
> location, but only where the date numbers from both the raster brick and the
> locations match, but not for all times for all locations as the extract from
> raster brick does.
>
> And if it helps, then below is the structure of my raster brick:
>> str (rasterbrick)
> Formal class 'RasterBrick' [package "raster"] with 12 slots
>   ..@ file    :Formal class '.RasterFile' [package "raster"] with 13 slots
>   .. .. ..@ name        : chr "C:\\Gudrun\\DINEOF_NIALL\\R\\chl.nc"
>   .. .. ..@ datanotation: chr "FLT4S"
>   .. .. ..@ byteorder   : chr "little"
>   .. .. ..@ nodatavalue : num -9999
>   .. .. ..@ NAchanged   : logi FALSE
>   .. .. ..@ nbands      : int 464
>   .. .. ..@ bandorder   : chr "BIL"
>   .. .. ..@ offset      : int 0
>   .. .. ..@ toptobottom : logi TRUE
>   .. .. ..@ blockrows   : int 0
>   .. .. ..@ blockcols   : int 0
>   .. .. ..@ driver      : chr "netcdf"
>   .. .. ..@ open        : logi FALSE
>   ..@ data    :Formal class '.MultipleRasterData' [package "raster"] with 14
> slots
>   .. .. ..@ values    : logi[0 , 0 ]
>   .. .. ..@ offset    : num 0
>   .. .. ..@ gain      : num 1
>   .. .. ..@ inmemory  : logi FALSE
>   .. .. ..@ fromdisk  : logi TRUE
>   .. .. ..@ nlayers   : int 464
>   .. .. ..@ dropped   : NULL
>   .. .. ..@ isfactor  : logi FALSE
>   .. .. ..@ attributes: list()
>   .. .. ..@ haveminmax: logi FALSE
>   .. .. ..@ min       : num [1:464] Inf Inf Inf Inf Inf ...
>   .. .. ..@ max       : num [1:464] -Inf -Inf -Inf -Inf -Inf ...
>   .. .. ..@ unit      : chr "units"
>   .. .. ..@ names     : chr [1:464] "X341" "X41" "X169" "X281" ...
>   ..@ legend  :Formal class '.RasterLegend' [package "raster"] with 5 slots
>   .. .. ..@ type      : chr(0)
>   .. .. ..@ values    : logi(0)
>   .. .. ..@ color     : logi(0)
>   .. .. ..@ names     : logi(0)
>   .. .. ..@ colortable: logi(0)
>   ..@ title   : chr "var3d"
>   ..@ extent  :Formal class 'Extent' [package "raster"] with 4 slots
>   .. .. ..@ xmin: num -30
>   .. .. ..@ xmax: num -8.01
>   .. .. ..@ ymin: num 60
>   .. .. ..@ ymax: num 68
>   ..@ rotated : logi FALSE
>   ..@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
>   .. .. ..@ geotrans: num(0)
>   .. .. ..@ transfun:function ()
>   ..@ ncols   : int 440
>   ..@ nrows   : int 160
>   ..@ crs     :Formal class 'CRS' [package "sp"] with 1 slots
>   .. .. ..@ projargs: chr "+proj=longlat +datum=WGS84"
>   ..@ history : list()
>   ..@ z       :List of 1
>   .. ..$ days: int [1:464(1d)] 341 41 169 281 409 69 197 309 437 101 ...
>
> atb,
> Kristin
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Extract-points-from-raster-brick-by-both-location-and-a-matching-attributes-tp7587083.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list