Skip to content

Projecting data

miturbide edited this page Oct 16, 2018 · 11 revisions

Grid datum definition and transformation is performed by function projectGrid.

In the first example we use VALUE station data in the form of a climate4R object (included in package transformeR).

library(transformeR)
data("VALUE_Iberia_pr")

For an overview of the spatial shape of this data we can extract the coordinates of the object (with getCoordinates) and plot them:

plot(getCoordinates(VALUE_Iberia_pr))

This object has a defined projection:

attributes(VALUE_Iberia_pr$xyCoords)

But we want to transform the datum of the object (new.CRS = "+init=epsg:28992")

new <- projectGrid(VALUE_Iberia_pr,
                     new.CRS = "+init=epsg:28992")
plot(getCoordinates(new))

We can perform the same operation for gridded data (e.g. object EOBS_Iberia_pr).

data("EOBS_Iberia_pr")
plot(get2DmatCoordinates(EOBS_Iberia_pr))

This object has not a standard definition of the projection.

attributes(EOBS_Iberia_pr$xyCoords)

However, we do know from the data provider that the datum and other projection arguments are: "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0" as passed to function CRS (package rgdal). Therefore we give this information to argument original.CRS to define the original projection and allow the transformation.

grid <- projectGrid(EOBS_Iberia_pr,
                     original.CRS = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0",
                     new.CRS = "+init=epsg:28992")
plot(get2DmatCoordinates(grid))

In this example we also use package visualizeR (function spatialPlot) to plot the original and projected data.

require(visualizeR)
spatialPlot(climatology(EOBS_Iberia_pr))
spatialPlot(climatology(grid))

Clone this wiki locally