osmextract

Download and import OpenStreetMap data from Geofabrik and other providers

https://github.com/ropensci/osmextract

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (22.2%) to scientific vocabulary

Keywords

geo geofabrik-zone open-data osm osm-pbf r rstats

Keywords from Contributors

osm-data overpass-api
Last synced: 4 months ago · JSON representation

Repository

Download and import OpenStreetMap data from Geofabrik and other providers

Basic Info
Statistics
  • Stars: 177
  • Watchers: 7
  • Forks: 12
  • Open Issues: 31
  • Releases: 11
Topics
geo geofabrik-zone open-data osm osm-pbf r rstats
Created over 6 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Codemeta

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```



# osmextract 



[![R build status](https://github.com/ropensci/osmextract/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/osmextract/actions)
[![Codecov test coverage](https://codecov.io/gh/ropensci/osmextract/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/osmextract?branch=master)
[![peer-review](https://badges.ropensci.org/395_status.svg)](https://github.com/ropensci/software-review/issues/395)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![CRAN status](https://www.r-pkg.org/badges/version/osmextract)](https://CRAN.R-project.org/package=osmextract)


The goal of `osmextract` is to make it easier for people to access OpenStreetMap (OSM) data for reproducible research.
OSM data is the premier source of freely available, community created geographic data worldwide.
We aim to enable you to extract it for data-driven work in the public interest.

`osmextract` matches, downloads, converts, and imports bulk OSM data hosted by providers such as [Geofabrik GmbH](http://download.geofabrik.de) and [bbbike](https://download.bbbike.org/osm/).
For information on alternative providers and how to add them see the [providers vignette](https://docs.ropensci.org/osmextract/articles/providers.html).

## Why osmextract?

The package answers a common question for researchers who use OSM data:
how to get it into a statistical environment, in an appropriate format, as part of a computationally efficient and reproducible workflow?
Other packages answer parts of this question.
[`osmdata`](https://github.com/ropensci/osmdata), for example, is an R package that provides an R interface to the [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API), which is ideal for downloading small OSM datasets.
However, the API is rate limited, making it hard to download large datasets.
As a case study, try to download all cycleways in England using `osmdata`:

```r
library(osmdata)
cycleways_england = opq("England") %>% 
  add_osm_feature(key = "highway", value = "cycleway") %>% 
  osmdata_sf()
# Error in check_for_error(doc) : General overpass server error; returned:
# The data included in this document is from www.openstreetmap.org. The data is made available under ODbL. runtime error: Query timed out in "query" at line 4 after 26 seconds. 
```

The query stops with an error message after around 30 seconds.
The same query can be made with `osmextract` as follows, which reads-in almost 100k linestrings in less than 10 seconds, after the data has been downloaded in the compressed `.pbf` format and converted to the open standard `.gpkg` format. 
The download-and-conversion operation of the OSM extract associated to England takes approximately a few minutes, but this operation must be executed only once. 
The following code chunk is not evaluated.

```{r, eval = FALSE}
library(osmextract)

