We define the Space dimension
defineDefaultSpace(ESpaceType_RN(), 2)
## NULL
Creating a dummy Model used for simulating a random field
mymodel = Model_createFromParam(ECov_CUBIC(), range=10, sill=1)
We construct a standard non rotated 2-D grid with two simulated variables
nx = c(70,25)
dx = c(1,2)
x0 = c(-40, 20)
mygrid = DbGrid_create(nx,dx,x0)
err = simtub(NULL,mygrid,mymodel,nbsimu=2)
mygrid$display()
##
## Data Base Grid Characteristics
## ==============================
##
## Data Base Summary
## -----------------
## File is organized as a regular grid
## Space dimension = 2
## Number of Columns = 5
## Total number of samples = 1750
##
## Grid characteristics:
## ---------------------
## Origin : -40.000 20.000
## Mesh : 1.000 2.000
## Number : 70 25
##
## Variables
## ---------
## Column = 0 - Name = rank - Locator = NA
## Column = 1 - Name = x1 - Locator = x1
## Column = 2 - Name = x2 - Locator = x2
## Column = 3 - Name = Simu.1 - Locator = z1
## Column = 4 - Name = Simu.2 - Locator = z2
## NULL
We construct a Selection
mygrid["sel"] = 1. -
(mygrid["x1"] > 0) * (mygrid["x1"] < 15) * (mygrid["x2"] > 40) * (mygrid["x2"] < 50)
err = mygrid$setLocator("sel",ELoc_SEL())
mygrid
##
## Data Base Grid Characteristics
## ==============================
##
## Data Base Summary
## -----------------
## File is organized as a regular grid
## Space dimension = 2
## Number of Columns = 6
## Total number of samples = 1750
## Number of active samples = 1694
##
## Grid characteristics:
## ---------------------
## Origin : -40.000 20.000
## Mesh : 1.000 2.000
## Number : 70 25
##
## Variables
## ---------
## Column = 0 - Name = rank - Locator = NA
## Column = 1 - Name = x1 - Locator = x1
## Column = 2 - Name = x2 - Locator = x2
## Column = 3 - Name = Simu.1 - Locator = z1
## Column = 4 - Name = Simu.2 - Locator = z2
## Column = 5 - Name = sel - Locator = sel
Displaying the grid cells
p = ggDefaultGeographic()
p = p + plot.grid(mygrid, nameRaster="Simu.1", nameContour="Simu.2",
flagLegendRaster=TRUE, legendNameRaster="ma Legende")
p = p + plot.decoration(title="Display of Grid Cells")
ggPrint(p)
Using another collor scale. Among the different choices, one makes it possible to create a color scale on the fly, specifying the starting (yellow), middle (red) and ending (blue) colors. The color referred to as 'naColor' serves for encoding pixels whose values have been left undefined.
ggDefaultGeographic() + plot.grid(mygrid, palette=c("yellow","red","blue"), naColor="white")
Displaying the grid nodes only
p = ggDefaultGeographic()
p = p + plot.point(mygrid, nameColor="Simu.1",nameSize="Simu.2",
flagLegendColor = TRUE,
legendNameColor="myColor")
p = p + plot.decoration(title="Display of Grid Nodes")
ggPrint(p)
mygrid = DbGrid_create(nx,dx,x0,angles=c(10,0))
err = simtub(NULL,mygrid,mymodel,nbsimu=2)
mygrid
##
## Data Base Grid Characteristics
## ==============================
##
## Data Base Summary
## -----------------
## File is organized as a regular grid
## Space dimension = 2
## Number of Columns = 5
## Total number of samples = 1750
##
## Grid characteristics:
## ---------------------
## Origin : -40.000 20.000
## Mesh : 1.000 2.000
## Number : 70 25
## Rotation Angles = 10.000 0.000
## Direct Rotation Matrix
## [, 0] [, 1]
## [ 0,] 0.985 -0.174
## [ 1,] 0.174 0.985
## Inverse Rotation Matrix
## [, 0] [, 1]
## [ 0,] 0.985 0.174
## [ 1,] -0.174 0.985
##
## Variables
## ---------
## Column = 0 - Name = rank - Locator = NA
## Column = 1 - Name = x1 - Locator = x1
## Column = 2 - Name = x2 - Locator = x2
## Column = 3 - Name = Simu.1 - Locator = z1
## Column = 4 - Name = Simu.2 - Locator = z2
Displaying the cell contents in the rotated grid
p = ggDefaultGeographic()
p = p + plot.grid(mygrid, nameRaster="Simu.1", flagLegendRaster=FALSE)
p = p + plot.decoration(title="Display of Rotated Grid")
ggPrint(p)
As a set of grid nodes
p = ggDefaultGeographic()
p = p + plot.point(mygrid,nameColor="Simu.1", flagLegendColor = TRUE)
p = p + plot.decoration(title="Display of Rotated Grid Nodes")
ggPrint(p)
A set of points is sampled from the previous Grid and stored in a new Point Db. The number of samples if fixed to 1% of the number of grid nodes.
mypoint = Db_createSamplingDb(mygrid,0.01)
mypoint$display()
##
## Data Base Characteristics
## =========================
##
## Data Base Summary
## -----------------
## File is organized as a set of isolated points
## Space dimension = 2
## Number of Columns = 6
## Total number of samples = 17
##
## Variables
## ---------
## Column = 0 - Name = rank - Locator = NA
## Column = 1 - Name = rank.1 - Locator = NA
## Column = 2 - Name = x1 - Locator = x1
## Column = 3 - Name = x2 - Locator = x2
## Column = 4 - Name = Simu.1 - Locator = z1
## Column = 5 - Name = Simu.2 - Locator = z2
## NULL
We create a polygon as the convex hull of the samples
mypoly = Polygons_createFromDb(mypoint)
We now display the points and the polygon on top of the grid: the overlay is ensured by using the argument 'p'.
p = ggDefaultGeographic()
p = p + plot(mygrid)
p = p + plot(mypoly, fill=NA, color='yellow', linewidth=1)
p = p + plot(mypoint,color="black")
p = p + plot.decoration(title="mon titre", xlab="mon axe des X", ylab="Mon axe des Y")
ggPrint(p)
We create two layers containing the Point and the Grid representation. We then use ggarrange to display them side-by-side.
p1 = ggDefaultGeographic() + plot(mygrid)
p2 = ggDefaultGeographic() + plot(mypoint)
ggarrange(p1, p2, labels = c("Plot #1", "Plot #2"), ncol = 2, nrow = 1)