Title: | An 'ohsome API' Client |
---|---|
Description: | A client that grants access to the power of the 'ohsome API' from R. It lets you analyze the rich data source of the 'OpenStreetMap (OSM)' history. You can retrieve the geometry of 'OSM' data at specific points in time, and you can get aggregated statistics on the evolution of 'OSM' elements and specify your own temporal, spatial and/or thematic filters. |
Authors: | Heidelberg Institute for Geoinformation Technology (HeiGIT) gGmbH [cph], Oliver Fritz [aut, cre] |
Maintainer: | Oliver Fritz <[email protected]> |
License: | LGPL (>= 3) |
Version: | 0.2.2.9000 |
Built: | 2024-11-18 06:11:23 UTC |
Source: | https://github.com/giscience/ohsome-r |
Creates an ohsome_query
object for OSM element aggregation
ohsome_aggregate_elements( boundary = NULL, aggregation = c("count", "length", "perimeter", "area"), return_value = c("absolute", "density", "ratio"), grouping = NULL, time = NULL, ... ) ohsome_elements_count(boundary = NULL, ...) ohsome_elements_length(boundary = NULL, ...) ohsome_elements_perimeter(boundary = NULL, ...) ohsome_elements_area(boundary = NULL, ...)
ohsome_aggregate_elements( boundary = NULL, aggregation = c("count", "length", "perimeter", "area"), return_value = c("absolute", "density", "ratio"), grouping = NULL, time = NULL, ... ) ohsome_elements_count(boundary = NULL, ...) ohsome_elements_length(boundary = NULL, ...) ohsome_elements_perimeter(boundary = NULL, ...) ohsome_elements_area(boundary = NULL, ...)
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
aggregation |
character; aggregation type:
|
return_value |
character; the value to be returned by the ohsome API:
|
grouping |
character; group type(s) for grouped aggregations (only available for queries to aggregation endpoints). The following group types are available:
Not all of these group types are accepted by all of the aggregation endpoints. Check Grouping for available group types. |
time |
character; |
... |
Parameters of the request to the ohsome API endpoint. |
ohsome_aggregate_elements()
creates an ohsome_query
object for
OSM element aggregation. ohsome_elements_count()
,
ohsome_elements_length()
, ohsome_elements_perimeter()
and
ohsome_elements_area()
are wrapper functions for specific aggregation
endpoints. Boundary objects are passed via set_boundary()
into
ohsome_boundary()
.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
ohsome API Endpoints - Elements Aggregation
# Count of breweries in Franconia ohsome_aggregate_elements( mapview::franconia, aggregation = "count", filter = "craft=brewery", time = "2022-01-01" ) ohsome_elements_count( mapview::franconia, filter = "craft=brewery", time = "2022-01-01" ) # Monthly counts of breweries in Franconia from 2012 to 2022 ohsome_elements_count( mapview::franconia, filter = "craft=brewery", time = "2012/2022/P1M" ) # Count of breweries per district of Franconia ohsome_elements_count( mapview::franconia, filter = "craft=brewery", grouping = "boundary", time = "2022-01-01" ) # Number of breweries per square kilometer ohsome_elements_count( mapview::franconia, filter = "craft=brewery", return_value = "density", time = "2022-01-01" ) # Proportion of breweries that are microbreweries ohsome_elements_count( mapview::franconia, filter = "craft=brewery", filter2 = "craft=brewery and microbrewery=yes", return_value = "ratio", time = "2022-01-01" ) # Total length of highway elements in Franconia ohsome_elements_length( mapview::franconia, filter = "highway=* and geometry:line", time = "2022-01-01" )
# Count of breweries in Franconia ohsome_aggregate_elements( mapview::franconia, aggregation = "count", filter = "craft=brewery", time = "2022-01-01" ) ohsome_elements_count( mapview::franconia, filter = "craft=brewery", time = "2022-01-01" ) # Monthly counts of breweries in Franconia from 2012 to 2022 ohsome_elements_count( mapview::franconia, filter = "craft=brewery", time = "2012/2022/P1M" ) # Count of breweries per district of Franconia ohsome_elements_count( mapview::franconia, filter = "craft=brewery", grouping = "boundary", time = "2022-01-01" ) # Number of breweries per square kilometer ohsome_elements_count( mapview::franconia, filter = "craft=brewery", return_value = "density", time = "2022-01-01" ) # Proportion of breweries that are microbreweries ohsome_elements_count( mapview::franconia, filter = "craft=brewery", filter2 = "craft=brewery and microbrewery=yes", return_value = "ratio", time = "2022-01-01" ) # Total length of highway elements in Franconia ohsome_elements_length( mapview::franconia, filter = "highway=* and geometry:line", time = "2022-01-01" )
The base URL of the ohsome API with path to current major version.
A list:
base
: character; base URL
version
: character; path to current major API version
ohsome_boundary
objectCreates an ohsome_boundary
object from various classes of input geometries.
The ohsome_boundary
object is used to set the bpolys
, bboxes
or
bcircles
parameter of an ohsome_query
object.
ohsome_boundary(boundary, ...) ## S3 method for class 'ohsome_boundary' ohsome_boundary(boundary, ...) ## S3 method for class 'character' ohsome_boundary(boundary, ...) ## S3 method for class 'sf' ohsome_boundary(boundary, digits = 6, ...) ## S3 method for class 'sfc' ohsome_boundary(boundary, ...) ## S3 method for class 'sfg' ohsome_boundary(boundary, ...) ## S3 method for class 'bbox' ohsome_boundary(boundary, ...) ## S3 method for class 'matrix' ohsome_boundary(boundary, ...) ## S3 method for class 'list' ohsome_boundary(boundary, ...)
ohsome_boundary(boundary, ...) ## S3 method for class 'ohsome_boundary' ohsome_boundary(boundary, ...) ## S3 method for class 'character' ohsome_boundary(boundary, ...) ## S3 method for class 'sf' ohsome_boundary(boundary, digits = 6, ...) ## S3 method for class 'sfc' ohsome_boundary(boundary, ...) ## S3 method for class 'sfg' ohsome_boundary(boundary, ...) ## S3 method for class 'bbox' ohsome_boundary(boundary, ...) ## S3 method for class 'matrix' ohsome_boundary(boundary, ...) ## S3 method for class 'list' ohsome_boundary(boundary, ...)
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
... |
Additional arguments other than |
digits |
integer; number of decimal places of coordinates in the
resulting GeoJSON when converting |
An ohsome_boundary
object which contains the following elements:
boundary
: the boundary in textual format
type
of the boundary (bpolys
, bcircles
, or bboxes
).
# Defintion of a bounding circle (lon,lat,radius in meters) ohsome_boundary("8.6528,49.3683,1000") # Definition of two named bounding circles ohsome_boundary("Circle 1:8.6528,49.3683,1000|Circle 2:8.7294,49.4376,1000") # Definition of two named bounding circles with a character vector ohsome_boundary(c("Circle 1:8.6528,49.3683,1000", "Circle 2:8.7294,49.4376,1000")) # Use franconia from the mapview package as bounding polygons ohsome_boundary(mapview::franconia, digits = 4) # Use the bounding box of franconia ohsome_boundary(sf::st_bbox(mapview::franconia)) # Get bounding box of the city of Berlin from OSM ## Not run: ohsome_boundary(osmdata::getbb("Berlin")) ## End(Not run) # Use a list of two bounding boxes ## Not run: ohsome_boundary(list(osmdata::getbb("Berlin"), sf::st_bbox(mapview::franconia))) ## End(Not run)
# Defintion of a bounding circle (lon,lat,radius in meters) ohsome_boundary("8.6528,49.3683,1000") # Definition of two named bounding circles ohsome_boundary("Circle 1:8.6528,49.3683,1000|Circle 2:8.7294,49.4376,1000") # Definition of two named bounding circles with a character vector ohsome_boundary(c("Circle 1:8.6528,49.3683,1000", "Circle 2:8.7294,49.4376,1000")) # Use franconia from the mapview package as bounding polygons ohsome_boundary(mapview::franconia, digits = 4) # Use the bounding box of franconia ohsome_boundary(sf::st_bbox(mapview::franconia)) # Get bounding box of the city of Berlin from OSM ## Not run: ohsome_boundary(osmdata::getbb("Berlin")) ## End(Not run) # Use a list of two bounding boxes ## Not run: ohsome_boundary(list(osmdata::getbb("Berlin"), sf::st_bbox(mapview::franconia))) ## End(Not run)
Creates an ohsome_query
object for OSM contributions count
ohsome_contributions_count( boundary = NULL, latest = FALSE, return_value = c("absolute", "density"), time = NULL, ... )
ohsome_contributions_count( boundary = NULL, latest = FALSE, return_value = c("absolute", "density"), time = NULL, ... )
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
latest |
logical; if |
return_value |
character; the value to be returned by the ohsome API:
|
time |
character; |
... |
Parameters of the request to the ohsome API endpoint. |
ohsome_contributions_count()
creates an ohsome_query
object for
OSM element aggregation. Boundary objects are passed via set_boundary()
into ohsome_boundary()
.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
ohsome API Endpoints - Contributions Aggregation
# Monthly counts of contributions to man-made objects around "Null Island" ohsome_contributions_count("0,0,10", filter = "man_made=*", time = "2010/2020/P1Y") # Monthly counts of latest contributions to man-made objects around "Null Island" ohsome_contributions_count( "0,0,10", latest = TRUE, filter = "man_made=*", time = "2010/2020/P1Y" )
# Monthly counts of contributions to man-made objects around "Null Island" ohsome_contributions_count("0,0,10", filter = "man_made=*", time = "2010/2020/P1Y") # Monthly counts of latest contributions to man-made objects around "Null Island" ohsome_contributions_count( "0,0,10", latest = TRUE, filter = "man_made=*", time = "2010/2020/P1Y" )
Available ohsome API endpoints with their parameters
A list of ohsome API endpoints.
Creates an ohsome_query
object for OSM contribution extraction
ohsome_extract_contributions( boundary = NULL, geometryType = c("centroid", "bbox", "geometry"), latest = FALSE, time = NULL, properties = NULL, clipGeometry = TRUE, ... ) ohsome_contributions_bbox(boundary = NULL, ...) ohsome_contributions_centroid(boundary = NULL, ...) ohsome_contributions_geometry(boundary = NULL, ...)
ohsome_extract_contributions( boundary = NULL, geometryType = c("centroid", "bbox", "geometry"), latest = FALSE, time = NULL, properties = NULL, clipGeometry = TRUE, ... ) ohsome_contributions_bbox(boundary = NULL, ...) ohsome_contributions_centroid(boundary = NULL, ...) ohsome_contributions_geometry(boundary = NULL, ...)
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
geometryType |
character; type of geometry to be extracted:
Caveat: Node elements are omitted from results in queries for bounding boxes. |
latest |
logical; if |
time |
character; |
properties |
character; properties to be extracted with the contributions:
Multiple values can be provided as comma-separated character or as
character vector. This defaults to |
clipGeometry |
logical; specifies whether the returned geometries should be clipped to the query’s spatial boundary |
... |
Parameters of the request to the ohsome API endpoint. |
ohsome_extract_contributions()
creates an ohsome_query
object for OSM
contribution extraction. ohsome_contributions_bbox()
,
ohsome_contributions_centroid()
and ohsome_contributions_geometry()
are wrapper functions for specific contributions extraction endpoints.
Boundary objects are passed via set_boundary()
into ohsome_boundary()
.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
ohsome API Endpoints – Contributions Extraction
# Extract contributions to man-made objects around "Null Island" with metadata: ohsome_contributions_geometry( "0,0,10", filter = "man_made=*", time = c("2021-01-01", "2022-01-01"), properties = "metadata" )
# Extract contributions to man-made objects around "Null Island" with metadata: ohsome_contributions_geometry( "0,0,10", filter = "man_made=*", time = c("2021-01-01", "2022-01-01"), properties = "metadata" )
Create an ohsome_query
object for OSM element extraction
ohsome_extract_elements( boundary = NULL, geometryType = c("centroid", "bbox", "geometry"), time = NULL, properties = NULL, clipGeometry = TRUE, ... ) ohsome_elements_bbox(boundary = NULL, ...) ohsome_elements_centroid(boundary = NULL, ...) ohsome_elements_geometry(boundary = NULL, ...)
ohsome_extract_elements( boundary = NULL, geometryType = c("centroid", "bbox", "geometry"), time = NULL, properties = NULL, clipGeometry = TRUE, ... ) ohsome_elements_bbox(boundary = NULL, ...) ohsome_elements_centroid(boundary = NULL, ...) ohsome_elements_geometry(boundary = NULL, ...)
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
geometryType |
character; type of geometry to be extracted:
Caveat: Node elements are omitted from results in queries for bounding boxes. |
time |
character; |
properties |
character; properties to be extracted with the features:
Multiple values can be provided as comma-separated character or as
character vector. This defaults to |
clipGeometry |
logical; specifies whether the returned geometries should be clipped to the query’s spatial boundary |
... |
Parameters of the request to the ohsome API endpoint. |
ohsome_extract_elements()
creates an ohsome_query
object for OSM element
extraction. ohsome_elements_bbox()
, ohsome_elements_centroid()
and
ohsome_elements_geometry()
are wrapper functions for specific elements
extraction endpoints. Boundary objects are passed via set_boundary()
into
ohsome_boundary()
.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
ohsome API Endpoints – Elements Extraction
# Extract geometries, metadata and tags of man-made objects around "Null Island": ohsome_elements_geometry( "0,0,10", filter = "man_made=*", time = "2022-01-01", properties = c("metadata", "tags") )
# Extract geometries, metadata and tags of man-made objects around "Null Island": ohsome_elements_geometry( "0,0,10", filter = "man_made=*", time = "2022-01-01", properties = c("metadata", "tags") )
Creates an ohsome_query
object for the extraction of OSM elements' full
history
ohsome_extract_elementsFullHistory( boundary = NULL, geometryType = c("centroid", "bbox", "geometry"), time = NULL, properties = NULL, clipGeometry = TRUE, ... ) ohsome_elementsFullHistory_bbox(boundary = NULL, ...) ohsome_elementsFullHistory_centroid(boundary = NULL, ...) ohsome_elementsFullHistory_geometry(boundary = NULL, ...)
ohsome_extract_elementsFullHistory( boundary = NULL, geometryType = c("centroid", "bbox", "geometry"), time = NULL, properties = NULL, clipGeometry = TRUE, ... ) ohsome_elementsFullHistory_bbox(boundary = NULL, ...) ohsome_elementsFullHistory_centroid(boundary = NULL, ...) ohsome_elementsFullHistory_geometry(boundary = NULL, ...)
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
geometryType |
character; type of geometry to be extracted:
Caveat: Node elements are omitted from results in queries for bounding boxes. |
time |
character; |
properties |
character; properties to be extracted with the features:
Multiple values can be provided as comma-separated character or as
character vector. This defaults to |
clipGeometry |
logical; specifies whether the returned geometries should be clipped to the query’s spatial boundary |
... |
Parameters of the request to the ohsome API endpoint. |
ohsome_extract_elementsFullHistory()
creates an ohsome_query
object for OSM
element full history extraction. ohsome_elementsFullHistory_bbox()
,
ohsome_elementsFullHistory_centroid()
and
ohsome_elementsFullHistory_geometry()
are wrapper functions for specific
elementsFullHistory extraction endpoints. Boundary objects are passed via
set_boundary()
into ohsome_boundary()
.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
ohsome API Endpoints – Elements Full History Extraction
# Extract full history of building geometries around Heidelberg main station: ohsome_elementsFullHistory_geometry( boundary = "8.67542,49.40347,1000", time = "2012,2022", filter = "building=* and geometry:polygon", clipGeometry = FALSE )
# Extract full history of building geometries around Heidelberg main station: ohsome_elementsFullHistory_geometry( boundary = "8.67542,49.40347,1000", time = "2012,2022", filter = "building=* and geometry:polygon", clipGeometry = FALSE )
Returns parsed metadata from ohsome API
ohsome_get_metadata(quiet = FALSE)
ohsome_get_metadata(quiet = FALSE)
quiet |
logical; suppresses message on data attribution, API version and temporal extent. |
ohsome_get_metadata()
sends a GET request to the metadata endpoint of
ohsome API and parses the response. The parsed metadata is silently returned.
An ohsome_metadata
object. This is a named list with the
attributes date
, status_code
(of the GET request) and the following list
elements:
attribution
: character; url
and text
of OSM data copyrights and
attribution
apiVersion
: character; Version of the ohsome API
timeout
: numeric; limit of the processing time in seconds
extractRegion
:
spatialExtent
: sfc_POLYGON; spatial boundary of the OSM data in the
underlying OSHDB
temporalExtent
: vector of ISO 8601 character; start and end of the temporal extent of OSM data in the
underlying OSHDB
replicationSequenceNumber
: numeric; precise state of the OSM data
contained in the underlying OSHDB, expressed as the id of the last
applied (hourly) diff file from Planet OSM
ohsome API Endpoints – Metadata
## Not run: ohsome_get_metadata() ## End(Not run)
## Not run: ohsome_get_metadata() ## End(Not run)
Metadata of the ohsome API that is requested on loading the package
An ohsome_metadata
object. This is a named list with the
attributes date
, status_code
(of the GET request) and the following list
elements:
attribution
: character; url
and text
of OSM data copyrights and
attribution
apiVersion
: numeric_version; Version of the ohsome API
timeout
: numeric; limit of the processing time in seconds
extractRegion
:
spatialExtent
: sfc_POLYGON; spatial boundary of the OSM data in the
underlying OSHDB
temporalExtent
: vector of POSIXct; timeframe of the OSM data in the
underlying OSHDB data
replicationSequenceNumber
: numeric; precise state of the OSM data
contained in the underlying OSHDB, expressed as the id of the last
applied (hourly) diff file from Planet OSM
Extracts and parses the content from an ohsome API response
ohsome_parse( response, returnclass = c("default", "sf", "data.frame", "list", "character"), omit_empty = TRUE ) ohsome_sf(response, omit_empty = TRUE) ohsome_df(response, omit_empty = TRUE)
ohsome_parse( response, returnclass = c("default", "sf", "data.frame", "list", "character"), omit_empty = TRUE ) ohsome_sf(response, omit_empty = TRUE) ohsome_df(response, omit_empty = TRUE)
response |
An |
returnclass |
character; one of the following:
|
omit_empty |
logical; omit features with empty geometries (only if
|
ohsome_parse()
parses an ohsome_response
object into an object of the
specified class. By default, this is an sf
object if the ohsome API
response contains GeoJSON data or a data.frame
if it does not.
ohsome_sf()
and ohsome_df()
wrapper functions for specific return
classes.
An sf
object, a data.frame
, a list
or a character
## Not run: # Create and send a query to ohsome API r <- ohsome_query("elements/centroid", filter = "amenity=*") |> set_boundary(osmdata::getbb("Heidelberg")) |> set_time("2021") |> set_properties("metadata") |> ohsome_post(parse = FALSE) # Parse response to object of default class (here: sf) ohsome_parse(r) # Parse response to data.frame ohsome_df(r) # Parse response to sf ohsome_sf(r) ## End(Not run)
## Not run: # Create and send a query to ohsome API r <- ohsome_query("elements/centroid", filter = "amenity=*") |> set_boundary(osmdata::getbb("Heidelberg")) |> set_time("2021") |> set_properties("metadata") |> ohsome_post(parse = FALSE) # Parse response to object of default class (here: sf) ohsome_parse(r) # Parse response to data.frame ohsome_df(r) # Parse response to sf ohsome_sf(r) ## End(Not run)
Sends an ohsome_query
object as a POST request to the ohsome API and
returns the response.
ohsome_post( query, parse = TRUE, validate = TRUE, strict = validate, additional_identifiers = NULL, ... )
ohsome_post( query, parse = TRUE, validate = TRUE, strict = validate, additional_identifiers = NULL, ... )
query |
An |
parse |
logical; if |
validate |
logical; if |
strict |
logical; If |
additional_identifiers |
vector coercible to character; optional user
agent identifiers in addition to |
... |
Additional arguments passed to
|
An ohsome_response
object if parse = FALSE
, else an sf
object,
a data.frame
, a list
or a character
## Not run: # Get bounding box of the city of Berlin bbberlin <- osmdata::getbb("Berlin") # Query for cinema geometries within bounding box q <- ohsome_elements_geometry(bbberlin, filter = "amenity=cinema") # Send query to ohsome API and return sf by default ohsome_post(q) # Send query to ohsome API and return data.frame ohsome_post(q, returnclass = "data.frame") # Send query and return unparsed response ohsome_post(q, parse = FALSE) ## End(Not run)
## Not run: # Get bounding box of the city of Berlin bbberlin <- osmdata::getbb("Berlin") # Query for cinema geometries within bounding box q <- ohsome_elements_geometry(bbberlin, filter = "amenity=cinema") # Send query to ohsome API and return sf by default ohsome_post(q) # Send query to ohsome API and return data.frame ohsome_post(q, returnclass = "data.frame") # Send query and return unparsed response ohsome_post(q, parse = FALSE) ## End(Not run)
ohsome_query
objectCreates an ohsome_query
object specifying the ohsome API endpoint and
the request parameters.
ohsome_query(endpoint, boundary = NULL, grouping = NULL, ..., validate = FALSE)
ohsome_query(endpoint, boundary = NULL, grouping = NULL, ..., validate = FALSE)
endpoint |
The path to the
ohsome API endpoint.
Either a single string (e.g. |
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
grouping |
character; group type(s) for grouped aggregations (only available for queries to aggregation endpoints). The following group types are available:
Not all of these group types are accepted by all of the aggregation endpoints. Check Grouping for available group types. |
... |
Parameters of the request to the ohsome API endpoint. |
validate |
logical; if |
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
# Extract building geometries with manually set bboxes parameter ohsome_query( "elements/geometry", bboxes = "8.6,49.36,8.75,49.44", time = "2022-01-01", filter = "building=*" ) # Extract building geometries using a boundary object: ohsome_query( "elements/geometry", boundary = "8.6,49.36,8.75,49.44", time = "2022-01-01", filter = "building=*" )
# Extract building geometries with manually set bboxes parameter ohsome_query( "elements/geometry", bboxes = "8.6,49.36,8.75,49.44", time = "2022-01-01", filter = "building=*" ) # Extract building geometries using a boundary object: ohsome_query( "elements/geometry", boundary = "8.6,49.36,8.75,49.44", time = "2022-01-01", filter = "building=*" )
Temporal extent of the OSM data in the underlying OSHDB
A vector of POSIXct
Create an ohsome_query
object for OSM users count
ohsome_users_count( boundary = NULL, return_value = c("absolute", "density"), grouping = NULL, time = NULL, ... )
ohsome_users_count( boundary = NULL, return_value = c("absolute", "density"), grouping = NULL, time = NULL, ... )
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
return_value |
character; the value to be returned by the ohsome API:
|
grouping |
character; group type(s) for grouped aggregations (only available for queries to aggregation endpoints). The following group types are available:
Not all of these group types are accepted by all of the aggregation endpoints. Check Grouping for available group types. |
time |
character; |
... |
Parameters of the request to the ohsome API endpoint. |
ohsome_users_count()
creates an ohsome_query
object for OSM users
aggregation. Boundary objects are passed via set_boundary()
into
ohsome_boundary()
.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
ohsome API Endpoints – Users Aggregation
# Yearly count of users contributing to man-made objects around "Null Island" ohsome_users_count("0,0,10", filter = "man_made=*", time = "2012/2022/P1Y")
# Yearly count of users contributing to man-made objects around "Null Island" ohsome_users_count("0,0,10", filter = "man_made=*", time = "2012/2022/P1Y")
Set or modify the spatial filter of an existing ohsome_query
object
set_boundary(query, boundary = NULL, ...)
set_boundary(query, boundary = NULL, ...)
query |
An |
boundary |
Bounding geometries specified by WGS84 coordinates in the
order
|
... |
Additional arguments other than |
set_boundary()
adds a spatial filter to an ohsome_query
object or
replaces an existing one. The spatial filter of a query to the ohsome API can
be defined as one or more polygons, bounding boxes or bounding circles.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
# Query without boundary definition q <- ohsome_query( "elements/count/groupBy/boundary", filter = "building=*", time = "2022-01-01" ) # Use franconia from the mapview package as bounding polygons set_boundary(q, mapview::franconia, digits = 4) # Use the bounding box of franconia set_boundary(q, sf::st_bbox(mapview::franconia)) ## Not run: # Get bounding box of the city of Kigali from OSM set_boundary(q, osmdata::getbb("Kigali")) ## End(Not run) # Definition of two named bounding circles set_boundary(q, c("Circle 1:8.6528,49.3683,1000", "Circle 2:8.7294,49.4376,1000"))
# Query without boundary definition q <- ohsome_query( "elements/count/groupBy/boundary", filter = "building=*", time = "2022-01-01" ) # Use franconia from the mapview package as bounding polygons set_boundary(q, mapview::franconia, digits = 4) # Use the bounding box of franconia set_boundary(q, sf::st_bbox(mapview::franconia)) ## Not run: # Get bounding box of the city of Kigali from OSM set_boundary(q, osmdata::getbb("Kigali")) ## End(Not run) # Definition of two named bounding circles set_boundary(q, c("Circle 1:8.6528,49.3683,1000", "Circle 2:8.7294,49.4376,1000"))
Modifies the endpoint of an existing ohsome_query
object
set_endpoint(query, endpoint, append = FALSE, reset_format = TRUE) set_grouping(query, grouping, ...)
set_endpoint(query, endpoint, append = FALSE, reset_format = TRUE) set_grouping(query, grouping, ...)
query |
An |
endpoint |
The path to the
ohsome API endpoint.
Either a single string (e.g. |
append |
logical; If |
reset_format |
logical; if |
grouping |
character; group type(s) for grouped aggregations (only available for queries to aggregation endpoints). The following group types are available:
Not all of these group types are accepted by all of the aggregation endpoints. Check Grouping for available group types. |
... |
Additional arguments passed to |
set_endpoint()
takes an ohsome_query
object and modifies the ohsome API
endpoint. set_grouping()
takes an ohsome_query
object and modifies the
endpoint path for grouped aggregations.
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
# Query for count of elements q <- ohsome_elements_count( boundary = "HD:8.5992,49.3567,8.7499,49.4371|HN:9.1638,49.113,9.2672,49.1766", time = "2022-01-01", filter = "highway=*" ) # Modify query to aggregate length of elements instead of count set_endpoint(q, "elements/length") # Modify query to extract geometries instead of aggregating elements set_endpoint(q, "elements/geometry") # Append the endpoint path in order to group aggregation by boundary set_endpoint(q, "groupBy/boundary", append = TRUE) # Modify query to group aggregation by boundary set_grouping(q, grouping = "boundary") # Modify query to group by boundary, but keep format csv instead of geojson set_grouping(q, grouping = "boundary", reset_format = FALSE) # Append the endpoint path to query for element densities per boundary set_endpoint(q, c("density", "groupBy", "boundary"), append = TRUE) # Modify query to group aggregation by OSM element type set_grouping(q, grouping = "type")
# Query for count of elements q <- ohsome_elements_count( boundary = "HD:8.5992,49.3567,8.7499,49.4371|HN:9.1638,49.113,9.2672,49.1766", time = "2022-01-01", filter = "highway=*" ) # Modify query to aggregate length of elements instead of count set_endpoint(q, "elements/length") # Modify query to extract geometries instead of aggregating elements set_endpoint(q, "elements/geometry") # Append the endpoint path in order to group aggregation by boundary set_endpoint(q, "groupBy/boundary", append = TRUE) # Modify query to group aggregation by boundary set_grouping(q, grouping = "boundary") # Modify query to group by boundary, but keep format csv instead of geojson set_grouping(q, grouping = "boundary", reset_format = FALSE) # Append the endpoint path to query for element densities per boundary set_endpoint(q, c("density", "groupBy", "boundary"), append = TRUE) # Modify query to group aggregation by OSM element type set_grouping(q, grouping = "type")
Sets or modifies parameters of an existing ohsome_query
object
set_parameters(query, ...) set_time(query, time = query$body$time) set_filter(query, filter = query$body$filter, filter2 = query$body$filter2) set_groupByKeys(query, groupByKeys = query$body$groupByKeys) set_groupByKey(query, groupByKey = query$body$groupByKey) set_groupByValues(query, groupByValues = query$body$groupByValues) set_properties(query, properties = NULL)
set_parameters(query, ...) set_time(query, time = query$body$time) set_filter(query, filter = query$body$filter, filter2 = query$body$filter2) set_groupByKeys(query, groupByKeys = query$body$groupByKeys) set_groupByKey(query, groupByKey = query$body$groupByKey) set_groupByValues(query, groupByValues = query$body$groupByValues) set_properties(query, properties = NULL)
query |
An |
... |
Parameters of the request to the ohsome API endpoint. |
time |
character; |
filter |
character; |
filter2 |
character; |
groupByKeys |
character; |
groupByKey |
character; |
groupByValues |
character; |
properties |
character; properties to be extracted with extraction queries:
Multiple values can be provided as comma-separated character or as
character vector. This defaults to |
set_parameters()
takes an ohsome_query
object and an arbitrary number of
named parameters as an input. It sets or modifies these parameters in the
ohsome_query
and returns the modified object. set_time()
, set_filter()
,
set_groupByKeys()
, set_groupByKey()
, set_groupByValues()
and
set_properties()
are wrapper functions to set specific parameters. By
default, an unmodified ohsome_query
object is returned. In order to remove
a parameter from the query object, you can set the respective argument
explicitly to NULL
(e.g. set_filter(query, filter = NULL)
).
An ohsome_query
object. The object can be sent to the ohsome API
with ohsome_post()
. It consists of the following elements:
url
: The URL of the endpoint.
encode
: The way the information is encoded and then posted to the
ohsome API. Set as "form"
.
body
: The parameters of the query such as format
, filter
or
bpolys
.
https://docs.ohsome.org/ohsome-api/v1/
# Query ratio grouped by boundary q1 <- ohsome_query( endpoint = "elements/count/ratio/groupBy/boundary", boundary = "HD:8.5992,49.3567,8.7499,49.4371|HN:9.1638,49.113,9.2672,49.1766" ) # Add time, filter and format parameters q1 |> set_time("2021/2022/P3M") |> set_filter("building=*", filter2 = "building=* and building:levels=3") |> set_parameters(format = "csv") # Query elements area grouped by tag q2 <- ohsome_query( endpoint = "elements/area/groupBy/tag", boundary = "HD:8.5992,49.3567,8.7499,49.4371" ) # Add time, filter and groupByKey parameters q2 |> set_time("2021/2022/P3M") |> set_filter("building=*") |> set_groupByKey("building:levels")
# Query ratio grouped by boundary q1 <- ohsome_query( endpoint = "elements/count/ratio/groupBy/boundary", boundary = "HD:8.5992,49.3567,8.7499,49.4371|HN:9.1638,49.113,9.2672,49.1766" ) # Add time, filter and format parameters q1 |> set_time("2021/2022/P3M") |> set_filter("building=*", filter2 = "building=* and building:levels=3") |> set_parameters(format = "csv") # Query elements area grouped by tag q2 <- ohsome_query( endpoint = "elements/area/groupBy/tag", boundary = "HD:8.5992,49.3567,8.7499,49.4371" ) # Add time, filter and groupByKey parameters q2 |> set_time("2021/2022/P3M") |> set_filter("building=*") |> set_groupByKey("building:levels")