Skip to content

Spatial overlay

miturbide edited this page Oct 17, 2018 · 1 revision

Function overGrid performs spatial overlay for grids and Spatial* objects. It applies function over from package sp to climate4R grids or station data.

For example, imagine that we want to work with this grid (included in the transformeR package, see the Wiki):

data("EOBS_Iberia_pr")

We can visualize the mean climatology with functions spatialPlot and climatology (package visualizeR, see the Wiki):

require("visualizeR")
spatialPlot(climatology(EOBS_Iberia_pr))

Let's suppose that the extension is too big and that we only want the grid boxes that fall inside the Iberian Peninsula as defined by the PRUDENCE regions. Then we will need a Spatial* object (type help(package = "sp") for more information) of the region of interest. In this case, we can obtain the SpatialPolygons object of the PRUDENCE regions from the visualizeR package (The Iberian Peninsula corresponds to the second polygon of the object).

data("PRUDENCEregions")
IP <- PRUDENCEregions[2,]
spatialPlot(climatology(EOBS_Iberia_pr), sp.layout = list(IP, first = FALSE))

Next we apply overGrid.

ov <- overGrid(EOBS_Iberia_pr, layer = IP)
spatialPlot(climatology(ov), sp.layout = list(IP, first = FALSE))

Note that the values of the grid boxes outside IP have been substituted with NA (they have no color in the previous map). If we prefer to directly remove those grid boxes we set argument subset = TRUE:

ovs <- overGrid(EOBS_Iberia_pr, layer = IP, subset = TRUE)
spatialPlot(climatology(ovs), sp.layout = list(IP, first = FALSE))

Clone this wiki locally