Learn R Programming

osmapiR (version 0.2.3)

osm_get_points_gps: Get GPS Points

Description

Use this to retrieve the GPS track points that are inside a given bounding box (formatted in a GPX format).

Usage

osm_get_points_gps(
  bbox,
  page_number = 0,
  format = c("R", "sf", "sf_lines", "sf_points", "gpx")
)

Value

If format = "R", returns a list of data frames with the points for each trace. For public and identifiable traces, the data frame include the attributes track_url, track_name, and track_desc. If format = "sf_lines", returns a sf object from sf. For format = "sf_points", returns a list of sf

object (see st_as_sf() for details).

format = "gpx"

Returns a xml2::xml_document with the following format:

<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0" creator="OpenStreetMap.org" xmlns="http://www.topografix.com/GPX/1/0">
  <trk>
    <name>20190626.gpx</name>
    <desc>Footpaths near Blackweir Pond, Epping Forest</desc>
    <url>https://api.openstreetmap.org/user/John%20Leeming/traces/3031013</url>
    <trkseg>
      <trkpt lat="51.6616100" lon="0.0534560">
        <time>2019-06-26T14:27:58Z</time>
      </trkpt>
      ...
    </trkseg>
    ...
  </trk>
  ...
</gpx>

  • This response is NOT wrapped in an OSM xml parent element.

  • The file format is GPX Version 1.0 which is not the current version. Verify that your tools support it.

Arguments

bbox

Coordinates for the area to retrieve the notes from (left,bottom,right,top). Floating point numbers in degrees, expressing a valid bounding box. The maximal width (right - left) and height (top - bottom) of the bounding box is 0.25 degree.

page_number

Specifies which groups of 5,000 points, or page, to return. The API call does not return more than 5,000 points at a time. In order to retrieve all of the points for a bounding box, set page_number = -1. When this parameter is 0 (zero), the command returns the first 5,000 points; when it is 1, the command returns points 5,001–10,000, etc. A vector is also valid (e.g. 0:2 to get the first 3 pages).

format

Format of the output. Can be "R" (default), "sf_lines" ("sf" is a synonym for "sf_lines"), "sf_points" or "gpx".

See Also

Other get GPS' functions: osm_get_data_gpx(), osm_get_gpx_metadata(), osm_list_gpxs()

Examples

Run this code
pts_gps <- osm_get_points_gps(bbox = c(-0.3667545, 40.2153246, -0.3354263, 40.2364915))
## bbox as a character value also works (bbox = "-0.3667545,40.2153246,-0.3354263,40.2364915").
pts_gps

## get attributes
lapply(pts_gps, function(x) attributes(x)[c("track_url", "track_name", "track_desc")])
attr(pts_gps, "gpx_attributes")

Run the code above in your browser using DataLab