[R-sig-Geo] Interpolating snowfall values on a Digital Elevation Model

Stefano Sofia stefano.sofia at regione.marche.it
Tue Feb 13 09:45:34 CET 2018


Dear Daniel and list users,
I tried to follow the instructions but I encountered two kinds of errors.
This is a reproducibile code:

---------------------------------------------------------------------------------------------------------------
library(automap)
library(ggplot2)
library(gstat)
library(raster)
library(rasterVis)
library(rgdal)
library(maptools)

## LOADING DEM
ita_DEM <- getData('alt', country='ITA', mask=TRUE)
crs(ita_DEM) <- "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
#ita_DEM <- as(ita_DEM, "SpatialGridDataFrame")
str(ita_DEM)

## LOADING RAINFALL DATA
rain_data <- data.frame(Cumulata=c(11.8, 9.0, 8.0, 36.6, 9.4), Long_Cent=c(12.61874, 12.78690, 12.96756, 13.15599, 13.28157), Lat_Cent=c(43.79447, 43.85185, 43.76267, 43.03470, 43.08003), Altitude=c(112.20, 42.93, 36.14, 747, 465))

stations <- data.frame(rain_data$Long_Cent, rain_data$Lat_Cent)
rain_data <- SpatialPointsDataFrame(stations, rain_data, proj4string=CRS("+init=epsg:4326"))
stations <- SpatialPoints(stations, proj4string=CRS("+init=epsg:4326"))

## EXTRACT THE ELEVATION VALUES TO MY POINTS
rain_data$ExtractedElevationValues <- extract(x=ita_DEM, y=stations)

## CREATE GRID FOR KRIGING OUTPUT
minx <-  rain_data at bbox[1,1]
maxx <- rain_data at bbox[1,2]
miny <- rain_data at bbox[2,1]
maxy <- rain_data at bbox[2,2]
pixel <- 0.01
grd <- expand.grid(x=seq(minx, maxx, by=pixel), y=seq(miny, maxy, by=pixel))
coordinates(grd) <- ~x+y
gridded(grd) <- TRUE
proj4string(grd) <- CRS("+init=epsg:4326")

## KRIGING: autoKrige(YourMeasurements ~ YourExtractedElevationValues, YourMeasurementLocations, TargetGrid)
OK_snow <- autoKrige(Cumulata ~ rain_data$ExtractedElevationValues, rain_data, grd)
-------------------------------------------------------------------------------------------------------------------------------

The error I get is:
Error in autoKrige(Cumulata ~ rain_data$ExtractedElevationValues, rain_data,  :
  Either input_data or new_data is in LongLat, please reproject.
   input_data:  +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
   new_data:    +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0

but I did pay attention to have the same reference system in rain_data, drg and the Digital Elevation Model.

Moreover, if I impose the class of the DEM to SpatialGridDataFrame when I extraxt the elevation points from the DEM I get the following error:
Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘extract’ for signature ‘"SpatialGridDataFrame", "SpatialPoints"’
Calls: extract -> <Anonymous>


Would you please somebody help to show me where is my mistake?

Thank you for all your attention
Stefano

         (oo)
--oOO--( )--OOo----------------
Stefano Sofia PhD
Area Meteorologica e  Area nivologica - Centro Funzionale
Servizio Protezione Civile - Regione Marche
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona
Uff: 071 806 7743
E-mail: stefano.sofia at regione.marche.it
---Oo---------oO----------------
________________________________________
Da: R-sig-Geo [r-sig-geo-bounces at r-project.org] per conto di Daniel Knitter [knitter at geographie.uni-kiel.de]
Inviato: lunedì 12 febbraio 2018 9.16
A: r-sig-geo at r-project.org
Oggetto: Re: [R-sig-Geo]  Interpolating snowfall values on a Digital Elevation Model

...sorry, I missed one step: you need to extract the elevation values to your points via extract function from the raster package:

YourPoints$YourExtractedElevationValues <- extract(x = DEM, y = YourPoints)

autoKrige(YourMeasurements ~ YourExtractedElevationValues, YourMeasurementLocations, TargetGrid)


Sorry for spamming.

Best,
Daniel

On Mon, 12 Feb 2018 08:03:41 +0000
Stefano Sofia <stefano.sofia at regione.marche.it> wrote:

> Dear list users,
> I have to produce rainfall maps. I know how to create a (bi-dimensional) grid and interpolate rainfall values (from automatic rain gauges) on that grid using Kriging:
>
> myinterpolation <- autoKrige(myrainfall_cumulate ~ 1, rain_data_UTM, mygrid)
>
> In reality I am dealing with snowfall values on mountain regions, and in this case altitude is an important factor, the use of a Digital Elevation Model might make the difference.
> Looking in the web I found some important material about accessing elevation data in R with the "elevatr" package (by J.W.Hollister), I am reading it.
> My concern would then be to interpolate snowfall values on a Digital Elevation Model. Did somebody already use R for these kinds of calculations? Could somebody share with me some useful hints?
>
> Thank you for your attention
> Stefano Sofia
>
>
>          (oo)
> --oOO--( )--OOo----------------
> Stefano Sofia PhD
> Area Meteorologica e  Area nivologica - Centro Funzionale
> Servizio Protezione Civile - Regione Marche
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona
> Uff: 071 806 7743
> E-mail: stefano.sofia at regione.marche.it
> ---Oo---------oO----------------
>
> ________________________________
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.
>
> --
> This message was scanned by Libra ESVA and is believed to be clean.
>
>
>       [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://urlsand.esvalabs.com/?u=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&e=52342f8a&h=f7d4a649&f=y&p=y


--

Dr. Daniel Knitter
CRC1266 -- Scales of Transformation
Project A2 "Integrative Modeling of Socio-Environmental Dynamics"

Christian-Albrechts-Universität zu Kiel
Department of Geography
Physical Geography -- Landscape Ecology and Geoinformation
Ludewig-Meyn-Str. 14, room 109
D - 24118 Kiel, Germany

Phone: +49 431 880 2941
Email: knitter at geographie.uni-kiel.de

________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.

--
This message was scanned by Libra ESVA and is believed to be clean.



More information about the R-sig-Geo mailing list