Title: | Access OS OpenData APIs From R |
---|---|
Description: | A package to enable accessing basemap tiles from the [OS Maps API](https://osdatahub.os.uk/docs/wmts/overview), initially. Access to other OS (Ordnance Survey) Data Hub APIs may follow. The primary motivation for this project was to find a map tile service that supplies tiles in the British National Grid (27700) CRS, unlike the usual web mapping standard CRS of 3857. The name of the package is an intentional corruption of the Spanish word mariposa 🦋. |
Authors: | Fran Barton [aut, cre] |
Maintainer: | Fran Barton <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.6 |
Built: | 2024-11-08 05:29:59 UTC |
Source: | https://github.com/francisbarton/mapirosa |
Build a basemap from the Ordnance Survey Maps API
build_basemap(bbox, zoom, crs = c(27700, 3857), ...)
build_basemap(bbox, zoom, crs = c(27700, 3857), ...)
bbox |
A bbox object (a length 4 vector with names xmin, ymin, xmax, ymax) |
zoom |
Zoom level, an integer. For |
crs |
CRS code (EPSG), an integer, either |
... |
Other details to pass on to generate_png_data() |
A geospatially-referenced raster... hopefully.
oxf <- create_bbox("Oxford", 27700) oxford_basemap <- build_basemap(oxf, zoom = 5, style = "road", crs = 27700) tmap::tm_shape(oxford_basemap, raster.downsample = FALSE) + tmap::tm_rgb(max.value = 1)
oxf <- create_bbox("Oxford", 27700) oxford_basemap <- build_basemap(oxf, zoom = 5, style = "road", crs = 27700) tmap::tm_shape(oxford_basemap, raster.downsample = FALSE) + tmap::tm_rgb(max.value = 1)
Internal check for a valid combination of CRS, map style and zoom level
check_zoom( zoom, style = c("outdoor", "road", "light", "leisure"), crs = c(27700, 3857), allow_premium = FALSE )
check_zoom( zoom, style = c("outdoor", "road", "light", "leisure"), crs = c(27700, 3857), allow_premium = FALSE )
zoom |
Zoom level, an integer. For |
crs |
CRS code (EPSG), an integer, either |
No visible return unless an error is thrown
Only the first search result from osmdata gets used, however
create_bbox(place, crs)
create_bbox(place, crs)
place |
string: place name to search for |
crs |
integer or string: the EPSG code for the desired CRS |
Retrieve PNG data (tiles) to cover a bbox, and generate a list of extents for each tile
generate_png_data( bbox, zoom, crs, style = c("outdoor", "road", "light", "leisure"), squarify = TRUE, squarify_to = c("south", "east"), cache_tiles = FALSE, allow_premium = FALSE, debug = FALSE )
generate_png_data( bbox, zoom, crs, style = c("outdoor", "road", "light", "leisure"), squarify = TRUE, squarify_to = c("south", "east"), cache_tiles = FALSE, allow_premium = FALSE, debug = FALSE )
bbox |
A bbox object (a length 4 vector with names xmin, ymin, xmax, ymax) |
zoom |
Zoom level, an integer. For |
crs |
CRS code (EPSG), an integer, either |
style |
Map style, a string. One of "road", "outdoor", "light", "leisure". Leisure is only available in the 27700 CRS. |
squarify |
Whether to add rows/columns to a basemap to make it square.
|
squarify_to |
Where |
cache_tiles |
Instead of converting PNG data from the API into a
basemap on the fly, cache data as local PNG files. Not functional yet;
hence set to |
allow_premium |
Whether to only access tiles from zoom levels that are within the "OpenData" tier of the OS API. These vary according to map style and CRS. See the API Technical Specification for details. Defaults to FALSE. Set to TRUE if you wish to access zoom levels within the "Premium" service tier (chargeable |
debug |
Whether to show any errors that were received from the API. This package should handle errors gracefully in general, but if your basemap is not complete then you may wish to turn this on to see what errors there might be. |
a list of length 2: a list of PNG data and a list of extents for each tile
Function not yet completed and functional. See https://osdatahub.os.uk/docs/wfs/technicalSpecification for details.
query_features_api( x, version = c("2.0.0", "1.1.0", "1.0.0"), user_agent = NULL )
query_features_api( x, version = c("2.0.0", "1.1.0", "1.0.0"), user_agent = NULL )
x |
character. The name of a place, or a postcode for example. The API docs say 'A free string text search of OS Names, intended to be an ambiguous/fuzzy search.' |
version |
character. API version. Most recent (2.0.0) by default. |
user_agent |
character. |
A raw response from the API endpoint - you will want to process this.
Build and perform a query to the OS Maps API
query_maps_api(x, y, zoom, style, crs, user_agent = NULL)
query_maps_api(x, y, zoom, style, crs, user_agent = NULL)
x |
Tile number (horizontally) |
y |
Tile number (vertically) |
zoom |
Zoom level, an integer. For |
crs |
CRS code (EPSG), an integer, either |
user_agent |
A User-Agent string to pass to the API |
Raw PNG data
Only uses 'find' method currently, not 'nearest' yet. See https://osdatahub.os.uk/docs/names/technicalSpecification for details.
query_names_api( x, local_types = NULL, bounds = NULL, max_results = 1L, user_agent = NULL )
query_names_api( x, local_types = NULL, bounds = NULL, max_results = 1L, user_agent = NULL )
x |
character. The name of a place, or a postcode for example. The API docs say 'A free string text search of OS Names, intended to be an ambiguous/fuzzy search.' |
local_types |
character vector. Types of result to return. Examples are:
'City', 'Village'. See API docs for all options. |
bounds |
bbox. The bounding box of an area to limit search to. |
max_results |
integer. How many results to return. Can be from 1-100. Set to 1 by default. |
user_agent |
character. |
An sfc geospatial tibble
query_names_api(c("Stroud", "Gloucester"))
query_names_api(c("Stroud", "Gloucester"))