-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
91 lines (68 loc) · 2.22 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# vg250
<!-- badges: start -->
[![R-CMD-check](https://github.com/dimfalk/vg250/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dimfalk/vg250/actions/workflows/R-CMD-check.yaml)
[![Codecov](https://codecov.io/gh/dimfalk/vg250/graph/badge.svg)](https://app.codecov.io/gh/dimfalk/vg250)
<!-- badges: end -->
vg250 aims to provide access to VG250 dataset in order to derive spatial
information for a chosen administrative level for various applications.
Since I found myself in the need of spatial information on a municipality level
(geometry, extent, centroids) for convenience reasons quite often, the decision
was made to centralize associated data and functions based on `{sf}` in a
separate package to simplify maintenance.
## Installation
You can install the development version of vg250 with:
``` r
# install.packages("devtools")
devtools::install_github("dimfalk/vg250")
```
## Basic examples
Just a few quick insights on the use of this package:
```{r example}
library(vg250)
# fetch data
name <- "Aachen"
ext <- get_extent(name)
buff <- get_extent(name, buffer = 5000)
geom <- get_geometry(name)
p <- get_centroid(name)
# check classes
class(ext)
class(buff)
class(geom)
class(p)
# inspect visually
library(ggplot2)
ggplot() +
geom_sf(data = buff) +
geom_sf(data = ext, col = "green") +
geom_sf(data = geom, col = "red") +
geom_sf(data = p, col = "blue")
```
This information can now be used to e.g. create masks to crop raster data,
select vector features, perform spatial joins, construct API calls, etc.
```{r warning = FALSE}
# convert to SpatExtent object when working with `{terra}`
terra::vect(ext) |> terra::ext()
# select vector features by p
sf::st_filter(vg250, p)
# join attributes spatially to p
sf::st_intersection(vg250, p)
# construct API queries
sf::st_bbox(ext) |> as.numeric() |> round(4) |> paste0(collapse = ",") |> paste0("&bbox=", x = _)
```
Note: The VG250 dataset itself can be accessed via `vg250`:
```{r warning = FALSE}
vg250
```