Skip to content
Snippets Groups Projects
Commit 0910b656 authored by Dennis Walvoort's avatar Dennis Walvoort
Browse files

updated rgl-code and proj4-code

parent a16c2c98
Branches
Tags
No related merge requests found
......@@ -8,56 +8,15 @@ output:
toc_depth: 4
vignette: >
%\VignetteIndexEntry{Introduction to the **spcosa**-package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
---
```{r, echo=FALSE}
# suggested package (see 1.1.3.1 of writing R extensions)
if (requireNamespace("rgl", quietly = TRUE)) {
# source: setup.R in rgl-package (by Duncan Murdoch)
options(rgl.useNULL=TRUE)
hook_webgl <- local({
commonParts <- TRUE
function (before, options, envir)
{
if (before || rgl::rgl.cur() == 0 || !requireNamespace("knitr"))
return()
out_type <- knitr::opts_knit$get("out.format")
if (!length(intersect(out_type, c("markdown", "html"))))
stop("hook_webgl is for HTML only. Use knitr::hook_rgl instead.")
name <- tempfile("webgl", tmpdir = ".", fileext = ".html")
on.exit(unlink(name))
dpi <- 96 # was options$dpi
rgl::par3d(windowRect = dpi * c(0, 0, options$fig.width,
options$fig.height))
Sys.sleep(0.1)
prefix = gsub("[^[:alnum:]]", "_", options$label)
prefix = sub("^([^[:alpha:]])", "_\\1", prefix)
rgl::writeWebGL(dir = dirname(name),
filename = name,
snapshot = !rgl::rgl.useNULL(),
template = NULL,
prefix = prefix,
commonParts = commonParts)
if (!isTRUE(options$rgl.keepopen) && rgl::rgl.cur())
rgl::rgl.close()
commonParts <<- FALSE
res <- readLines(name)
res <- res[!grepl("^\\s*$", res)]
paste(gsub("^\\s+", "", res), collapse = "\n")
}
})
knitr::knit_hooks$set(rgl = hook_webgl)
}
knitr::knit_hooks$set(webgl = rgl::hook_webgl)
}
knitr::opts_chunk$set(comment = NA)
set.seed(314)
```
......@@ -240,7 +199,7 @@ As an example, we will use the **gstat** package for predicting clay contents by
#coordinates(sp_data) <- ~ x * y
sp_data <- SpatialPointsDataFrame(coords = sampling_points, data = my_data)
```
Next, the sample variogram for clay has to be estimated, and needs to be fitted by a permissable model:
Next, the sample variogram for clay has to be estimated, and needs to be fitted by a permissible model:
```{r, fig.width=7, fig.height=5, out.width=400}
sample_variogram <- variogram(clay ~ 1, sp_data)
variogram_model <- fit.variogram(sample_variogram,
......@@ -510,7 +469,7 @@ grd <- expand.grid(
gridded(grd) <- ~ longitude * latitude
grd_crs <- grd
proj4string(grd_crs) <- CRS("+proj=longlat +ellps=WGS84")
proj4string(grd_crs) <- CRS("EPSG:4326")
```
Note that `grd` is identical to `grd_crs`, except that `grd_crs` has projection attributes. If no projection attributes are available, the algorithms in the **spcosa**-package use squared Euclidean distances in the _k_-means algorithms. However, if projection attributes have been set, the coordinates will be transformed to lat/long format (latitude/longitude) and squared great circle distances will be used instead.
......@@ -530,7 +489,7 @@ Note that `grd` seems to have more compact strata near the geographic poles than
```{r, echo=FALSE}
```{r, echo=FALSE, eval=requireNamespace("rgl", quietly = TRUE)}
# internal function for converting LatLong to XYZ format (r: radius of the earth in km)
.latLongToXYZ <-
function(x, r = 6378.1) {
......@@ -580,8 +539,7 @@ function(x) {
}
```
```{r, rgl=TRUE, eval=requireNamespace("rgl", quietly = TRUE), echo=FALSE, results='hide', fig.width=7, fig.height=4}
```{r, eval=requireNamespace("rgl", quietly = TRUE), echo=FALSE, results='hide', fig.width=7, fig.height=4, webgl=TRUE}
rgl::open3d(userMatrix = rbind(
c( 0.73, -0.63, 0.25, 0),
c( 0.37, 0.69, 0.63, 0),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment