An open API service indexing awesome lists of open source software.

https://github.com/petrbouchal/pragr

Tools for visualising Prague data in R
https://github.com/petrbouchal/pragr

czech-republic gis maps open-data prague prague-geodata r rstats rstats-package

Last synced: 8 months ago
JSON representation

Tools for visualising Prague data in R

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
warning = F,
dev = "ragg_png",
fig.width = 10,
out.width = "100%",
dpi = 300,
fig.asp = .7,
fig.retina = 3,
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# pragr: use Prague geodata in R

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/pragr)](https://CRAN.R-project.org/package=pragr)
[![R-CMD-check](https://github.com/petrbouchal/pragr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/petrbouchal/pragr/actions/workflows/R-CMD-check.yaml)

```{r, results='asis', echo=FALSE}

if(pkgdown:::dev_mode(pkgdown:::read_desc()$get_version(), pkgdown:::read_desc()$get_version()) == "devel") {
meta_dest <- pkgdown:::read_meta(".")$development$destination
meta_base_url <- pkgdown:::read_meta(".")$url
if(is.null(meta_dest)) {
dst <- "dev"
} else {
dst <- meta_dest
}

devurl <- paste0(meta_base_url, "/", dst)

cat(paste0("> Note: this is the documentation for the latest released version (the github release). Documentation for the current development version (reflecting the state of the master branch) is at [", devurl, "](", devurl,")."))
}

```

`pragr` aims to provide tools for visualising data about Prague. Currently, it makes Prague raster geodata accessible for use in R via `ggplot2`.

It also provides a set of utilities and shortcuts to simplify handling data about Prague.

## Installation
You can install the current version of `pragr` from GitHub with:

``` r
remotes::install_github("petrbouchal/pragr")
```

## What it does

Currently, the 📦 enables you to do two things:

1. Add raster tiles from the Prague geoopen data portal to a `ggplot2` object (`prg_tile()`)
2. Add other raster layer to a `ggplot2` object (`prg_basemap()`)

The basic logic of the two core functions is that given a simple feature dataset, they provide the tiles or image to create the base map for those coordinates.

It relies on the REST API of ArcGis map/image services that power the geoportal, using documentation for the following operations (endpoints):

- [Image Tile endpoint](https://developers.arcgis.com/rest/services-reference/image-tile.htm)
- [Export Image endoint](https://developers.arcgis.com/rest/services-reference/export-image.htm)
- [Export Map (image) endpoint](https://developers.arcgis.com/rest/services-reference/export-map.htm)

Additionally, the package provides

- quick access to a number of codes that identify Prague in various administrative or statistical registers.
- a function for downloading official Prague admin geodata (admin boundaries etc.)
- square and hex tiles for equal-area plotting
- a grid object suitable for use in the `geofacet::facet_geo()` function.
- basic demographic data about Prague districts

## Credit, inspiration and extensibility

The approach draws heavily on code provided by @[yutannihilation](https://github.com/yutannihilation) in her [blog post](https://yutani.rbind.io/post/2018-06-09-plot-osm-tiles/) on using OpenStreetMap tiles in 📦 `ggplot2`.

The approach should be generalisable to other ArcGIS-driven servers with the same REST API, though the package as it now is assumes a projected CRS measured in meters, specifically the Krovak CRS (EPSG 5514).

## Usage

```{r setup}
library(pragr)
library(dplyr)
library(sf)
library(ggplot2)
```

```{r load-data}
praha1 <- CzechData::load_RUIAN_settlement(prg_kod, "MOMC_P", WGS84 = F) %>%
filter(nazev == 'Praha 1')
```

Note that the possible values of the `tile_service` and `image_service` parameters can be found in `prg_endpoints`.

```{r example-tiles}
ggplot() +
prg_tile(data = praha1, zoom = 10, alpha = 1, buffer = 200,
tile_service = 'orto') +
geom_sf(data = praha1, colour = alpha("red", 0.6), fill = NA, shape = "dotted") +
theme_void()
```

The `layer` parameter can take values that you can find by inspecting the given image service (see note on sources below).

```{r example-base}
ggplot() +
prg_basemap(data = praha1, alpha = 1, buffer = 200, width = 1000,
image_service = 'cisarske_otisky_1840_velke', layer = 1) +
geom_sf(data = praha1, colour = alpha("red", 0.6), fill = NA, shape = "dotted") +
theme_void()
```

## What's in a name?

The name of the package refers to [Karel Prager](https://en.wikipedia.org/wiki/Karel_Prager), a renowned Czech modernist architect. Among other things, he designed - and for a long time worked in - the office buildings in which the [Institute for Planning and Development](https://iprpraha.cz), Prague's public urban planning body, is housed today.

The institute's excellent data team develops and maintains the data and software infrastructure for Prague's geographical data on which this package - and much of Prague's planning, government and business - relies.

Prag is of course how the city was once called by its many German-speaking inhabitants.

## Data sources:

Most map/image services are accessible via

A more technical route to lists of services is via

- for all tile services, including the in-preparation Metropolitan Plan
- for most tile, image as well as feature servers
- for undocumented services, including the Atlas 5000 map collection which contains data from the 2016 ÚAP (Core Spatial Analytics) report for Prague, in the [`/uap/` collection](https://gs.iprpraha.cz/arcgis/rest/services/uap) The [`/urk/` collection](https://gs.iprpraha.cz/arcgis/rest/services/urk) contains some interesting data (incl. construction limits ([stavební uzávěry](https://gs.iprpraha.cz/arcgis/rest/services/urk/StavebniUzavery/MapServer)) or the spread of the build-up area over time ([vývoj Prahy](https://gs.iprpraha.cz/arcgis/rest/services/urk/vyvoj_prahy/MapServer))).

Many of these services can be used in WMS mode, i.e. as tiles for `leaflet` maps, or as feature layers for webmaps - see the [web article](/articles/web.html) for an example.

There has recently been a migration from the "mpp.*" servers to the "gs[-pub]*" servers; see for the translation. Some services still run on but presumably these will go away at some point. For now, this is the only place where the full current Spatial plan lives ().

For some of the services, shortcut notation is implemented for use in the tile/basemap functions. See `prg_endpoints`. **Not all endpoint metadata in `prg_endoints` has been updated to reflect the new URLs.**

## Note on geodata about Prague

There will be a [vignette](articles/data-sources.html) or `vignette("data-sources", package = "pragr")`.

# See also:

- [CzechData](https://jancaha.github.io/CzechData)
- [RCzechia](https://github.com/jlacko/RCzechia)
- [czso](https://github.com/petrbouchal/czso)
- [GiscoR](https://dieghernan.github.io/giscoR/)

## Acknowledgments

- Most importantly, IPR Praha for providing the open data!
- The approach draws heavily on code provided by @[yutannihilation](https://github.com/yutannihilation) in her [blog post]
- logo designed using the 📦 bunny by @[dmi3kno](https://github.com/dmi3kno) following his [blog post]([https://www.ddrive.no/post/making-hex-and-twittercard-with-bunny-and-magick/])
- font in logo is Trivia Serif by [František Štorm](https://stormtype.com)

## Code of Conduct

Please note that the pragr project is released with a [Contributor Code of Conduct](https://petrbouchal.github.io/pragr/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.