-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
114 lines (78 loc) · 5.45 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
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%"
)
```
# osmxml
<!-- badges: start -->
[![DOI](https://zenodo.org/badge/489214893.svg)](https://zenodo.org/badge/latestdoi/489214893)
<!-- badges: end -->
**osmxml** is an R package useful to download, read, prepare and (rudimentarily) visualise OpenStreetMap (OSM) XML files like the `map.osm` file you would get from the [OSM website's "Export" page](https://www.openstreetmap.org/export).
This package might not be what you're after: please see below the section "Other OSM-related R packages" to find more powerful tools.
## Installation
You can install the development version of osmexport from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("stragu/osmxml")
```
## Available functions
* `ox_download()`: download an OSM export by defining its bounding box, save it to file.
* `ox_read()`: read a `.osm` file as an object of class `osm`
* `ox_separate_tags()`: separate the tags contained in the `other_tags` column. This is done by default when importing the data with `ox_read()`
## The `osm` class
The `osm` S3 class – very much subject to changing in name and properties – has `print()` and `plot()` methods. It is made of [`sf`](https://r-spatial.github.io/sf/) ("simple features") spatial objects.
## Example
The functions available are designed to be pipeable. For example, to download and read the area around [Te Kura Tatauranga, Waipapa Taumata Rau](https://www.auckland.ac.nz/en/science/about-the-faculty/department-of-statistics.html):
```{r Te_Kura_Tatauranga}
library(osmxml)
TKT <- c(174.76598, -36.85440, 174.77019, -36.85129) |>
ox_download() |>
ox_read()
# see what the object contains
TKT
```
We can now use the default plot method to have a glimpse at the data:
```{r plot}
plot(TKT)
```
Because the parts of the object are of class `sf`, they can be processed with sf and well as dplyr functions:
```{r process_data, message=FALSE}
library(dplyr)
library(sf)
# most common "building" values in polygons
TKT$multipolygons |>
st_drop_geometry() |> # remove geometry column
filter(!is.na(building)) |> # only keep buildings
count(building, sort = TRUE) # most commons values at the top
```
## Contributions and feedback
Contributions are welcome and appreciated. You can contribute to this package by:
* Testing it and [reporting issues](https://github.com/stragu/osmxml/issues) you encounter
* Suggesting a change with a pull request (but please discuss your idea in an issue beforehand)
* Writing a new vignette with an interesting worked example
Note that all contributions to the codebase will be released under the [GPL](LICENSE.md), and submitting your contribution to this repository is an implicit agreement.
We expect contributors to respect UQRUG's [Code of Conduct](https://gitlab.com/stragu/uqrug/blob/master/Code_of_Conduct.md).
If a conversation or comment does not belong in a public issue report, please contact the maintainer listed in the [package description](DESCRIPTION).
## Data licence
OSM data included in this package (in the `./inst` directory) and downloaded with the `ox_download()` function is © OpenStreetMap contributors, and the conditions of its reuse are defined by the [ODbL licence](https://opendatacommons.org/licenses/odbl/). You likely need to include this information on anything derived from it. Find out more on the [OSM website](https://www.openstreetmap.org/copyright).
## Other OSM-related R packages
There are many other OSM-related R packages that might be more suitable for what you are hoping to achieve. Notable packages available on CRAN are:
* [osmadata](https://cran.r-project.org/web/packages/osmdata) uses the Overpass API to download datasets based on location and tags. Use this for a more targeted download.
* [osmextract](https://cran.r-project.org/web/packages/osmextract) uses different providers to download chunks of large data dumps, for specific regions and dates. Some providers offer data already prepared for particular uses (e.g. data relevant to cycling).
* [osmplotr](https://cran.r-project.org/web/packages/osmplotr) downloads OSM data with the Overpass API and provides many tools to render the data.
* [osmar](https://cran.r-project.org/web/packages/osmar/index.html) accesses OSM data from different sources and converts it to various formats. Note that it hasn't been updated since 2013.
Transport-specific packages:
* [stplanr](https://cran.r-project.org/web/packages/stplanr) provides tools for sustainable transport planning, making use of the osrm package.
* [osrm](https://cran.r-project.org/web/packages/osrm) bridges R with the OSRM API (routing service based on OpenStreetMap data).
* [opentripplanner](https://docs.ropensci.org/opentripplanner/) provides an interface to OpenTripPlanner (OTP), a routing service that relies on OpenStreetMap data.
To acquire basemaps:
* [OpenStreetMap](https://cran.r-project.org/web/packages/OpenStreetMap) allows downloading rendered OSM data from various servers.
* [OSMscale](https://cran.r-project.org/web/packages/osmplotr) plots spatial data with OSM basemaps and corresponding scale bars.
Other interactive visualisation packages automatically fetch rendered OSM data as basemaps, like [leaflet](https://rstudio.github.io/leaflet/) and [tmap](https://r-tmap.github.io/tmap/).