rmapzen
is a client for any implementation of the Mapzen API. Though Mapzen itself has gone out of business, rmapzen
can be set up to work with any provider who hosts Mapzen’s open-source software, including geocode.earth, Nextzen, and NYC GeoSearch from NYC Planning Labs. For more information, see https://mapzen.com/documentation/. The project is available on github as well as CRAN.
rmapzen
provides access to the following Mapzen API services:
rmapzen
works with API providers who implement the Mapzen API. In order to specify provider information (such as URL and API key), use mz_set_host
. There are custom set-up functions for the following providers:
mz_set_search_host_geocode.earth
mz_set_tile_host_nextzen
.mz_set_search_host_nyc_geosearch
.As of this writing, there are no public providers offering the Mapzen isochrone service.
All of the services in Mapzen search have been implemented. Search functions:
mz_search
mz_reverse_geocode
mz_autocomplete
mz_place
mz_structured_search
(what’s this?)Each of those functions returns a mapzen_geo_list
. The sample dataset oakland_public
contains the results of mz_search("Oakland public library branch")
on January 8, 2017:
#> GeoJSON response from Mapzen
#> Attribution info: https://search.mapzen.com/v1/attribution
#> Bounds (lon/lat): (-122.29, 37.74) - (-122.17, 37.85)
#> 25 locations:
#> Oakland Public Library - Temescal Branch (-122.26, 37.84)
#> Oakland Public Library - Rockridge Branch (-122.25, 37.84)
#> Lakeview Branch Oakland Public Library (-122.25, 37.81)
#> Golden Gate Branch Oakland Public Library (-122.28, 37.84)
#> Brookfield Village Branch Oakland Public Library (-122.19, 37.74)
#> ...
mz_bbox(oakland_public)
#> # A tibble: 1 x 4
#> min_lon min_lat max_lon max_lat
#> <dbl> <dbl> <dbl> <dbl>
#> 1 -122. 37.7 -122. 37.8
as.data.frame(oakland_public)
#> # A tibble: 25 x 26
#> id gid layer source source_id name housenumber confidence
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
#> 1 way:1… openstr… venue openst… way:1256… Oakland… 5205 0.926
#> 2 way:4… openstr… venue openst… way:4325… Oakland… <NA> 0.926
#> 3 way:3… openstr… venue openst… way:3697… Lakevie… <NA> 0.664
#> 4 53528… geoname… venue geonam… 5352843 Golden … <NA> 0.663
#> 5 node:… openstr… venue openst… node:368… Brookfi… <NA> 0.663
#> 6 way:4… openstr… venue openst… way:4391… West Oa… 1801 0.663
#> 7 node:… openstr… venue openst… node:368… Elmhurs… <NA> 0.663
#> 8 node:… openstr… venue openst… node:368… Montcla… <NA> 0.663
#> 9 way:2… openstr… venue openst… way:2837… Main Br… 125 0.663
#> 10 node:… openstr… venue openst… node:368… Latin A… <NA> 0.663
#> # ... with 15 more rows, and 18 more variables: accuracy <chr>,
#> # country <chr>, country_gid <chr>, country_a <chr>, region <chr>,
#> # region_gid <chr>, region_a <chr>, county <chr>, county_gid <chr>,
#> # locality <chr>, locality_gid <chr>, neighbourhood <chr>,
#> # neighbourhood_gid <chr>, label <chr>, street <chr>, postalcode <chr>,
#> # lon <dbl>, lat <dbl>
Search can, optionally, be constrained to a particular country, data layer, boundary rectangle, or boundary circle. Furthermore, search can prioritize results near a given “focus” point. See ?mz_search
.
rmapzen
provides an interface to Mapzen’s vector tiles service. Tile requests can be specified using the x, y, zoom coordinates of the tile service, as well as with a lat/long bounding box. Multiple tiles are stitched together and returned as an object of class mz_vector_tiles
. See ?mz_vector_tiles
. The sample data set ca_tiles
contains zoomed out vector tile data for all of California as well as parts of neighboring states.
ca_tiles
#> Mapzen vector tile data
#> Layers: (count of features in parentheses)
#> water (144)
#> buildings (0)
#> places (28)
#> transit (10)
#> pois (30)
#> boundaries (22)
#> roads (308)
#> earth (4)
#> landuse (176)
Each element of a vector tile response includes point, line, and/or polygon data for an individual map layer, and has class mapzen_vector_layer
. Like other response types, the mapzen_vector_layer
can be converted to sf
and sp
objects for further processing, using the generic functions as_sf
and as_sp
.
# points of interest
as_sf(ca_tiles$pois)
#> Simple feature collection with 30 features and 11 fields
#> geometry type: POINT
#> dimension: XY
#> bbox: xmin: -123.536 ymin: 32.009 xmax: -112.58 ymax: 48.808
#> epsg (SRID): 4326
#> proj4string: +proj=longlat +datum=WGS84 +no_defs
#> # A tibble: 30 x 12
#> kind protect_class area operator source min_zoom tier osm_relation
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 natio… 2 1377… United S… opens… 5.58 1 TRUE
#> 2 natio… 2 2035… United S… opens… 5.29 1 TRUE
#> 3 natio… 2 2132… United S… opens… 3.6 1 TRUE
#> 4 natio… 2 2543… United S… opens… 5.13 1 TRUE
#> 5 natio… 2 2552… United S… opens… 5.13 1 TRUE
#> 6 natio… 2 2740… United S… opens… 5.08 1 TRUE
#> 7 natio… 2 2812… United S… opens… 5.06 1 TRUE
#> 8 natio… 2 4671… United S… opens… 4.7 1 TRUE
#> 9 natio… 2 4858… United S… opens… 4.67 1 TRUE
#> 10 natio… 2 7790… United S… opens… 4.33 1 TRUE
#> # ... with 20 more rows, and 4 more variables: name <chr>, id <chr>,
#> # name.de <chr>, geometry <POINT [°]>
sf
and Spatial*DataFrame
conversionAny object returned by a Mapzen service can be converted to the appropriate Spatial*DataFrame
or sf
object using the generics as_sp
and as_sf
, for easy interoperability with other packages. You can also convert most objects directly to data frames, allowing for use within tidy pipelines:
library(dplyr)
library(sf)
as_sf(oakland_public) %>%
select(name, confidence, region, locality, neighbourhood)
#> Simple feature collection with 25 features and 5 fields
#> geometry type: POINT
#> dimension: XY
#> bbox: xmin: -122.2854 ymin: 37.73742 xmax: -122.1749 ymax: 37.84632
#> epsg (SRID): 4326
#> proj4string: +proj=longlat +datum=WGS84 +no_defs
#> # A tibble: 25 x 6
#> name confidence region locality neighbourhood
#> <chr> <dbl> <chr> <chr> <chr>
#> 1 Oakland Public Library - T… 0.926 Califor… Oakland Shafter
#> 2 Oakland Public Library - R… 0.926 Califor… Oakland Rockridge
#> 3 Lakeview Branch Oakland Pu… 0.664 Califor… Oakland <NA>
#> 4 Golden Gate Branch Oakland… 0.663 Califor… Oakland Gaskill
#> 5 Brookfield Village Branch … 0.663 Califor… Oakland South Stonehu…
#> 6 West Oakland Branch Oaklan… 0.663 Califor… Oakland Ralph Bunche
#> 7 Elmhurst Branch Oakland Pu… 0.663 Califor… Oakland Webster
#> 8 Montclair Branch Oakland P… 0.663 Califor… Oakland Montclair
#> 9 Main Branch Oakland Public… 0.663 Califor… Oakland Civic Center
#> 10 Latin American Branch Oakl… 0.663 Califor… Oakland St. Elizabeth
#> # ... with 15 more rows, and 1 more variable: geometry <POINT [°]>
Currently, the following methods are available to pull out commonly used pieces of a response:
mz_coordinates
(only available for search results): extracts lat/lon coordinates from search results, and returns them as a data.frame
.mz_bbox
: returns the bounding box of an object as a data.frame
with columns min_lon
, min_lat
, max_lon
, and max_lat
.mz_bbox(ca_tiles)
#> # A tibble: 1 x 4
#> min_lon min_lat max_lon max_lat
#> * <dbl> <dbl> <dbl> <dbl>
#> 1 -135 32.0 -112. 48.9