-
Notifications
You must be signed in to change notification settings - Fork 2
Projecting data
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)
## $names
## [1] "x" "y"
##
## $row.names
## [1] 1 2 3 4 5 6 7 8 9 10 11
##
## $class
## [1] "data.frame"
##
## $projection
## [1] "+proj=longlat +init=epsg:4326 +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
##
## $resX
## [1] 0But 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)
## $names
## [1] "x" "y"
##
## $projection
## [1] "LatLonProjection"
##
## $resX
## [1] 0.5
##
## $resY
## [1] 0.5However, 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))
We might only be interested in defining the projection and not in transforming it:
def_EOBS_Iberia_pr <- projectGrid(EOBS_Iberia_pr,
original.CRS = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")



