autokriging and SpatialPixel grid file

244 views Asked by At

I am trying to use autoKrige in automap package. My data looks like

head(LL12)

  Location Longitude  Latitude   percent
1       L1  16.48476 -28.60737 1.0000000
2       L3  16.90045 -29.24154 1.0000000
3       L4  16.99268 -28.44906 0.6363636
4       L5  17.06871 -29.67825 1.0000000
5       L6  17.09935 -29.00169 0.6000000
6       L7  17.25630 -28.82418 1.0000000

and I am trying to plot this in a South African map.

First I obtained the grid following Create Grid in R for kriging in gstat

SAgrd <- makegrid(SApol_border, n = 1000)

colnames(SAgrd) <- c('lon','lat')

SAgrd_pts <- SpatialPoints(coords = SAgrd, 
                           proj4string=CRS(proj4string(SApol_border)))


SAgrd_pts_in <- SAgrd_pts[SApol_border, ]

plot(SAgrd_pts_in)

plot(SAgrd_pts_in)

enter image description here

then I convert it to a SpatialPixel dataframe

SAgrd_pts_in = as(SAgrd_pts_in,"SpatialPixelsDataFrame") 

but plot(SAgrd_pts_in) gives the follwoing error message:

Error in .subset2(x, i, exact = exact) : subscript out of bounds

and when I want to use the following line in autokriging also gives error message

krigLL12_fit <- autoKrige(percent~1, SA.grid, LL12spdf) # percent is the variable of interest in the spdf LL12spdf

error message:

Error in autoKrige(percent ~ 1, SA.grid, LL12spdf) : Either input_data or new_data is in LongLat, please reproject. input_data: +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs new_data: NA In addition: Warning messages: 1: In proj4string(input_data) : CRS object has comment, which is lost in output 2: In proj4string(input_data) : CRS object has comment, which is lost in output 3: In showSRID(uprojargs, format = "PROJ", multiline = "NO") : Discarded datum Unknown based on WGS84 ellipsoid in CRS definition, but +towgs84= values preserved

I am very new in this topic and cannot realize what I need to do, or what to correct, the coordinate units look the same in the grid and in the data file. I also fitted an autovariogram and tried to use in in autokrige but it doean't work either. thnx.

1

There are 1 answers

0
Maria Eugenia D'Amato On

I found the problem: the grid file required to apply NA to its crs, and then transform it to a Spatial Pixels file, instead of Spatial Pixels Data Frame. I expanded on this, with codes and results in https://gis.stackexchange.com/questions/375476/0-0-kriging-error-messages-grid-file-problem-automap-gstat