{"id":13857262,"url":"https://github.com/ropensci/osmextract","last_synced_at":"2025-05-16T09:04:24.817Z","repository":{"id":40244845,"uuid":"208763634","full_name":"ropensci/osmextract","owner":"ropensci","description":"Download and import OpenStreetMap data from Geofabrik and other providers","archived":false,"fork":false,"pushed_at":"2025-04-09T16:49:19.000Z","size":36804,"stargazers_count":174,"open_issues_count":35,"forks_count":12,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-12T20:18:52.286Z","etag":null,"topics":["geo","geofabrik-zone","open-data","osm","osm-pbf","r","rstats"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/osmextract","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null}},"created_at":"2019-09-16T09:40:42.000Z","updated_at":"2025-04-12T00:43:00.000Z","dependencies_parsed_at":"2023-02-19T11:31:42.542Z","dependency_job_id":"51c82edc-6ab5-4f26-9e37-ebfe36f3ba7e","html_url":"https://github.com/ropensci/osmextract","commit_stats":{"total_commits":792,"total_committers":6,"mean_commits":132.0,"dds":"0.49368686868686873","last_synced_commit":"20742aa0296c6a5c1c9e15bf587fc9a6e657b82e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmextract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmextract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmextract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fosmextract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/osmextract/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501557,"owners_count":22081528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geo","geofabrik-zone","open-data","osm","osm-pbf","r","rstats"],"created_at":"2024-08-05T03:01:31.885Z","updated_at":"2025-05-16T09:04:24.786Z","avatar_url":"https://github.com/ropensci.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n# osmextract \u003ca href='https://docs.ropensci.org/osmextract/'\u003e\u003cimg src='man/figures/logo.svg' align=\"right\" height=275/\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![R build status](https://github.com/ropensci/osmextract/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/osmextract/actions)\n[![Codecov test coverage](https://codecov.io/gh/ropensci/osmextract/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/osmextract?branch=master)\n[![peer-review](https://badges.ropensci.org/395_status.svg)](https://github.com/ropensci/software-review/issues/395)\n[![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)\n[![CRAN status](https://www.r-pkg.org/badges/version/osmextract)](https://CRAN.R-project.org/package=osmextract)\n\u003c!-- badges: end --\u003e\n\nThe goal of `osmextract` is to make it easier for people to access OpenStreetMap (OSM) data for reproducible research.\nOSM data is the premier source of freely available, community created geographic data worldwide.\nWe aim to enable you to extract it for data-driven work in the public interest.\n\n`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/).\nFor information on alternative providers and how to add them see the [providers vignette](https://docs.ropensci.org/osmextract/articles/providers.html).\n\n## Why osmextract?\n\nThe package answers a common question for researchers who use OSM data:\nhow to get it into a statistical environment, in an appropriate format, as part of a computationally efficient and reproducible workflow?\nOther packages answer parts of this question.\n[`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.\nHowever, the API is rate limited, making it hard to download large datasets.\nAs a case study, try to download all cycleways in England using `osmdata`:\n\n```r\nlibrary(osmdata)\ncycleways_england = opq(\"England\") %\u003e% \n  add_osm_feature(key = \"highway\", value = \"cycleway\") %\u003e% \n  osmdata_sf()\n# Error in check_for_error(doc) : General overpass server error; returned:\n# 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. \n```\n\nThe query stops with an error message after around 30 seconds.\nThe 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. \nThe download-and-conversion operation of the OSM extract associated to England takes approximately a few minutes, but this operation must be executed only once. \nThe following code chunk is not evaluated.\n\n```{r, eval = FALSE}\nlibrary(osmextract)\n\ncycleways_england = oe_get(\n  \"England\",\n  quiet = FALSE,\n  query = \"SELECT * FROM 'lines' WHERE highway = 'cycleway'\"\n)\npar(mar = rep(0.1, 4))\nplot(sf::st_geometry(cycleways_england))\n```\n\n```{r, echo = FALSE, out.width=\"80%\", fig.align='center'}\nknitr::include_graphics(\"man/figures/89990770-22bf2480-dc83-11ea-9092-764594534959.png\")\n```\n\nThe 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. \n`osmdata` can provide data in a range of formats, while `osmextract` only returns [`sf`](https://github.com/r-spatial/sf) objects. \n`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).\n\n## Installation\n\nYou can install the released version of `osmextract` from [CRAN](https://cran.r-project.org/package=osmextract) with:\n\n``` r\ninstall.packages(\"osmextract\")\n```\n\nYou can install the development version from [GitHub](https://github.com/ropensci/osmextract) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"ropensci/osmextract\")\n```\n\nLoad the package with:\n\n```{r}\nlibrary(osmextract)\n```\n\nTo use alongside functionality in the `sf` package, we also recommend attaching this geographic data package as follows:\n\n```{r}\nlibrary(sf)\n```\n\n### Warnings: \n\nThe functions defined in this package may return a warning message like \n\n```\nst_crs\u003c- : replacing crs does not reproject data; use st_transform for that \n```\n\nif the user is running an old version of GDAL (\u003c= 3.0.0) or PROJ (\u003c= 6.0.0). \nSee [here](https://github.com/r-spatial/sf/issues/1419) for more details. \nNevertheless, every function should still work correctly. \nPlease, raise [a new issue](https://github.com/ropensci/osmextract/issues) if you find any odd behaviour. \n\n## Basic usage\n\nGive `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).\nIf the name you give it matches a place, it will download and import the associated data into R.\nThe function `oe_get()` downloads (if not already downloaded) and reads-in data from OSM providers as `sf` objects.\nBy default `oe_get()` imports the `lines` layer, but any layer can be read-in by changing the `layer` argument:\n\n```{r points-lines-iow, fig.show = 'hold', out.width = \"50%\"}\nosm_lines = oe_get(\"Isle of Wight\", stringsAsFactors = FALSE, quiet = TRUE)\nosm_points = oe_get(\"Isle of Wight\", layer = \"points\", stringsAsFactors = FALSE, quiet = TRUE)\nnrow(osm_lines)\nnrow(osm_points)\npar(mar = rep(0, 4))\nplot(st_geometry(osm_lines), xlim = c(-1.59, -1.1), ylim = c(50.5, 50.8))\nplot(st_geometry(osm_points), xlim = c(-1.59, -1.1), ylim = c(50.5, 50.8))\n```\n\nThe figures above give an insight into the volume and richness of data contained in OSM extracts.\nEven for a small island such as the Isle of Wight, it contains over 50k features including ferry routes, shops and roads.\nThe column names in the `osm_lines` object are as follows:\n\n```{r}\nnames(osm_lines) # default variable names\n```\n\nOnce imported, you can use all functions for data frames in base R and other packages.\nYou can also use functions from the `sf` package for spatial analysis and visualisation.\nLet's plot all the major, secondary and residential roads, for example:\n\n```{r iow1}\nht = c(\"primary\", \"secondary\", \"tertiary\", \"unclassified\") # highway types of interest\nosm_major_roads = osm_lines[osm_lines$highway %in% ht, ]\nplot(osm_major_roads[\"highway\"], key.pos = 1)\n```\n\nThe same steps can be used to get other OSM datasets (examples not run):\n\n```{r, eval = FALSE}\nmalta = oe_get(\"Malta\", quiet = TRUE)\nandorra = oe_get(\"Andorra\", extra_tags = \"ref\")\nleeds = oe_get(\"Leeds\")\ngoa = oe_get(\"Goa\", query = \"SELECT highway, geometry FROM 'lines'\")\n```\n\nIf 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. \nFor example (not run): \n\n```{r, eval = FALSE}\noe_get(\"Milan\") # Warning: It will download more than 400MB of data\n#\u003e No exact match found for place = Milan and provider = geofabrik. Best match is Iran.\n#\u003e Checking the other providers.\n#\u003e No exact match found in any OSM provider data. Searching for the location online.\n#\u003e ... (extra messages here)\n```\n\nFor further details on using the package, see the [Introducing osmextract vignette](https://docs.ropensci.org/osmextract/articles/osmextract.html).\n\n## Persistent download directory\n\nThe default behaviour of `oe_get()` is to save all the files in a temporary directory, which is erased every time you restart your R session. \nIf you want to set a directory that will persist, you can add `OSMEXT_DOWNLOAD_DIRECTORY=/path/for/osm/data` in your `.Renviron` file, e.g. with:\n\n```{r, eval = FALSE}\nusethis::edit_r_environ()\n# Add a line containing: OSMEXT_DOWNLOAD_DIRECTORY=/path/to/save/files\n```\n\nWe strongly advise you setting a persistent directory since working with `.pbf` files is an expensive operation, that is skipped by `oe_*()` functions if they detect that the input `.pbf` file was already downloaded.\n\nYou can always check the default `download_directory` used by `oe_get()` with: \n\n```{r, eval = FALSE}\noe_download_directory()\n```\n\n\u003c!-- The following section was removed since now oe_download sets the timeout value. See https://github.com/ropensci/osmextract/issues/222 --\u003e\n\n\u003c!-- ## Troubleshooting --\u003e\n\n\u003c!-- Depending on the `.pbf` file selected and your connection speed, you may experience an error stating `Timeout of 60 seconds was reached`.  --\u003e\n\u003c!-- If so, before calling `oe_get()`, you can adjust the timeout using `options(timeout = 300)`, choosing an appropriate value.  --\u003e\n\u003c!-- This setting affects all calls to [download.file()](https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/download.file), so you may need to reset it for the rest of your script. --\u003e\n\n\u003c!-- If you need to update an existing `.pbf` file or replace an incomplete extract, you can use the argument `force_download`, i.e `oe_get(\"some-place\", force_download = TRUE)`.    --\u003e\n\u003c!-- Check `?oe_get` and `?oe_download` for more details.  --\u003e\n\n## Next steps\n\nWe 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.\nAny contributions to support this or any other improvements to the package are very welcome via our issue tracker.\n\n## Licence\n\nWe 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\n\n\u003e Any Derivative Database that You Publicly Use must be only under the terms of:\n\n- i. This License;\n- ii. A later version of this License similar in spirit to this\n\nSee the [Introducing osmextract vignette](https://docs.ropensci.org/osmextract/articles/osmextract.html) for more details.\n\n## Other approaches\n\n\u003c!-- todo: add links to other packages --\u003e\n- [osmdata](https://github.com/ropensci/osmdata) is an R package for importing small datasets directly from OSM servers\n- [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.\n- [geofabrik](https://cran.r-project.org/package=geofabrik) is an R package to download OSM data from [Geofabrik](https://download.geofabrik.de/)\n- [pyrosm](https://pyrosm.readthedocs.io/en/latest/) is a Python package for reading .pbf files\n- [pydriosm](https://pypi.org/project/pydriosm/) is a Python package to download, read and import OSM extracts\n- [osmium](https://pypi.org/project/osmium/) provides python bindings for the Libosmium C++ library\n- [OpenStreetMapX.jl](https://github.com/pszufe/OpenStreetMapX.jl) is a Julia package for reading and analysing .osm files\n- [PostGIS](https://www.bostongis.com/PrinterFriendly.aspx?content_name=loading_osm_postgis) is an established spatial database that works well with large OSM datasets\n- Any others? Let us know!\n\n## Contribution\n\nWe very much look forward to comments, questions and contributions. \nIf 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). \nIf 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). \nWe 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. \n\n## Contributor Code of Conduct\nPlease note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). \nBy contributing to this project, you agree to abide by its terms.\n\n\u003c!-- :) --\u003e\n\u003c!-- :) --\u003e\n\u003c!-- :) --\u003e\n\u003c!-- :) --\u003e\n\u003c!-- :) --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fosmextract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Fosmextract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fosmextract/lists"}