R package for downloading OpenStreetMap data
1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/get-osmdata-df.R
3\name{osmdata_data_frame}
4\alias{osmdata_data_frame}
5\title{Return an OSM Overpass query as a \link{data.frame} object.}
6\usage{
7osmdata_data_frame(q, doc, quiet = TRUE, stringsAsFactors = FALSE)
8}
9\arguments{
10\item{q}{An object of class \code{overpass_query} constructed with
11\link{opq} and \link{add_osm_feature} or a string with a valid query, such
12as \code{"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"}.
13May be be omitted, in which case the attributes of the \link{data.frame}
14will not include the query. See examples below.}
15
16\item{doc}{If missing, \code{doc} is obtained by issuing the overpass query,
17\code{q}, otherwise either the name of a file from which to read data,
18or an object of class \pkg{xml2} returned from \link{osmdata_xml}.}
19
20\item{quiet}{suppress status messages.}
21
22\item{stringsAsFactors}{Should character strings in the 'data.frame' be
23coerced to factors?}
24}
25\value{
26A \code{data.frame} inheriting from \code{osmdata_data.frame} class with id, type
27and tags of the the objects from the query.
28}
29\description{
30Return an OSM Overpass query as a \link{data.frame} object.
31}
32\details{
33If you are not interested in the geometries of the results, it's a
34good option to query for objects that match the features only and forget
35about members of the ways and relations. You can achieve this by passing
36the parameter \code{body = "tags"} to \code{\link{opq}}.
37}
38\examples{
39\dontrun{
40query <- opq ("hampi india") |>
41 add_osm_feature (key = "historic", value = "ruins")
42# Then extract data from 'Overpass' API
43hampi_df <- osmdata_data_frame (query)
44attr (hampi_df, "bbox")
45attr (hampi_df, "overpass_call")
46attr (hampi_df, "meta")
47}
48
49# Complex query as a string (not possible with regular osmdata functions)
50q <- '[out:csv(::type, ::id, "name:ca", "wikidata")][timeout:50];
51 area[name="Països Catalans"][boundary=political]->.boundaryarea;
52
53 rel(area.boundaryarea)[admin_level=8][boundary=administrative];
54 map_to_area -> .all_level_8_areas;
55
56 ( nwr(area.boundaryarea)[amenity=townhall]; >; );
57 is_in;
58 area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall;
59
60 (.all_level_8_areas; - .level_8_areas_with_townhall;);
61 rel(pivot);
62 out tags;'
63
64\dontrun{
65no_townhall <- osmdata_data_frame (q)
66no_townhall
67}
68}
69\seealso{
70Other extract:
71\code{\link{osmdata_sc}()},
72\code{\link{osmdata_sf}()},
73\code{\link{osmdata_sp}()},
74\code{\link{osmdata_xml}()}
75}
76\concept{extract}