Re: [R] Error with sf ordinary kriging after creating grid

2020-08-13 Thread Bert Gunter
You should post on r-sig-geo, not here. The specific expertise you seek is
much more likely to be found there.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Aug 13, 2020 at 4:09 AM Nicola Gambaro  wrote:

> I want to perform ordinary kriging of temperature (UTCI) data in Nigeria
> with sf and gstat packages. However, after fitting the variogram model and
> creating a grid for the region, the krige function returns this error:
>
> Error in (function (classes, fdef, mtable)  :
>   unable to find an inherited method for function ‘krige’ for signature
> ‘"formula", "sfc_POINT"’
> What am I doing wrong? Here is my code:
>
> library(gstat)
> library(sf)
> sf_data <- st_as_sf(x = data, coords = c("longitude", "latitude"), crs =
> 4326)
>
> #VARIOGRAM
> vgm_utci <- variogram(UTCI~1, sf_data)
> utci_fit <- fit.variogram(vgm_utci, vgm("Mat"), fit.kappa = TRUE)
>
> #CREATE GRID
> nigeria <- read_sf("./Igismap/Nigeria_Boundary.shp")
> nigeria <- nigeria$geometry
> nigeria.grid <- nigeria %>%
>   st_make_grid(cellsize = 0.1, what = "centers") %>%
>   st_intersection(nigeria)
>
> #UTCI ORDINARY KRIGING
> utci_krig <- krige(formula = sf_data$UTCI ~ 1, nigeria.grid, model =
> utci_fit)
> When plotted, the grid and the variogram model look fine. I have attached
> data and shapefile. Thank you so much in advance,
>
> Nicola
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Error with sf ordinary kriging after creating grid

2020-08-13 Thread Nicola Gambaro
I want to perform ordinary kriging of temperature (UTCI) data in Nigeria with 
sf and gstat packages. However, after fitting the variogram model and creating 
a grid for the region, the krige function returns this error:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘krige’ for signature 
‘"formula", "sfc_POINT"’
What am I doing wrong? Here is my code:

library(gstat)
library(sf)  
sf_data <- st_as_sf(x = data, coords = c("longitude", "latitude"), crs = 4326)

#VARIOGRAM  
vgm_utci <- variogram(UTCI~1, sf_data)
utci_fit <- fit.variogram(vgm_utci, vgm("Mat"), fit.kappa = TRUE)
   
#CREATE GRID
nigeria <- read_sf("./Igismap/Nigeria_Boundary.shp")
nigeria <- nigeria$geometry
nigeria.grid <- nigeria %>% 
  st_make_grid(cellsize = 0.1, what = "centers") %>%
  st_intersection(nigeria)

#UTCI ORDINARY KRIGING
utci_krig <- krige(formula = sf_data$UTCI ~ 1, nigeria.grid, model = utci_fit)
When plotted, the grid and the variogram model look fine. I have attached data 
and shapefile. Thank you so much in advance,

Nicola
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.