12
12
</p >
13
13
<br />
14
14
15
- # Enrich geocoded data using openstreetmaps
15
+ # Enrich geocoded data using OpenStreetMap
16
16
17
17
![ 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 )
18
18
19
-
20
19
The goal of ` osmenrich ` is to easily enrich geocoded data
21
20
(` latitude ` /` longitude ` ) with geographic features from OpenStreetMap (OSM).
22
21
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.
24
25
25
26
## Installation
26
27
@@ -54,84 +55,87 @@ dataset:
54
55
# Import libraries
55
56
library(tidyverse )
56
57
library(sf )
57
- library(osmdata )
58
58
library(osmenrich )
59
59
60
60
# Create an example dataset to enrich
61
61
sf_example <-
62
62
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 ,
66
66
) %> %
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
+ )
68
71
69
72
# Print it
70
73
sf_example
71
- # > Simple feature collection with 2 features and 3 fields
74
+ # > Simple feature collection with 2 features and 1 field
72
75
# > geometry type: POINT
73
76
# > dimension: XY
74
77
# > bbox: xmin: 5.08 ymin: 52.12 xmax: 5.09 ymax: 52.13
75
78
# > 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)
81
84
```
82
85
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
85
88
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
87
90
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.
89
94
90
95
``` r
91
96
# Simple OSMEnrich query
92
- sf_example_simple <- sf_example %> %
97
+ sf_example_enriched <- sf_example %> %
93
98
enrich_osm(
94
- name = " waste_baskets " ,
99
+ name = " n_waste_baskets " ,
95
100
key = " amenity" ,
96
101
value = " waste_basket" ,
97
- r = 100
102
+ r = 500
98
103
)
99
104
# > 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.
104
107
```
105
108
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 ` .
108
111
109
112
``` r
110
113
sf_example_enriched
111
- # > Simple feature collection with 2 features and 4 fields
114
+ # > Simple feature collection with 2 features and 2 fields
112
115
# > geometry type: POINT
113
116
# > dimension: XY
114
117
# > 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
121
124
```
122
125
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 )
123
128
124
129
## Local API setup
125
130
126
131
OSM enrichment can ask for a lot of data, which can overload public APIs. If
127
132
you intend to enrich large amounts of data or compute routing distances (e.g.,
128
133
driving duration) between many points, you should set up a local API endpoint.
129
134
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
131
136
[ osmenrich_docker
132
137
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.
135
139
136
140
<img src =" man/figures/docker.png " width =" 250px " ></img >
137
141
@@ -142,15 +146,14 @@ Contributions are what make the open source community an amazing place to
142
146
learn, inspire, and create. Any contributions you make are ** greatly
143
147
appreciated** .
144
148
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
149
152
project: ` develop ` and ` master ` . The ` master ` branch is used only for the
150
153
official releases of the project, while the ` develop ` branch is used to
151
154
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.
154
157
155
158
The workflow to contribute with Gitflow becomes:
156
159
@@ -176,7 +179,7 @@ Enrich sf Data with Geographic Features from OpenStreetMaps (Version v1.0). Zeno
176
179
This package is developed and maintained by the [ ODISSEI Social Data Science
177
180
(SoDa)] ( https://odissei-data.nl/nl/soda/ ) team.
178
181
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
180
183
tracker or feel free to contact [ Erik-Jan van
181
184
Kesteren] ( https://github.com/vankesteren )
182
185
([ @ejvankesteren ] ( https://twitter.com/ejvankesteren ) ) or [ Leonardo
0 commit comments