cycleways_england = oe_get(
  "England",
  quiet = FALSE,
  query = "SELECT * FROM 'lines' WHERE highway = 'cycleway'"
)
par(mar = rep(0.1, 4))
plot(sf::st_geometry(cycleways_england))
```

```{r, echo = FALSE, out.width="80%", fig.align='center'}
knitr::include_graphics("man/figures/89990770-22bf2480-dc83-11ea-9092-764594534959.png")
```

The package is designed to complement `osmdata`, which has advantages over `osmextract` for small datasets: `osmdata` is likely to be quicker for datasets less than a few MB in size, provides up-to-date data and has an intuitive interface. 
`osmdata` can provide data in a range of formats, while `osmextract` only returns [`sf`](https://github.com/r-spatial/sf) objects. 
`osmextract`'s niche is that it provides a fast way to download large OSM datasets in the highly compressed `pbf` format and read them in via the fast C library [GDAL](https://gdal.org/en/stable/drivers/vector/osm.html) and the popular R package for working with geographic data [`sf`](https://github.com/r-spatial/sf).

## Installation

You can install the released version of `osmextract` from [CRAN](https://cran.r-project.org/package=osmextract) with:

``` r
install.packages("osmextract")
```

You can install the development version from [GitHub](https://github.com/ropensci/osmextract) with:

``` r
# install.packages("remotes")
remotes::install_github("ropensci/osmextract")
```

Load the package with:

```{r}
library(osmextract)
```

To use alongside functionality in the `sf` package, we also recommend attaching this geographic data package as follows:

```{r}
library(sf)
```

### Warnings: 

The functions defined in this package may return a warning message like 

```
st_crs<- : replacing crs does not reproject data; use st_transform for that 
```

if the user is running an old version of GDAL (<= 3.0.0) or PROJ (<= 6.0.0). 
See [here](https://github.com/r-spatial/sf/issues/1419) for more details. 
Nevertheless, every function should still work correctly. 
Please, raise [a new issue](https://github.com/ropensci/osmextract/issues) if you find any odd behaviour. 

## Basic usage

Give `osmextract` a place name and it will try to find it in a list of names in the specified provider ([Geofabrik](https://www.geofabrik.de/data/download.html) by default).
If the name you give it matches a place, it will download and import the associated data into R.
The function `oe_get()` downloads (if not already downloaded) and reads-in data from OSM providers as `sf` objects.
By default `oe_get()` imports the `lines` layer, but any layer can be read-in by changing the `layer` argument:

```{r points-lines-iow, fig.show = 'hold', out.width = "50%"}
osm_lines = oe_get("Isle of Wight", stringsAsFactors = FALSE, quiet = TRUE)
osm_points = oe_get("Isle of Wight", layer = "points", stringsAsFactors = FALSE, quiet = TRUE)
nrow(osm_lines)
nrow(osm_points)
par(mar = rep(0, 4))
plot(st_geometry(osm_lines), xlim = c(-1.59, -1.1), ylim = c(50.5, 50.8))
plot(st_geometry(osm_points), xlim = c(-1.59, -1.1), ylim = c(50.5, 50.8))
```

The figures above give an insight into the volume and richness of data contained in OSM extracts.
Even for a small island such as the Isle of Wight, it contains over 50k features including ferry routes, shops and roads.
The column names in the `osm_lines` object are as follows:

```{r}
names(osm_lines) # default variable names
```

Once imported, you can use all functions for data frames in base R and other packages.
You can also use functions from the `sf` package for spatial analysis and visualisation.
Let's plot all the major, secondary and residential roads, for example:

```{r iow1}
ht = c("primary", "secondary", "tertiary", "unclassified") # highway types of interest
osm_major_roads = osm_lines[osm_lines$highway %in% ht, ]
plot(osm_major_roads["highway"], key.pos = 1)
```

The same steps can be used to get other OSM datasets (examples not run):

```{r, eval = FALSE}
malta = oe_get("Malta", quiet = TRUE)
andorra = oe_get("Andorra", extra_tags = "ref")
leeds = oe_get("Leeds")
goa = oe_get("Goa", query = "SELECT highway, geometry FROM 'lines'")
```

If the input place does not match any of the existing names in the supported providers, then `oe_get()` will try to geocode it via [Nominatim API](https://nominatim.org/release-docs/develop/api/Overview/), and it will select the smallest OSM extract intersecting the area. 
For example (not run): 

```{r, eval = FALSE}
oe_get("Milan") # Warning: It will download more than 400MB of data
#> No exact match found for place = Milan and provider = geofabrik. Best match is Iran.
#> Checking the other providers.
#> No exact match found in any OSM provider data. Searching for the location online.
#> ... (extra messages here)
```

For further details on using the package, see the [Introducing osmextract vignette](https://docs.ropensci.org/osmextract/articles/osmextract.html).

## Changing the download directory

The default behaviour of `oe_get()` is to save all files in a package specific directory located at `tools::R_user_dir("osmextract", "data")`. 
If you prefer using any other persistent or temporary directory, you can add `OSMEXT_DOWNLOAD_DIRECTORY=/path/for/osm/data` to your `.Renviron` file, e.g. with:

```{r, eval = FALSE}
usethis::edit_r_environ()
# Add a line containing: OSMEXT_DOWNLOAD_DIRECTORY=/path/where/to/save/files
```

You can always check the default `download_directory` used by this package with: 

```{r, eval = FALSE}
oe_download_directory()
```

The `force_download` argument can be used to refresh OSM extracts already present in the download directory. See also `oe_update()`and the introductory vignette for more details. 

## Next steps

We would love to see more providers added (see the [Add new OpenStreetMap providers](https://docs.ropensci.org/osmextract/articles/providers.html) for details) and see what people can do with OSM datasets of the type provided by this package in a reproducible and open statistical programming environment for the greater good.
Any contributions to support this or any other improvements to the package are very welcome via our issue tracker.

## Licence

We hope this package will provide easy access to OSM data for reproducible research in the public interest, adhering to the condition of the [OdBL licence](https://opendatacommons.org/licenses/odbl/) which states that

> Any Derivative Database that You Publicly Use must be only under the terms of:

- i. This License;
- ii. A later version of this License similar in spirit to this

See the [Introducing osmextract vignette](https://docs.ropensci.org/osmextract/articles/osmextract.html) for more details.

## Other approaches

- [osmdata](https://github.com/ropensci/osmdata) is an R package for importing small datasets directly from OSM servers
- [osmapiR](https://docs.ropensci.org/osmapiR/) is an R interface to the [OpenStreetMap API v0.6](https://wiki.openstreetmap.org/wiki/API_v0.6) for fetching and saving raw from/to the OpenStreetMap database including map data as well as map notes, GPS traces, changelogs, and users data.
- [geofabrik](https://cran.r-project.org/package=geofabrik) is an R package to download OSM data from [Geofabrik](https://download.geofabrik.de/)
- [pyrosm](https://pyrosm.readthedocs.io/en/latest/) is a Python package for reading .pbf files
- [pydriosm](https://pypi.org/project/pydriosm/) is a Python package to download, read and import OSM extracts
- [osmium](https://pypi.org/project/osmium/) provides python bindings for the Libosmium C++ library
- [OpenStreetMapX.jl](https://github.com/pszufe/OpenStreetMapX.jl) is a Julia package for reading and analysing .osm files
- [PostGIS](https://www.bostongis.com/PrinterFriendly.aspx?content_name=loading_osm_postgis) is an established spatial database that works well with large OSM datasets
- Any others? Let us know!

## Contribution

We very much look forward to comments, questions and contributions. 
If you have any question or if you want to suggest a new approach, feel free to create a new discussion in the [github repository](https://github.com/ropensci/osmextract/discussions). 
If you found a bug, or if you want to add a new OSM extracts provider, create a new issue in the [issue tracker](https://github.com/ropensci/osmextract/issues) or a new [pull request](https://github.com/ropensci/osmextract/pulls). 
We always try to build the most intuitive user interface and write the most informative error messages, but if you think that something is not clear and could have been explained better, please let us know. 

## Contributor Code of Conduct
Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). 
By contributing to this project, you agree to abide by its terms.

Owner

  • Name: rOpenSci
  • Login: ropensci
  • Kind: organization
  • Email: info@ropensci.org
  • Location: Berkeley, CA

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "osmextract",
  "description": "Match, download, convert and import Open Street Map data extracts obtained from several providers. ",
  "name": "osmextract: Download and Import Open Street Map Data Extracts",
  "relatedLink": [
    "https://docs.ropensci.org/osmextract/",
    "https://CRAN.R-project.org/package=osmextract"
  ],
  "codeRepository": "https://github.com/ropensci/osmextract",
  "issueTracker": "https://github.com/ropensci/osmextract/issues",
  "license": "https://spdx.org/licenses/GPL-3.0",
  "version": "0.5.3",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.4.2 (2024-10-31 ucrt)",
  "provider": {
    "@id": "https://cran.r-project.org",
    "@type": "Organization",
    "name": "Comprehensive R Archive Network (CRAN)",
    "url": "https://cran.r-project.org"
  },
  "author": [
    {
      "@type": "Person",
      "givenName": "Andrea",
      "familyName": "Gilardi",
      "email": "andrea.gilardi@unimib.it",
      "@id": "https://orcid.org/0000-0002-9424-7439"
    },
    {
      "@type": "Person",
      "givenName": "Robin",
      "familyName": "Lovelace",
      "@id": "https://orcid.org/0000-0001-5679-6536"
    }
  ],
  "contributor": [
    {
      "@type": "Person",
      "givenName": "Barry",
      "familyName": "Rowlingson",
      "@id": "https://orcid.org/0000-0002-8586-6625"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Andrea",
      "familyName": "Gilardi",
      "email": "andrea.gilardi@unimib.it",
      "@id": "https://orcid.org/0000-0002-9424-7439"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "version": ">= 3.0.2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "covr",
      "name": "covr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=covr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "withr",
      "name": "withr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=withr"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 3.6.0"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "sf",
      "name": "sf",
      "version": ">= 0.8.1",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=sf"
    },
    "3": {
      "@type": "SoftwareApplication",
      "identifier": "utils",
      "name": "utils"
    },
    "4": {
      "@type": "SoftwareApplication",
      "identifier": "tools",
      "name": "tools"
    },
    "5": {
      "@type": "SoftwareApplication",
      "identifier": "httr",
      "name": "httr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=httr"
    },
    "6": {
      "@type": "SoftwareApplication",
      "identifier": "jsonlite",
      "name": "jsonlite",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=jsonlite"
    },
    "SystemRequirements": null
  },
  "fileSize": "3770.484KB",
  "releaseNotes": "https://github.com/ropensci/osmextract/blob/master/NEWS.md",
  "readme": "https://github.com/ropensci/osmextract/blob/master/README.md",
  "contIntegration": [
    "https://github.com/ropensci/osmextract/actions",
    "https://app.codecov.io/gh/ropensci/osmextract?branch=master"
  ],
  "developmentStatus": "https://www.repostatus.org/#active",
  "review": {
    "@type": "Review",
    "url": "https://github.com/ropensci/software-review/issues/395",
    "provider": "https://ropensci.org"
  },
  "keywords": [
    "osm",
    "osm-pbf",
    "rstats",
    "r",
    "open-data",
    "geofabrik-zone",
    "geo"
  ]
}

GitHub Events

Total
  • Create event: 7
  • Release event: 1
  • Issues event: 20
  • Watch event: 7
  • Delete event: 5
  • Issue comment event: 46
  • Push event: 83
  • Pull request review event: 8
  • Pull request review comment event: 6
  • Pull request event: 12
  • Fork event: 1
Last Year
  • Create event: 7
  • Release event: 1
  • Issues event: 20
  • Watch event: 7
  • Delete event: 5
  • Issue comment event: 46
  • Push event: 83
  • Pull request review event: 8
  • Pull request review comment event: 6
  • Pull request event: 12
  • Fork event: 1

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 882
  • Total Committers: 7
  • Avg Commits per committer: 126.0
  • Development Distribution Score (DDS): 0.433
Past Year
  • Commits: 67
  • Committers: 3
  • Avg Commits per committer: 22.333
  • Development Distribution Score (DDS): 0.045
Top Committers
Name Email Commits
Andrea Gilardi a****i@u****t 500
Andrea Gilardi a****5@c****t 253
Robin Lovelace r****x@g****m 123
Juan P. Fonseca-Zamora 6****1 2
Dustin Carlino d****r@g****m 2
Joan Maspons j****s@g****m 1
Greta 8****e 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 83
  • Total pull requests: 42
  • Average time to close issues: 5 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 18
  • Total pull request authors: 4
  • Average comments per issue: 3.12
  • Average comments per pull request: 2.5
  • Merged pull requests: 32
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 9
  • Pull requests: 8
  • Average time to close issues: 2 months
  • Average time to close pull requests: 22 days
  • Issue authors: 4
  • Pull request authors: 2
  • Average comments per issue: 2.11
  • Average comments per pull request: 4.75
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • agila5 (51)
  • Robinlovelace (12)
  • juanfonsecaLS1 (2)
  • StephanLo (2)
  • rsbivand (2)
  • andreas-ullrich (2)
  • luukvdmeer (1)
  • eugene100hickey (1)
  • wlangera (1)
  • edzer (1)
  • eugenividal (1)
  • simonrolph (1)
  • adithirgis (1)
  • cormundo (1)
  • mtennekes (1)
Pull Request Authors
  • agila5 (39)
  • Robinlovelace (6)
  • juanfonsecaLS1 (2)
  • GretaTimaite (1)
  • jmaspons (1)
Top Labels
Issue Labels
enhancement (5) wontfix (1) help wanted (1) discussion (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 1,084 last-month
  • Total docker downloads: 8
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 17
    (may contain duplicates)
  • Total versions: 20
  • Total maintainers: 1
proxy.golang.org: github.com/ropensci/osmextract
  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 5 months ago
cran.r-project.org: osmextract

Download and Import Open Street Map Data Extracts

  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 17
  • Downloads: 1,084 Last month
  • Docker Downloads: 8
Rankings
Stargazers count: 2.6%
Forks count: 6.8%
Dependent repos count: 6.9%
Average: 14.6%
Downloads: 16.7%
Docker downloads count: 25.7%
Dependent packages count: 28.7%
Maintainers (1)
Last synced: 5 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • actions/upload-artifact main composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action 4.1.4 composite
  • actions/checkout v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 3.5.0 depends
  • httr * imports
  • jsonlite * imports
  • sf >= 0.8.1 imports
  • tools * imports
  • utils * imports
  • covr * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.2 suggests
  • withr * suggests