https://github.com/mdsumner/llbox
https://github.com/mdsumner/llbox
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mdsumner/llbox
- Owner: mdsumner
- Created: 2021-11-25T05:10:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-29T05:10:35.000Z (over 4 years ago)
- Last Synced: 2025-05-19T16:13:27.581Z (about 1 year ago)
- Language: R
- Size: 70.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
editor_options:
chunk_output_type: console
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# llbox
The goal of llbox is to ... have control over building graticules.
There are simple cases ... we can do curvature analysis (see tissot) for more complex ones, or segment subdivision ala D3.
This is how to make tiles. Do the start and end edge of a series of longitudes and latitudes.
```{r tiles}
library(llbox)
devtools::load_all()
#system.time({
to_sf <- function(x) {
#sfheaders::sfc_polygon(polygonate(x))
sf::st_sfc(sf::st_polygon(list(polygonate(x))), crs = "OGC:CRS84")
}
proj <- "+proj=murd3 +lat_1=30 +lat_2=50"
# proj <- "+proj=tobmerc"
# proj <- "+proj=laea"
# proj <- "+proj=peirce_q"
gridx <- seq(-180, 180, by = 10)
gridy <- seq(-50, 90, by = 15)
x0 <- list()
revm <- function(x) {
x[seq(nrow(x), 1), ]
}
nv <- 180
for (i in seq_along(head(gridx, -1))) {
for (j in seq_along(head(gridy, -1))) {
ww <- west(x = gridx[i], y = gridy[j + c(0, 1)], nverts = nv)
nn <- north(x = gridx[i + c(0, 1)], y = gridy[j + 1], nverts = nv)
ee <- revm(east(x = gridx[i + 1], y = gridy[j + c(0, 1)], nverts = nv))
ss <- revm(south(x = gridx[i + c(0, 1)], y = gridy[j], nverts = nv))
x0 <- c(x0, list(rbind(ww, nn, ee, ss)))
}
}
sfx <- sf::st_transform(do.call(c, lapply(x0, to_sf)), proj)
#})
plot(sfx)
```
This is how to make lines.
```{r lines}
xs <- seq(-175, 175, by = 15)
ys <- seq(-75, 75, by = 10)
meridians <- lapply(xs, \(x) west(x, c(-85, 85)))
parallels <- lapply(ys, \(x) north(c(-180, 180), x, nverts = 120))
to_sfl <- function(x) {
sf::st_sfc(sf::st_linestring(x), crs = "OGC:CRS84")
}
sfx <- sf::st_transform(do.call(c, lapply(c(meridians, parallels), to_sfl)), proj)
plot(sfx)
```
## Code of Conduct
Please note that the llbox project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.