how to get an attribute from a raster layer

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get an attribute from a raster layer

Antonio Silva
Dear list members

I need help to do something that should be easy but I could not execute.

I just want to plot a raster layer and use "z-value" as the title.

rst.data[[1]]
class       : RasterLayer
band        : 1  (of  4  bands)
dimensions  : 33, 45, 1485  (nrow, ncol, ncell)
resolution  : 0.25, 0.25  (x, y)
extent      : -50.25, -39, -29, -20.75  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : /mnt/.../dataset-sss-ssd-rep-monthly_2016-11-12_sos.nc
names       : X2016.11.15.1
z-value     : 2016-11-15
zvar        : sos

Is it possible to extract the z-value value directly (2016-11-15)?

The best I could do was

plot(rst.data[[1]],main=substr(names(rst.data[[1]]),2,11))

Thanks a lot

Antonio Olinto
Fisheries Institute
São Paulo, Brazil

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: how to get an attribute from a raster layer

Ben Tupper
Hi,

You are looking for raster::getZ() but be aware that the Z value can be of any type - in this case I would guess it is a Date class so you will need to cast it to character using format() to get a label you desire.

https://www.rdocumentation.org/packages/raster/versions/2.8-4/topics/z-values


Cheers,
Ben

> On Dec 28, 2018, at 10:04 AM, Antonio Silva <[hidden email]> wrote:
>
> Dear list members
>
> I need help to do something that should be easy but I could not execute.
>
> I just want to plot a raster layer and use "z-value" as the title.
>
> rst.data[[1]]
> class       : RasterLayer
> band        : 1  (of  4  bands)
> dimensions  : 33, 45, 1485  (nrow, ncol, ncell)
> resolution  : 0.25, 0.25  (x, y)
> extent      : -50.25, -39, -29, -20.75  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : /mnt/.../dataset-sss-ssd-rep-monthly_2016-11-12_sos.nc
> names       : X2016.11.15.1
> z-value     : 2016-11-15
> zvar        : sos
>
> Is it possible to extract the z-value value directly (2016-11-15)?
>
> The best I could do was
>
> plot(rst.data[[1]],main=substr(names(rst.data[[1]]),2,11))
>
> Thanks a lot
>
> Antonio Olinto
> Fisheries Institute
> São Paulo, Brazil
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: how to get an attribute from a raster layer

Antonio Silva
Dear Ben

Thanks again. I didn't find this function in my search.

Happy new year to all.

Antonio Olinto

Em sex, 28 de dez de 2018 às 13:19, Ben Tupper <[hidden email]>
escreveu:

> Hi,
>
> You are looking for raster::getZ() but be aware that the Z value can be of
> any type - in this case I would guess it is a Date class so you will need
> to cast it to character using format() to get a label you desire.
>
>
> https://www.rdocumentation.org/packages/raster/versions/2.8-4/topics/z-values
>
>
> Cheers,
> Ben
>
> On Dec 28, 2018, at 10:04 AM, Antonio Silva <[hidden email]> wrote:
>
> Dear list members
>
> I need help to do something that should be easy but I could not execute.
>
> I just want to plot a raster layer and use "z-value" as the title.
>
> rst.data[[1]]
> class       : RasterLayer
> band        : 1  (of  4  bands)
> dimensions  : 33, 45, 1485  (nrow, ncol, ncell)
> resolution  : 0.25, 0.25  (x, y)
> extent      : -50.25, -39, -29, -20.75  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : /mnt/.../dataset-sss-ssd-rep-monthly_2016-11-12_sos.nc
> names       : X2016.11.15.1
> z-value     : 2016-11-15
> zvar        : sos
>
> Is it possible to extract the z-value value directly (2016-11-15)?
>
> The best I could do was
>
> plot(rst.data[[1]],main=substr(names(rst.data[[1]]),2,11))
>
> Thanks a lot
>
> Antonio Olinto
> Fisheries Institute
> São Paulo, Brazil
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: how to get an attribute from a raster layer

David L Carlson
Where did you search? My google search for "getZ package raster" found it easily. If you have loaded the raster package, then the command ?getZ brings up the manual page:

> library(raster)
Loading required package: sp
> ?getZ

--------------------------------------
David L. Carlson
Department of Anthropology
Texas A&M University


-----Original Message-----
From: R-sig-Geo [mailto:[hidden email]] On Behalf Of Antonio Silva
Sent: Friday, December 28, 2018 10:39 AM
To: Ben Tupper <[hidden email]>
Cc: R-mailing list <[hidden email]>
Subject: Re: [R-sig-Geo] how to get an attribute from a raster layer

Dear Ben

Thanks again. I didn't find this function in my search.

Happy new year to all.

Antonio Olinto

Em sex, 28 de dez de 2018 às 13:19, Ben Tupper <[hidden email]>
escreveu:

> Hi,
>
> You are looking for raster::getZ() but be aware that the Z value can be of
> any type - in this case I would guess it is a Date class so you will need
> to cast it to character using format() to get a label you desire.
>
>
> https://www.rdocumentation.org/packages/raster/versions/2.8-4/topics/z-values
>
>
> Cheers,
> Ben
>
> On Dec 28, 2018, at 10:04 AM, Antonio Silva <[hidden email]> wrote:
>
> Dear list members
>
> I need help to do something that should be easy but I could not execute.
>
> I just want to plot a raster layer and use "z-value" as the title.
>
> rst.data[[1]]
> class       : RasterLayer
> band        : 1  (of  4  bands)
> dimensions  : 33, 45, 1485  (nrow, ncol, ncell)
> resolution  : 0.25, 0.25  (x, y)
> extent      : -50.25, -39, -29, -20.75  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : /mnt/.../dataset-sss-ssd-rep-monthly_2016-11-12_sos.nc
> names       : X2016.11.15.1
> z-value     : 2016-11-15
> zvar        : sos
>
> Is it possible to extract the z-value value directly (2016-11-15)?
>
> The best I could do was
>
> plot(rst.data[[1]],main=substr(names(rst.data[[1]]),2,11))
>
> Thanks a lot
>
> Antonio Olinto
> Fisheries Institute
> São Paulo, Brazil
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo