Skip to content

Commit ed8cd78

Browse files
vankesterenJ535D165leonardovida
authored
Documentation update of osmenrich (#18)
* Add hyperlink to Map Features on the OSM website (#5) * Add links to sf and osmdata * Remove comment statement * Fix undefined variable in example (#7) * Remove words like 'our' and 'we' (#12) * Remove irrelevant information to avoid confusion (#8) * Replace dontrun by donttest (#13) * Clarify title enrich_osm (#14) * Move details of enrich_opq to enrich_osm (#10) * Correct README text (#16) * 📝 Text changes * 📝 Update using review * Update readme, add wastebasket figure Co-authored-by: Jonathan de Bruin <jonathandebruinos@gmail.com> Co-authored-by: Leonardo Vida <lleonardovida@gmail.com>
1 parent 3d92db2 commit ed8cd78

File tree

5 files changed

+85
-79
lines changed

5 files changed

+85
-79
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# From: https://github.com/github/gitignore/blob/master/R.gitignore
22

3+
# R osm cache
4+
rosm.cache/
5+
36
# History files
47
.Rhistory
58
.Rapp.history

R/enrich.R

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#' @name enrich
2-
#' @title Enrich OSM Data
2+
#' @title Enrich `sf` object with OSM data
33
#' @description Perform enriched query on osm and add as new column.
44
#'
55
#' The enrichment call works in the following way: an `enriched_overpass_query`
@@ -18,10 +18,42 @@
1818
#' @param ... `enriched_overpass_query` column or columns to add
1919
#' @param .verbose `bool` whether to print info during enrichment
2020
#'
21+
#' @details
22+
#' `Type` represents the feature type to be considered. Usually this would be
23+
#' points, but polygons and multipolygons are also possible. This argument can
24+
#' also be a vector of multiple types. Non-point types will be converted to
25+
#' points using the st_centroid function from the sf package (NB this does not
26+
#' necessarily work well for all features!) Available options are:
27+
#' - points
28+
#' - lines
29+
#' - polygons
30+
#' - multilines
31+
#' - multipolygons
32+
#'
33+
#' `Distance` represents the metric used to compute the distances between the
34+
#' rows in the dataset and the osm features. `Duration` represents the metric
35+
#' that indicates the average duration to cover the distances between the
36+
#' rows in the dataset and the osm features. The following metrics are
37+
#' available in this package, assuming that the OSRM server is setup as
38+
#' suggested in our guide at:
39+
#' https://github.com/sodascience/osmenrich_docker:
40+
#' - spherical ("as the crow flies")
41+
#' - distance_by_foot
42+
#' - duration_by_foot
43+
#' - distance_by_car
44+
#' - duration_by_car
45+
#' - distance_by_bike
46+
#' - duration_by_bike
47+
#'
48+
#' `Kernel` is a kernel function from the osmenrich package to be used in weighing
49+
#' the features and the radius/distance where features are considered. For
50+
#' simply counting the number of occurrences within a radius, use kernel_uniform
51+
#' with radius r.
52+
#'
2153
#' @examples
22-
#' \dontrun{
54+
#' \donttest{
2355
#'
24-
#' #' # Enrich data creating new column `waste_baskets`
56+
#' # Enrich data creating new column `waste_baskets`
2557
#' sf_enriched <- dataset %>%
2658
#' enrich_osm(
2759
#' name = "waste_baskets",

R/opqenrich.R

-32
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,6 @@
1212
#' @param .verbose `bool` whether to print info during enrichment
1313
#' @param ... arguments passed to the kernel function
1414
#'
15-
#' @details
16-
#' `Type` represents the feature type to be considered. Usually this would be
17-
#' points, but polygons and multipolygons are also possible. This argument can
18-
#' also be a vector of multiple types. Non-point types will be converted to
19-
#' points using the st_centroid function from the sf package (NB this does not
20-
#' necessarily work well for all features!) Available options are:
21-
#' - points
22-
#' - lines
23-
#' - polygons
24-
#' - multilines
25-
#' - multipolygons
26-
#'
27-
#' `Distance` represents the metric used to compute the distances between the
28-
#' rows in the dataset and the osm features. `Duration` represents the metric
29-
#' that indicates the average duration to cover the distances between the
30-
#' rows in the dataset and the osm features. The following metrics are
31-
#' available in this package, assuming that the OSRM server is setup as
32-
#' suggested in our guide at:
33-
#' https://github.com/sodascience/osmenrich_docker:
34-
#' - spherical ("as the crow flies")
35-
#' - distance_by_foot
36-
#' - duration_by_foot
37-
#' - distance_by_car
38-
#' - duration_by_car
39-
#' - distance_by_bike
40-
#' - duration_by_bike
41-
#'
42-
#' `Kernel` is a kernel function from the osmenrich package to be used in weighing
43-
#' the features and the radius/distance where features are considered. For
44-
#' simply counting the number of occurrences within a radius, use kernel_uniform
45-
#' with radius r.
46-
#'
4715
#' @importFrom methods is
4816
#' @rdname enrich_opq
4917
#'

README.md

+47-44
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
</p>
1313
<br/>
1414

15-
# Enrich geocoded data using openstreetmaps
15+
# Enrich geocoded data using OpenStreetMap
1616

1717
![Github Action test](https://github.com/sodascience/osmenrich/workflows/R-CMD-check/badge.svg) [![DOI](https://zenodo.org/badge/337555188.svg)](https://zenodo.org/badge/latestdoi/337555188)
1818

19-
2019
The goal of `osmenrich` is to easily enrich geocoded data
2120
(`latitude`/`longitude`) with geographic features from OpenStreetMap (OSM).
2221
The main language of the package is `R` and this package is designed to work
23-
with the `sf` and `osmdata` packages for collecting and manipulating geodata.
22+
with the [`sf`](https://r-spatial.github.io/sf/) and [`osmdata`](
23+
https://cran.r-project.org/web/packages/osmdata/vignettes/osmdata.html)
24+
packages for collecting and manipulating geodata.
2425

2526
## Installation
2627

@@ -54,84 +55,87 @@ dataset:
5455
# Import libraries
5556
library(tidyverse)
5657
library(sf)
57-
library(osmdata)
5858
library(osmenrich)
5959

6060
# Create an example dataset to enrich
6161
sf_example <-
6262
tribble(
63-
~person, ~id, ~lat, ~lon, ~val,
64-
"Alice", 1, 52.12, 5.09, 5L,
65-
"Bob", 2, 52.13, 5.08, 2L
63+
~person, ~lat, ~lon,
64+
"Alice", 52.12, 5.09,
65+
"Bob", 52.13, 5.08,
6666
) %>%
67-
sf::st_as_sf(coords = c("lon", "lat"), crs = 4326)
67+
sf::st_as_sf(
68+
coords = c("lon", "lat"),
69+
crs = 4326
70+
)
6871

6972
# Print it
7073
sf_example
71-
#> Simple feature collection with 2 features and 3 fields
74+
#> Simple feature collection with 2 features and 1 field
7275
#> geometry type: POINT
7376
#> dimension: XY
7477
#> bbox: xmin: 5.08 ymin: 52.12 xmax: 5.09 ymax: 52.13
7578
#> CRS: EPSG:4326
76-
#> # A tibble: 2 x 4
77-
#> person id val geometry
78-
#> * <chr> <dbl> <int> <POINT [°]>
79-
#> 1 Alice 1 5 (5.09 52.12)
80-
#> 2 Bob 2 2 (5.08 52.13)
79+
#> # A tibble: 2 x 2
80+
#> person geometry
81+
#> * <chr> <POINT [°]>
82+
#> 1 Alice (5.09 52.12)
83+
#> 2 Bob (5.08 52.13)
8184
```
8285

83-
To enrich the `sf_example` dataset with "waste baskets" in a 100m radius, we
84-
create a query using the `enrich_osm()` function. This function uses the
86+
To enrich the `sf_example` dataset with "waste baskets" in a 100m radius, you
87+
can create a query using the `enrich_osm()` function. This function uses the
8588
bounding box created by the points present in the example dataset and searches
86-
for the specified `key = "amenity"` and `value = "waste_basket`. We also add a
89+
for the specified `key = "amenity"` and `value = "waste_basket`. You can also add a
8790
custom `name` for the newly created column and specify the radius (`r`) used
88-
in the search.
91+
in the search. See
92+
[Map Features on the website of OSM](https://wiki.openstreetmap.org/wiki/Map_features)
93+
for a complete list of `key` and `value` combinations.
8994

9095
```r
9196
# Simple OSMEnrich query
92-
sf_example_simple <- sf_example %>%
97+
sf_example_enriched <- sf_example %>%
9398
enrich_osm(
94-
name = "waste_baskets",
99+
name = "n_waste_baskets",
95100
key = "amenity",
96101
value = "waste_basket",
97-
r = 100
102+
r = 500
98103
)
99104
#> Downloading data for waste_baskets... Done.
100-
#> Downloaded 26 points, 0 lines, 0 polygons, 0 mlines, 0 mpolygons.
101-
#> Computing distance matrix for wastebaskets...Done.
102-
#> Adding waste_baskets to data.
103-
105+
#> Downloaded 147 points, 0 lines, 0 polygons, 0 mlines, 0 mpolygons.
106+
#> Computing distance matrix for waste_baskets...Done.
104107
```
105108

106-
The resulting enriched dataset is a `sf` object and can be printed as usual
107-
and we can inspect the newly added column `waste_baskets`.
109+
The resulting enriched dataset `sf_example_enriched` is a `sf` object and can be printed as usual
110+
to inspect the newly added column `n_waste_baskets`.
108111

109112
```r
110113
sf_example_enriched
111-
#> Simple feature collection with 2 features and 4 fields
114+
#> Simple feature collection with 2 features and 2 fields
112115
#> geometry type: POINT
113116
#> dimension: XY
114117
#> bbox: xmin: 5.08 ymin: 52.12 xmax: 5.09 ymax: 52.13
115-
#> CRS: EPSG:4326
116-
#> A tibble: 2 x 5
117-
#> person id val geometry waste_baskets
118-
#> * <chr> <dbl> <int> <POINT [°]> <int>
119-
#> 1 Alice 1 5 (5.09 52.12) 3
120-
#> 2 Bob 2 2 (5.08 52.13) 0
118+
#> geographic CRS: WGS 84
119+
#> # A tibble: 2 x 3
120+
#> person geometry waste_baskets
121+
#> * <chr> <POINT [°]> <int>
122+
#> 1 Alice (5.09 52.12) 75
123+
#> 2 Bob (5.08 52.13) 1
121124
```
122125

126+
The waste baskets column is now the result of summing all the wastebaskets in a 500 meter radius for Alice and Bob:
127+
![](man/figures/example_wastebaskets_r500.png)
123128

124129
## Local API setup
125130

126131
OSM enrichment can ask for a lot of data, which can overload public APIs. If
127132
you intend to enrich large amounts of data or compute routing distances (e.g.,
128133
driving duration) between many points, you should set up a local API endpoint.
129134

130-
We provide a `docker-compose` workflow for this in the separate
135+
Multiple `docker-compose` workflows for doing this are avaialble in the separate
131136
[osmenrich_docker
132137
repository](https://github.com/sodascience/osmenrich_docker). Use the `README`
133-
on the repository for setup instructions.
134-
138+
in the repository to select the workflow that fits your desired outcome.
135139

136140
<img src="man/figures/docker.png" width="250px"></img>
137141

@@ -142,15 +146,14 @@ Contributions are what make the open source community an amazing place to
142146
learn, inspire, and create. Any contributions you make are **greatly
143147
appreciated**.
144148

145-
In this project we use the
146-
[Gitflow workflow](https://nvie.com/posts/a-successful-git-branching-model/)
147-
to help us with continious development. Instead of having a single
148-
`master`/`main` branch we use two branches to record the history of the
149+
In this project, the [Gitflow workflow](https://nvie.com/posts/a-successful-
150+
git-branching-model/) is used. Instead of having a single `master`/`main`
151+
branch, the project makes use of two branches to record the history of the
149152
project: `develop` and `master`. The `master` branch is used only for the
150153
official releases of the project, while the `develop` branch is used to
151154
integrate the new features developed. Finally, `feature` branches are used to
152-
develop new features or additions to the project that will be `rebased and
153-
squash` in the `develop` branch.
155+
develop new features or additions to the project that will be `rebased and squashed`
156+
in the `develop` branch.
154157

155158
The workflow to contribute with Gitflow becomes:
156159

@@ -176,7 +179,7 @@ Enrich sf Data with Geographic Features from OpenStreetMaps (Version v1.0). Zeno
176179
This package is developed and maintained by the [ODISSEI Social Data Science
177180
(SoDa)](https://odissei-data.nl/nl/soda/) team.
178181

179-
Do you have questions, suggestions, or remarks? File an issue in our issue
182+
Do you have questions, suggestions, or remarks? File an issue in the issue
180183
tracker or feel free to contact [Erik-Jan van
181184
Kesteren](https://github.com/vankesteren)
182185
([@ejvankesteren](https://twitter.com/ejvankesteren)) or [Leonardo
4.91 MB
Loading

0 commit comments

Comments
 (0)