Git Product home page Git Product logo

vg250's Introduction

vg250

R-CMD-check codecov

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:

# install.packages("devtools")
devtools::install_github("dimfalk/vg250")

Basic examples

Just a few quick insights on the use of this package:

library(vg250)
#> 0.5.6
# 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)
#> [1] "sfc_POLYGON" "sfc"
class(buff)
#> [1] "sfc_POLYGON" "sfc"
class(geom)
#> [1] "sfc_POLYGON" "sfc"
class(p)
#> [1] "sfc_POINT" "sfc"
# 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.

# convert to SpatExtent object when working with `{terra}`
terra::vect(ext) |> terra::ext()
#> SpatExtent : 5.9748614, 6.2169125, 50.6627898, 50.8573535 (xmin, xmax, ymin, ymax)
# select vector features by p
sf::st_filter(vg250, p)
#> Simple feature collection with 1 feature and 5 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 5.974861 ymin: 50.66279 xmax: 6.216912 ymax: 50.85735
#> Geodetic CRS:  WGS 84
#>      GEM                 KRS                 LAN    EWZ    KFL
#> 1 Aachen Städteregion Aachen Nordrhein-Westfalen 252136 160.85
#>                             geom
#> 1 MULTIPOLYGON (((6.057066 50...
# join attributes spatially to p
sf::st_intersection(vg250, p)
#> Simple feature collection with 1 feature and 5 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 6.109002 ymin: 50.76053 xmax: 6.109002 ymax: 50.76053
#> Geodetic CRS:  WGS 84
#>         GEM                 KRS                 LAN    EWZ    KFL
#> 2145 Aachen Städteregion Aachen Nordrhein-Westfalen 252136 160.85
#>                           geom
#> 2145 POINT (6.109002 50.76053)
# construct API queries
sf::st_bbox(ext) |> as.numeric() |> round(4) |> paste0(collapse = ",") |> paste0("&bbox=", x = _)
#> [1] "&bbox=5.9749,50.6628,6.2169,50.8574"

Note: The VG250 dataset itself can be accessed via vg250:

vg250
#> Simple feature collection with 10990 features and 5 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: 5.86625 ymin: 47.27012 xmax: 15.04182 ymax: 55.05878
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>                    GEM          KRS                LAN    EWZ    KFL
#> 1            Flensburg    Flensburg Schleswig-Holstein  92550  56.73
#> 2                 Kiel         Kiel Schleswig-Holstein 247717 118.65
#> 3               Lübeck       Lübeck Schleswig-Holstein 218095 214.19
#> 4           Neumünster   Neumünster Schleswig-Holstein  79502  71.66
#> 5          Brunsbüttel Dithmarschen Schleswig-Holstein  12603  65.21
#> 6                Heide Dithmarschen Schleswig-Holstein  22114  31.97
#> 7              Averlak Dithmarschen Schleswig-Holstein    570   9.06
#> 8             Brickeln Dithmarschen Schleswig-Holstein    198   6.07
#> 9             Buchholz Dithmarschen Schleswig-Holstein   1001  14.56
#> 10 Burg (Dithmarschen) Dithmarschen Schleswig-Holstein   4206  11.25
#>                              geom
#> 1  MULTIPOLYGON (((9.412137 54...
#> 2  MULTIPOLYGON (((10.16852 54...
#> 3  MULTIPOLYGON (((10.87526 53...
#> 4  MULTIPOLYGON (((9.991971 54...
#> 5  MULTIPOLYGON (((9.166074 53...
#> 6  MULTIPOLYGON (((9.121658 54...
#> 7  MULTIPOLYGON (((9.212443 53...
#> 8  MULTIPOLYGON (((9.255627 54...
#> 9  MULTIPOLYGON (((9.182763 53...
#> 10 MULTIPOLYGON (((9.277097 54...

vg250's People

Contributors

dimfalk avatar

Watchers

 avatar

vg250's Issues

`get_*("Bremen" | "Hamburg")`: MULTIPOLYGON objects leading to unreasonable spatial footprint

library(vg250)

get_extent(x = "Hamburg", crs = "epsg:25832")
#> Warning in check_municipality(x): Your input returned multiple objects. Only the object with the largest number of inhabitants is processed.
#>   Consider to visually inspect the returned object using e.g. `mapview::mapview()`.
#> Geometry set for 1 feature 
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 461426.2 ymin: 5916377 xmax: 588169 ymax: 5980375
#> Projected CRS: ETRS89 / UTM zone 32N
#> POLYGON ((461426.2 5916377, 588169 5917039, 586...

dplyr::filter(vg250, GEM == "Hamburg")
#> Simple feature collection with 2 features and 4 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 8.419907 ymin: 53.39507 xmax: 10.32596 ymax: 53.9644
#> Geodetic CRS:  WGS 84
#>       GEM     KRS     LAN     EWZ                           geom
#> 1 Hamburg Hamburg Hamburg 1853935 MULTIPOLYGON (((10.18516 53...
#> 2 Hamburg Hamburg Hamburg       0 MULTIPOLYGON (((9.745421 53...

Created on 2023-06-05 with reprex v2.0.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.