Skip to content
Prev 6066 / 29559 Next

[SoC v.autokrige2.py] autoKrige() and projected data

Hi Edzer, Anne and r-sig-geo,

I adapted the code of automap in reaction to this problem and included 
it in the new version of automap taht should be released somewhere next 
week.

from the documentation of autoKrige():

'autoKrige' performs some checks on the coordinate systems of
     'input_data' and 'new_data'. If one of both is 'NA', it is
     assigned the projection of the other. If they have different
     projections, an error is raised. If one of both has a
     non-projected system (i.e. latitude-longitude), an error is
     raised. This error is raised because 'gstat does use spherical
     distances when data are in geographical coordinates, however the
     usual variogram models are typically not non-negative definite on
     the sphere, and no appropriate models are available' (Edzer
     Pebesma on r-sig-geo).

This code illustrates the new functionality:

library(automap)
library(rgdal)
data(meuse)
coordinates(meuse) = ~x+y
data(meuse.grid)
gridded(meuse.grid) = ~x+y
proj4string(meuse) = CRS("+init=epsg:28992")

# new_data gets projection of input_data
autoKrige(log(zinc)~1, meuse, meuse.grid)

proj4string(meuse.grid) = CRS("+init=epsg:28992")
# Reproject to latlong
meuse_ll = spTransform(meuse, CRS("+init=epsg:4238"))
# Reproject to another projected system (LAEA)
meuse2 = spTransform(meuse, CRS("+init=epsg:3034"))
# Reproject to latlong
meuse.grid_ll = spTransform(meuse.grid, CRS("+init=epsg:4238"))

autoKrige(log(zinc)~1, meuse, meuse.grid)    # Should work
autoKrige(log(zinc)~1, meuse_ll, meuse.grid) # Should fail
autoKrige(log(zinc)~1, meuse, meuse.grid_ll) # Should fail
autoKrige(log(zinc)~1, meuse2, meuse.grid)   # Should fail

cheers,
Paul
Edzer Pebesma wrote: