Skip to content
Prev 18368 / 29559 Next

Kriging and datum shifts

For a simple approach I would just do on the raw coordinates in the
SPDF. You could operate on the NetCDF file itself by reading from it
directly as a matrix with vectors, but since you mention the SPDF why
not just do this:

x <- as.data.frame(spdf)
## figure out what "longitude" and "latitude" are called here
lon <- x$longitude
x$longitude <- ifelse(lon < -180, lon + (-180 - -280), lon)

## reconstruct, also with what "longitude" and "latitude" are named
xr <- SpatialPointsDataFrame(x[, c("longitude", "latitude")], x,
proj4string = CRS(proj4string(spdf)))

(Though I doubt you have a valid CRS string in your original object
already, the above will work. To give it one replace the proj4string
call with "+proj=longlat +datum=WGS84").

Now proceed with xr instead.

There is rotate() in the raster package, though it's only for one
special case. You can easily crop and re-merge the two parts as
rasters with that package too, and you can do the same with and
subsetting and recombining in sp, but in this case I would go as far
back to the source first. R has excellent tools for dealing with data
that need some kind of pre-preparation before they are ready for these
spatial tools.  As an example, sp will baulk at this

 SpatialPointsDataFrame(cbind(c(-280, -100), c(-40, -60)),
data.frame(x = 1:2), proj4string = CRS("+proj=longlat"))


Since you are reading data from NetCDF and they are on an irregular
grid I would also spend time becoming familiar with that by reading
from it with generic tools like ncdf or ncdf4 or RNetCDF, R's image()
list structure will handle irregular coordinates in one or two
dimensions and sometimes that can save you from confusion or pain.


Also, sometimes NetCDF data are using some underlying map projection
and if you can discover that rather than work in the irregular lon/lat
you'll be able to cast more directly to these rigid grid/raster
objects. Mercator is commonly used for global grids and provides
irregular latitudes for example. Can you point to one of these files?

Cheers, Mike.
On Tue, May 28, 2013 at 12:50 AM, Jeroen Steenbeek <drmbongo at gmail.com> wrote: