diff --git a/DESCRIPTION b/DESCRIPTION index 9edf86eb..e505f8c1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,11 @@ Authors@R: c(person(given = "Krzysztof", comment = c(ORCID = "0000-0002-8281-4301")), person("GUGiK", role = "ctb", - comment = "source of the data")) + comment = "source of the data"), + person(given = "Grzegorz", + family = "Sapijaszko", + role = "ctb", + email = "grzegorz@sapijaszko.net")) Description: Automatic open data acquisition from resources of Polish Head Office of Geodesy and Cartography ('Główny Urząd Geodezji i Kartografii') (). diff --git a/NAMESPACE b/NAMESPACE index e7e89862..d85171a2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(DEM_request) export(borders_download) export(borders_get) +export(egib_download) export(emuia_download) export(geocodePL_get) export(geodb_download) diff --git a/NEWS.md b/NEWS.md index b13891b6..1044bccc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,8 @@ in `ortho_request()` and `DEM_request()`. * Updated data sources in `borders_download()` function. +* added `egib_download()` function for downloading Land and Building Register layers. + # rgugik 0.4.1 * The list of communes has been updated (as of 02 January 2024). diff --git a/R/egib_download.R b/R/egib_download.R new file mode 100644 index 00000000..f17e9e3a --- /dev/null +++ b/R/egib_download.R @@ -0,0 +1,143 @@ +#' @title Download Land and Building Register (EGiB) layers +#' +#' @param county County name in Polish. Check [`county_names()`] function. +#' @param TERYT County ID (4 characters). +#' @param layer Requested layer, `parcels` default. Other common layer is `buildings` (budynki). +#' You can check available layers by [`egib_layers()`] data set. +#' @param outdir name of the output directory where the data has to be stored, +#' current directory by default. If you don't want to download data, pass a `NULL` value. +#' @param ... any other parameter passed to [`sf::read_sf()`] function +#' +#' @return Simple feature data frame of objects for requested layer. +#' +#' @export +#' +#' @examples +#' \dontrun{ +#' parcels <- egib_download(county = "Świętochłowice", layer = "parcels", outdir = NULL) # 3.9 MB +#' egib_download(TERYT = c("2476", "2264"), layer = "buildings", outdir = ".") # 2.2 + 2.6 MB +#' } +#' +#' @references +#' The EGiB data (Ewidencja Gruntów i Budynków) consist of 2 primary layers: +#' cadastral data (parcels, "dzialki" in Polish) and buildings footprints (budynki). +#' The data is maintained on county level, which results in 380 units/different +#' sources of data. It may contain additional layers like points of detailed +#' horizontal and vertical geodetic control network (osnowa_pozioma +#' and osnowa_pionowa respectively). +#' +#' \url{https://www.geoportal.gov.pl/en/data/land-and-building-register-egib/} +#' \url{https://www.geoportal.gov.pl/en/data/detailed-control-network-database-bdsog/} + +egib_download <- function(county = NULL, TERYT = NULL, layer = "parcels", outdir = ".", ...) { + + layer_names = rgugik::egib_layers + + if (is.null(county) && is.null(TERYT)) { + stop("'county' and 'TERYT' are empty") + } + + if (!is.null(county) && !is.null(TERYT)) { + stop("use only one input") + } + + if (!all(county %in% layer_names$NAME)) { + stop("incorrect county name") + } + + if (!is.null(TERYT) && any(nchar(TERYT) != 4)) { + stop("incorrect TERYT") + } + + if (length(layer) > 1L) { + stop("please provide only one layer at time") + } + + switch(layer, + parcels = { + layer <- "dzialki" }, + buildings = { + layer <- "budynki" }, + { + layer <- layer + } + ) + + if (!is.null(county)) { + sel_vector <- layer_names[, "NAME"] %in% county + layer_names <- layer_names[sel_vector, ] + layer_names <- layer_names[match(county, layer_names$NAME),] + + if(any(duplicated(layer_names$NAME))) { + dup <- which(duplicated(layer_names$NAME)) + + message("There are counties with the same name, both will be downloaded.") + message("If you would like to avoid it, please provide TERYT instead.") + + layer_names[layer_names$NAME == layer_names[dup, "NAME"], 1:2] + } + + } else { + sel_vector <- layer_names[, "TERYT"] %in% TERYT + layer_names = layer_names[sel_vector, ] + layer_names <- layer_names[match(TERYT, layer_names$TERYT),] + + } + + if(nrow(layer_names > 1L) & is.null(outdir)) { + message("There is more than one county provided, however you didn't specified the output directory.") + message("Only the first will be taken.") + layer_names <- layer_names[1, ] + } + + for (k in seq_len(nrow(layer_names))) { + print(k) + + TERYT <- layer_names[k, "TERYT"] + county_name <- layer_names[k, "NAME"] + + layers <- layer_names[k, "LAYERS"] |> + strsplit(split = ", ") |> + as.list() + layers <- layers[[1]] + + egib_url <- layer_names[k, "URL"] + + if (all(is.na(layers))) { + a <- "" + if(!is.na(egib_url)) { + a <- paste("You might try to check", egib_url, "using st_layers() directly.") + } + stop(paste0("there is no layers available for time being\n", a)) + } + + if(!any(grepl(layer, layers))) { + stop(paste("Can't find", layer, "in", paste0(unlist(layers), collapse = ", "))) + } + + if(any(grepl(layer, layers))) { + layer <- layers[which(grepl(layer, layers))] + if(length(layer) > 1L) { + stop(paste0("There is more than 1 layer simillar to requested: ", + paste0(unlist(layer), collapse = ", "), ". Please specify.")) + } + egib_url <- paste0("WFS:", egib_url) + + message(paste("Downloading layer", layer, "for", county_name, "county. TERYT:", TERYT)) + + output <- tryGet(sf::read_sf(dsn = egib_url, layer = layer, + options = "CONSIDER_EPSG_AS_URN=YES", ...)) + + if (any(output %in% c("error", "warning"))) { + return(invisible("connection error")) + } + + if(!is.null(outdir)) { + outfile <- paste0(outdir, "/", TERYT, ".gpkg") + message(paste("Writing the data to", outfile)) + sf::write_sf(output, dsn = outfile, layer = layer, append = FALSE) + } + } + } + return(output) +} diff --git a/R/egib_layers.R b/R/egib_layers.R new file mode 100644 index 00000000..e2512f26 --- /dev/null +++ b/R/egib_layers.R @@ -0,0 +1,14 @@ +#' @name egib_layers +#' @title Available urls and layers of Land and building register (EGiB) +#' +#' @description The data frame contains the names of counties, +#' their identifiers (TERYT, 4 characters), URL ofthe EGiB data (WFS) +#' and the names of available layers. +#' +#' @importFrom utils data +#' +#' @docType data +#' @keywords dataset EGiB +#' @examples +#' egib_layers +"egib_layers" diff --git a/README.Rmd b/README.Rmd index 01cf5bc4..887451e7 100644 --- a/README.Rmd +++ b/README.Rmd @@ -31,6 +31,7 @@ knitr::opts_chunk$set( - [Register of Towns, Streets and Addresses](https://emuia.gugik.gov.pl) - [State Register of Geographical Names](https://www.geoportal.gov.pl/pl/dane/panstwowy-rejestr-nazw-geograficznych-prng/) - [State Register of Borders](https://www.geoportal.gov.pl/pl/dane/panstwowy-rejestr-granic-prg/) + - [Land and Building Registers](https://integracja.gugik.gov.pl/eziudp/index.php?zbior=egib) - Location (geometry) of cadastral parcels using TERYT (parcel ID) or coordinates - 3D models of buildings (LOD1, LOD2) - Various digital elevation models as: @@ -47,6 +48,7 @@ ds_pl = c("Ortofotomapa", "Baza Danych Obiektów Ogólnogeograficznych", "Baza Danych Obiektów Topograficznych", "Ewidencja Miejscowości, Ulic i Adresów", + "Ewidencja Gruntów i Budynków", "Państwowy Rejestr Nazw Geograficznych", "Państwowy Rejestr Granic", "Lokalizacja działek katastralnych", @@ -57,6 +59,7 @@ ds_en = c("Orthophotomap", "General Geographic Database", "Topographic Database", "Register of Towns, Streets and Addresses", + "Land and Building Register", "State Register of Geographical Names", "State Register of Borders", "Location of cadastral parcels", @@ -67,6 +70,7 @@ fun = c("`ortho_request()`, `tile_download()`", "`geodb_download()`", "`topodb_download()`", "`emuia_download()`", + "`egib_download()`", "`geonames_download()`", "`borders_get()`, `borders_download()`", "`parcel_get()`", @@ -77,6 +81,7 @@ input = c("geometry", "voivodeship", "county", "commune", + "county", "type", "type", "parcel ID, coordinates", diff --git a/README.md b/README.md index e13cbc94..39a8a810 100644 --- a/README.md +++ b/README.md @@ -1,200 +1,203 @@ - - - -# rgugik - - - -[![CRAN](https://www.r-pkg.org/badges/version/rgugik)](https://cran.r-project.org/package=rgugik) -[![R build -status](https://github.com/kadyb/rgugik/workflows/rcmdcheck/badge.svg)](https://github.com/kadyb/rgugik/actions) -[![codecov](https://codecov.io/gh/kadyb/rgugik/branch/master/graph/badge.svg)](https://app.codecov.io/gh/kadyb/rgugik) -[![License: -MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit) -[![DOI](https://joss.theoj.org/papers/10.21105/joss.02948/status.svg)](https://doi.org/10.21105/joss.02948) - - -**rgugik** is an R package for downloading open data from resources of -[Polish Head Office of Geodesy and -Cartography](https://www.gov.pl/web/gugik) including: - -- [Orthophotomaps](https://www.geoportal.gov.pl/pl/dane/ortofotomapa-orto/) -- [General Geographic - Database](https://www.geoportal.gov.pl/pl/dane/baza-danych-obiektow-ogolnogeograficznych-bdoo/) -- [Topographic - Database](https://www.geoportal.gov.pl/pl/dane/baza-danych-obiektow-topograficznych-bdot10k/) -- [Register of Towns, Streets and Addresses](https://emuia.gugik.gov.pl) -- [State Register of Geographical - Names](https://www.geoportal.gov.pl/pl/dane/panstwowy-rejestr-nazw-geograficznych-prng/) -- [State Register of - Borders](https://www.geoportal.gov.pl/pl/dane/panstwowy-rejestr-granic-prg/) -- Location (geometry) of cadastral parcels using TERYT (parcel ID) or - coordinates -- 3D models of buildings (LOD1, LOD2) -- Various digital elevation models as: - - [Digital terrain - model](https://www.geoportal.gov.pl/pl/dane/numeryczny-model-terenu-nmt/) - - [Digital surface - model](https://www.geoportal.gov.pl/pl/dane/numeryczny-model-pokrycia-terenu-nmpt/) - - [Point - cloud](https://www.geoportal.gov.pl/pl/dane/dane-pomiarowe-lidar-lidar/) - -It is also possible to geocode addresses or objects using the -`geocodePL_get()` function. - -**Corresponding functions** - -| Function | Input | Dastaset EN | Dataset PL | -|:---|:---|:---|:---| -| `ortho_request()`, `tile_download()` | geometry | Orthophotomap | Ortofotomapa | -| `geodb_download()` | voivodeship | General Geographic Database | Baza Danych Obiektów Ogólnogeograficznych | -| `topodb_download()` | county | Topographic Database | Baza Danych Obiektów Topograficznych | -| `emuia_download()` | commune | Register of Towns, Streets and Addresses | Ewidencja Miejscowości, Ulic i Adresów | -| `geonames_download()` | type | State Register of Geographical Names | Państwowy Rejestr Nazw Geograficznych | -| `borders_get()`, `borders_download()` | type | State Register of Borders | Państwowy Rejestr Granic | -| `parcel_get()` | parcel ID, coordinates | Location of cadastral parcels | Lokalizacja działek katastralnych | -| `models3D_download()` | county | 3D models of buildings | Modele 3D budynków | -| `DEM_request()`, `tile_download()` | geometry | Digital elevation models | Cyfrowe modele wysokościowe | - -There are the additional functions for obtaining digital terrain model: - -- `pointDTM_get()` for small areas (high resolution grid) -- `pointDTM100_download()` for voivodeships areas (low resolution grid) -- `minmaxDTM_get()` to find the minimum and maximum elevation (small - areas) - -The names of administrative units and their IDs are included in these -objects: - -- `voivodeship_names` (16) -- `county_names` (380) -- `commune_names` (2476) - -## Installation - -You can install the released version from -[CRAN](https://cran.r-project.org/) with: - -``` r -install.packages("rgugik") -``` - -You can install the development version from -[GitHub](https://github.com) with: - -``` r -# install.packages("remotes") -remotes::install_github("kadyb/rgugik") -``` - -## Usage - -### Orthophotomap - -- `ortho_request()` - returns a data frame with metadata and links to - the orthoimages for a given geometry (point, line or polygon) -- `tile_download()` - downloads orthoimages based on the data frame - obtained using the `ortho_request()` function - -``` r -library(rgugik) -library(sf) -library(stars) - -polygon_path = system.file("datasets/search_area.gpkg", package = "rgugik") -polygon = read_sf(polygon_path) - -req_df = ortho_request(polygon) - -# select the oldest image -req_df = req_df[req_df$year == 2001, ] - -# print metadata -t(req_df) -#> 27 -#> sheetID "N-33-130-D-b-2-3" -#> year "2001" -#> resolution "1" -#> composition "RGB" -#> sensor "Satellite" -#> CRS "PL-1992" -#> date "2001-01-01" -#> isFilled "TRUE" -#> URL "https://opendata.geoportal.gov.pl/ortofotomapa/41/41_3756_N-33-130-D-b-2-3.tif" -#> filename "41_3756_N-33-130-D-b-2-3" -#> seriesID "41" - -# download image -tile_download(req_df) -#> 1/1 - -img = read_stars("41_3756_N-33-130-D-b-2-3.tif") -plot(st_rgb(img), main = NULL) -``` - - - -### Administrative boundaries - -``` r -library(rgugik) -library(sf) - -# get counties from opolskie voivodeship (TERYT 16) -counties = county_names -counties = counties[substr(counties$TERYT, 1, 2) == "16", "TERYT"] -counties_geom = borders_get(TERYT = counties) -plot(st_geometry(counties_geom), main = "Opolskie") -``` - - - -### Vignettes - -More advanced examples of the practical (step by step) use of this -package can be found in the vignettes: - -- [Orthophotomap](https://kadyb.github.io/rgugik/articles/orthophotomap.html) -- [Digital elevation - model](https://kadyb.github.io/rgugik/articles/DEM.html) -- [Topographic - Database](https://kadyb.github.io/rgugik/articles/topodb.html) - -## Acknowledgment - -[Head Office of Geodesy and Cartography in -Poland](https://www.gov.pl/web/gugik) is the main source of the provided -data. The data is made available in accordance with the [Act of May 17, -1989 Geodetic and Cartographic -Law](http://isap.sejm.gov.pl/isap.nsf/DocDetails.xsp?id=WDU19890300163) -(amended on 16 April 2020). - -All datasets can be explored interactively using the -[Geoportal](https://mapy.geoportal.gov.pl). - -## Contribution - -Contributions to this package are welcome. The preferred method of -contribution is through a GitHub pull request. Feel also free to contact -us by creating [an issue](https://github.com/kadyb/rgugik/issues). More -detailed information can be found in the -[CONTRIBUTING](https://github.com/kadyb/rgugik/blob/master/CONTRIBUTING.md) -document. - -Maintainers and contributors must follow this repository’s [CODE OF -CONDUCT](https://github.com/kadyb/rgugik/blob/master/CODE_OF_CONDUCT.md). - -## Citation - -To cite **rgugik** in publications, please use the following -[article](https://doi.org/10.21105/joss.02948): - - Dyba, K. and Nowosad, J. (2021). rgugik: Search and Retrieve Spatial Data from the Polish Head Office of Geodesy and Cartography in R. Journal of Open Source Software, 6(59), 2948, https://doi.org/10.21105/joss.02948 - -BibTeX version can be obtained with `citation("rgugik")`. - -## Related projects - -If you don’t feel familiar with R, there is a similar -[QGIS](https://www.qgis.org/) tool in the -[EnviroSolutions](https://github.com/envirosolutionspl) repository. + + + +# rgugik + + + +[![CRAN](https://www.r-pkg.org/badges/version/rgugik)](https://cran.r-project.org/package=rgugik) +[![R build +status](https://github.com/kadyb/rgugik/workflows/rcmdcheck/badge.svg)](https://github.com/kadyb/rgugik/actions) +[![codecov](https://codecov.io/gh/kadyb/rgugik/branch/master/graph/badge.svg)](https://app.codecov.io/gh/kadyb/rgugik) +[![License: +MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit) +[![DOI](https://joss.theoj.org/papers/10.21105/joss.02948/status.svg)](https://doi.org/10.21105/joss.02948) + + +**rgugik** is an R package for downloading open data from resources of +[Polish Head Office of Geodesy and +Cartography](https://www.gov.pl/web/gugik) including: + +- [Orthophotomaps](https://www.geoportal.gov.pl/pl/dane/ortofotomapa-orto/) +- [General Geographic + Database](https://www.geoportal.gov.pl/pl/dane/baza-danych-obiektow-ogolnogeograficznych-bdoo/) +- [Topographic + Database](https://www.geoportal.gov.pl/pl/dane/baza-danych-obiektow-topograficznych-bdot10k/) +- [Register of Towns, Streets and Addresses](https://emuia.gugik.gov.pl) +- [State Register of Geographical + Names](https://www.geoportal.gov.pl/pl/dane/panstwowy-rejestr-nazw-geograficznych-prng/) +- [State Register of + Borders](https://www.geoportal.gov.pl/pl/dane/panstwowy-rejestr-granic-prg/) +- [Land and Building + Registers](https://integracja.gugik.gov.pl/eziudp/index.php?zbior=egib) +- Location (geometry) of cadastral parcels using TERYT (parcel ID) or + coordinates +- 3D models of buildings (LOD1, LOD2) +- Various digital elevation models as: + - [Digital terrain + model](https://www.geoportal.gov.pl/pl/dane/numeryczny-model-terenu-nmt/) + - [Digital surface + model](https://www.geoportal.gov.pl/pl/dane/numeryczny-model-pokrycia-terenu-nmpt/) + - [Point + cloud](https://www.geoportal.gov.pl/pl/dane/dane-pomiarowe-lidar-lidar/) + +It is also possible to geocode addresses or objects using the +`geocodePL_get()` function. + +**Corresponding functions** + +| Function | Input | Dastaset EN | Dataset PL | +|:---|:---|:---|:---| +| `ortho_request()`, `tile_download()` | geometry | Orthophotomap | Ortofotomapa | +| `geodb_download()` | voivodeship | General Geographic Database | Baza Danych Obiektów Ogólnogeograficznych | +| `topodb_download()` | county | Topographic Database | Baza Danych Obiektów Topograficznych | +| `emuia_download()` | commune | Register of Towns, Streets and Addresses | Ewidencja Miejscowości, Ulic i Adresów | +| `egib_download()` | county | Land and Building Register | Ewidencja Gruntów i Budynków | +| `geonames_download()` | type | State Register of Geographical Names | Państwowy Rejestr Nazw Geograficznych | +| `borders_get()`, `borders_download()` | type | State Register of Borders | Państwowy Rejestr Granic | +| `parcel_get()` | parcel ID, coordinates | Location of cadastral parcels | Lokalizacja działek katastralnych | +| `models3D_download()` | county | 3D models of buildings | Modele 3D budynków | +| `DEM_request()`, `tile_download()` | geometry | Digital elevation models | Cyfrowe modele wysokościowe | + +There are the additional functions for obtaining digital terrain model: + +- `pointDTM_get()` for small areas (high resolution grid) +- `pointDTM100_download()` for voivodeships areas (low resolution grid) +- `minmaxDTM_get()` to find the minimum and maximum elevation (small + areas) + +The names of administrative units and their IDs are included in these +objects: + +- `voivodeship_names` (16) +- `county_names` (380) +- `commune_names` (2476) + +## Installation + +You can install the released version from +[CRAN](https://cran.r-project.org/) with: + +``` r +install.packages("rgugik") +``` + +You can install the development version from +[GitHub](https://github.com) with: + +``` r +# install.packages("remotes") +remotes::install_github("kadyb/rgugik") +``` + +## Usage + +### Orthophotomap + +- `ortho_request()` - returns a data frame with metadata and links to + the orthoimages for a given geometry (point, line or polygon) +- `tile_download()` - downloads orthoimages based on the data frame + obtained using the `ortho_request()` function + +``` r +library(rgugik) +library(sf) +library(stars) + +polygon_path = system.file("datasets/search_area.gpkg", package = "rgugik") +polygon = read_sf(polygon_path) + +req_df = ortho_request(polygon) + +# select the oldest image +req_df = req_df[req_df$year == 2001, ] + +# print metadata +t(req_df) +#> 27 +#> sheetID "N-33-130-D-b-2-3" +#> year "2001" +#> resolution "1" +#> composition "RGB" +#> sensor "Satellite" +#> CRS "PL-1992" +#> date "2001-01-01" +#> isFilled "TRUE" +#> URL "https://opendata.geoportal.gov.pl/ortofotomapa/41/41_3756_N-33-130-D-b-2-3.tif" +#> filename "41_3756_N-33-130-D-b-2-3" +#> seriesID "41" + +# download image +tile_download(req_df) +#> 1/1 + +img = read_stars("41_3756_N-33-130-D-b-2-3.tif") +plot(st_rgb(img), main = NULL) +``` + + + +### Administrative boundaries + +``` r +library(rgugik) +library(sf) + +# get counties from opolskie voivodeship (TERYT 16) +counties = county_names +counties = counties[substr(counties$TERYT, 1, 2) == "16", "TERYT"] +counties_geom = borders_get(TERYT = counties) +plot(st_geometry(counties_geom), main = "Opolskie") +``` + + + +### Vignettes + +More advanced examples of the practical (step by step) use of this +package can be found in the vignettes: + +- [Orthophotomap](https://kadyb.github.io/rgugik/articles/orthophotomap.html) +- [Digital elevation + model](https://kadyb.github.io/rgugik/articles/DEM.html) +- [Topographic + Database](https://kadyb.github.io/rgugik/articles/topodb.html) + +## Acknowledgment + +[Head Office of Geodesy and Cartography in +Poland](https://www.gov.pl/web/gugik) is the main source of the provided +data. The data is made available in accordance with the [Act of May 17, +1989 Geodetic and Cartographic +Law](http://isap.sejm.gov.pl/isap.nsf/DocDetails.xsp?id=WDU19890300163) +(amended on 16 April 2020). + +All datasets can be explored interactively using the +[Geoportal](https://mapy.geoportal.gov.pl). + +## Contribution + +Contributions to this package are welcome. The preferred method of +contribution is through a GitHub pull request. Feel also free to contact +us by creating [an issue](https://github.com/kadyb/rgugik/issues). More +detailed information can be found in the +[CONTRIBUTING](https://github.com/kadyb/rgugik/blob/master/CONTRIBUTING.md) +document. + +Maintainers and contributors must follow this repository’s [CODE OF +CONDUCT](https://github.com/kadyb/rgugik/blob/master/CODE_OF_CONDUCT.md). + +## Citation + +To cite **rgugik** in publications, please use the following +[article](https://doi.org/10.21105/joss.02948): + + Dyba, K. and Nowosad, J. (2021). rgugik: Search and Retrieve Spatial Data from the Polish Head Office of Geodesy and Cartography in R. Journal of Open Source Software, 6(59), 2948, https://doi.org/10.21105/joss.02948 + +BibTeX version can be obtained with `citation("rgugik")`. + +## Related projects + +If you don’t feel familiar with R, there is a similar +[QGIS](https://www.qgis.org/) tool in the +[EnviroSolutions](https://github.com/envirosolutionspl) repository. diff --git a/data/egib_layers.rda b/data/egib_layers.rda new file mode 100644 index 00000000..d6417149 Binary files /dev/null and b/data/egib_layers.rda differ diff --git a/man/egib_download.Rd b/man/egib_download.Rd new file mode 100644 index 00000000..b2d36678 --- /dev/null +++ b/man/egib_download.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/egib_download.R +\name{egib_download} +\alias{egib_download} +\title{Download Land and Building Register (EGiB) layers} +\usage{ +egib_download( + county = NULL, + TERYT = NULL, + layer = "parcels", + outdir = ".", + ... +) +} +\arguments{ +\item{county}{County name in Polish. Check \code{\link[=county_names]{county_names()}} function.} + +\item{TERYT}{County ID (4 characters).} + +\item{layer}{Requested layer, \code{parcels} default. Other common layer is \code{buildings} (budynki). +You can check available layers by \code{\link[=egib_layers]{egib_layers()}} data set.} + +\item{outdir}{name of the output directory where the data has to be stored, +current directory by default. If you don't want to download data, pass a \code{NULL} value.} + +\item{...}{any other parameter passed to \code{\link[sf:st_read]{sf::read_sf()}} function} +} +\value{ +Simple feature data frame of objects for requested layer. +} +\description{ +Download Land and Building Register (EGiB) layers +} +\examples{ +\dontrun{ +parcels <- egib_download(county = "Świętochłowice", layer = "parcels", outdir = NULL) # 3.9 MB +egib_download(TERYT = c("2476", "2264"), layer = "buildings", outdir = ".") # 2.2 + 2.6 MB +} + +} +\references{ +The EGiB data (Ewidencja Gruntów i Budynków) consist of 2 primary layers: +cadastral data (parcels, "dzialki" in Polish) and buildings footprints (budynki). +The data is maintained on county level, which results in 380 units/different +sources of data. It may contain additional layers like points of detailed +horizontal and vertical geodetic control network (osnowa_pozioma +and osnowa_pionowa respectively). + +\url{https://www.geoportal.gov.pl/en/data/land-and-building-register-egib/} +\url{https://www.geoportal.gov.pl/en/data/detailed-control-network-database-bdsog/} +} diff --git a/man/egib_layers.Rd b/man/egib_layers.Rd new file mode 100644 index 00000000..7d6b2183 --- /dev/null +++ b/man/egib_layers.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/egib_layers.R +\docType{data} +\name{egib_layers} +\alias{egib_layers} +\title{Available urls and layers of Land and building register (EGiB)} +\format{ +An object of class \code{data.frame} with 380 rows and 4 columns. +} +\usage{ +egib_layers +} +\description{ +The data frame contains the names of counties, +their identifiers (TERYT, 4 characters), URL ofthe EGiB data (WFS) +and the names of available layers. +} +\examples{ +egib_layers +} +\keyword{EGiB} +\keyword{dataset} diff --git a/man/figures/README-f1-1.png b/man/figures/README-f1-1.png index 338b1d54..ff1e6e35 100644 Binary files a/man/figures/README-f1-1.png and b/man/figures/README-f1-1.png differ diff --git a/man/figures/README-f2-1.png b/man/figures/README-f2-1.png index 33367e5f..f60b58a1 100644 Binary files a/man/figures/README-f2-1.png and b/man/figures/README-f2-1.png differ diff --git a/man/rgugik-package.Rd b/man/rgugik-package.Rd index 69e553e1..08df5cdf 100644 --- a/man/rgugik-package.Rd +++ b/man/rgugik-package.Rd @@ -31,6 +31,7 @@ Other contributors: \itemize{ \item Maciej Beręsewicz \email{maciej.beresewicz@ue.poznan.pl} (\href{https://orcid.org/0000-0002-8281-4301}{ORCID}) [contributor] \item GUGiK (source of the data) [contributor] + \item Grzegorz Sapijaszko \email{grzegorz@sapijaszko.net} [contributor] } } diff --git a/tests/testthat/test-egib_download.R b/tests/testthat/test-egib_download.R new file mode 100644 index 00000000..789c336f --- /dev/null +++ b/tests/testthat/test-egib_download.R @@ -0,0 +1,17 @@ +skip_on_cran() + +tmp = tempdir() +status = egib_download(county = "Świętochłowice", layer = "dzialki", outdir = tmp) + +# status should be sf data frame +expect_s3_class(status, c("sf", "data.frame")) + +# test stops +test_that("check stops", { + expect_error(egib_download(), "'county' and 'TERYT' are empty") + expect_error(egib_download("Świętochłowice", "2476"), "use only one input") + expect_error(egib_download(county = "XXX"), "incorrect county name") + expect_error(egib_download(TERYT = "0"), "incorrect TERYT") + expect_error(egib_download("Łomża"), "there is no layers available") + expect_error(egib_download(TERYT = "0220", layer = "Osnowa"), "There is more than 1 layer") +})