Type: Package
Title: API Wrapper Around 'Postcodes.io'
Version: 0.3.1
Maintainer: Eryk Walczak <erykjwalczak@gmail.com>
Description: Free UK geocoding using data from Office for National Statistics. It is using several functions to get information about post codes, outward codes, reverse geocoding, nearest post codes/outward codes, validation, or randomly generate a post code. API wrapper around https://postcodes.io.
License: GPL-3
URL: https://docs.ropensci.org/PostcodesioR/
Depends: R (≥ 3.1)
Imports: httr
RoxygenNote: 7.1.2
Suggests: knitr, dplyr, rmarkdown, testthat, covr, purrr
VignetteBuilder: knitr
BugReports: https://github.com/ropensci/PostcodesioR/issues
NeedsCompilation: no
Packaged: 2021-11-30 22:20:44 UTC; e
Author: Eryk Walczak ORCID iD [aut, cre], Claudia Vitolo ORCID iD [rev], Robin Lovelace ORCID iD [rev]
Repository: CRAN
Date/Publication: 2021-12-01 00:40:11 UTC

Bulk postcode lookup

Description

Returns a list of matching postcodes and respective available data.

Usage

bulk_postcode_lookup(postcodes)

Arguments

postcodes

Accepts a list of postcodes. Accepts up to 100 postcodes. For only one postcode use postcode_lookup.

Value

A list of length one.

See Also

postcode_lookup for documentation.

Examples


pc_list <- list(
postcodes = c("PR3 0SG", "M45 6GN", "EX165BL")) # spaces are ignored
bulk_postcode_lookup(pc_list)
# The function needs a list of length one. This won't work:
bulk_postcode_lookup(list("PR3 0SG", "M45 6GN", "EX165BL"))



Bulk reverse geocoding

Description

Returns nearest postcodes for a given longitude and latitude. Accepts up to 100 geolocations.

Usage

bulk_reverse_geocoding(geolocations)

Arguments

geolocations

A list containing an array of objects to geolocate. At least two elements needed.

Details

This method requires a JSON object containing an array of geolocation objects to be POSTed. Each geolocation object accepts an optional radius (meters) and limit argument. Both default to 100m and 10 respectively. It also accepts a wideSearch argument.

Value

A list with the geocoded data.

See Also

postcode_lookup for documentation.

Examples



geolocations_list <- structure(
list(
geolocations = structure(
list(
longitude = c(-3.15807731271522, -1.12935802905177),
latitude = c(51.4799900627036, 50.7186356978817),
limit = c(NA, 100L),
radius = c(NA, 500L)),
.Names = c("longitude", "latitude", "limit", "radius"),
class = "data.frame",
row.names = 1:2)),
.Names = "geolocations")

bulk_reverse_geocoding(geolocations_list)



Nearest outcode

Description

Returns nearest outcodes for a given outcode. The search is based on the relative distance of the outcode centroid.

Usage

nearest_outcode(outcode, limit = 10, radius = 5000)

Arguments

outcode

A string with a UK postcode.

limit

An integer. Optional parameter. Limits number of postcodes matches to return. Defaults to 10. Needs to be less than 100.

radius

An integer. Optional parameter. Limits number of postcodes matches to return. Defaults to 5,000m. Needs to be less than 25,000m.

Value

A list of geographical properties.

See Also

postcode_lookup for documentation.

Examples


nearest_outcode("EC1Y")
nearest_outcode("EC1Y", limit = 11)
nearest_outcode("EC1Y", limit = 11, radius = 6000)



Nearest outcodes given longitude and latitude

Description

Returns nearest outward codes for a given longitude and latitude. The search is based on the relative distance of the outcode centroid.

Usage

nearest_outcode_lonlat(longitude, latitude)

Arguments

longitude

A string or numeric. Needs to have at least three decimal points.

latitude

A string or numeric. Needs to have at least three decimal points.

Value

A list with available data.

See Also

postcode_lookup for documentation.

Examples


nearest_outcode_lonlat(0.127, 51.507)



Nearest postcode

Description

Returns nearest postcodes for a given postcode. The search is based on the relative distance of the postcode centroid.

Usage

nearest_postcode(postcode, limit = 10, radius = 100)

Arguments

postcode

A string. Valid UK postcode.

limit

A string or integer. Limits number of postcodes matches to return. Defaults to 10. Needs to be lower than 100.

radius

Limits number of postcodes matches to return. Defaults to 100m. Needs to be less than 2,000m.

Value

A list of geographic properties of the nearest postcode.

Examples


nearest_postcode("EC1Y 8LX")
nearest_postcode("EC1Y 8LX", limit = 11)
nearest_postcode("EC1Y 8LX", limit = 12, radius = 200)



Outcode reverse geocoding

Description

Returns nearest outcodes for a given longitude and latitude.

Usage

outcode_reverse_geocoding(longitude, latitude, limit = 10, radius = 5000)

Arguments

longitude

A string, integer or float. Needs to have at least two decimal points.

latitude

A string, integer or float. Needs to have at least two decimal points.

limit

A string, integer or float. Limits number of postcodes matches to return. Defaults to 10. Needs to be less than 100.

radius

A string, integer or float. Limits number of postcodes matches to return. Defaults to 5,000m. Needs to be less than 25,000m.

Value

A list of geographical properties.

See Also

postcode_lookup for documentation.

Examples


outcode_reverse_geocoding("-3.15", "51.47")
outcode_reverse_geocoding(-3.15, 51.47)
outcode_reverse_geocoding("-3.15807731271522", "51.4799900627036")
outcode_reverse_geocoding(-3.15, 51.47, limit = 11, radius = 20000)



Outward code lookup

Description

Geolocation data for the centroid of the outward code specified.

Usage

outward_code_lookup(outcode)

Arguments

outcode

A string. The outward code representing the first half of any postcode (separated by a space).

Value

The list of geographical properties.

See Also

postcode_lookup for documentation.

Examples


outward_code_lookup("E1")



Place lookup

Description

Lookup a place by code. Returns all available data if found. Returns 404 if a place does not exist.

Usage

place_lookup(code)

Arguments

code

A string. The unique identifier for places - Ordnance Survey (OSGB) code.

Value

A list with available places.

See https://postcodes.io/docs for more details.

Examples


place_lookup("osgb4000000074544700")



Place query

Description

Submit a place query and receive a complete list of places matches and associated data. This function is similar to place_lookup but it returns a list and allows limiting the results.

Usage

place_query(place, limit = 10)

Arguments

place

A string. Name of a place to search for.

limit

An integer. Limits the number of matches to return. Defaults to 10. Needs to be less than 100.

Value

A list with available places.

See Also

place_lookup for documentation.

Examples


place_query("Hills")
place_query("Hills", limit = 12)



Postcode autocomplete

Description

Returns a data frame of matching postcodes.

Usage

postcode_autocomplete(postcode, limit = 10)

Arguments

postcode

A string. Valid UK postcode.

limit

An integer. Limits number of postcodes matches to return. Defaults to 10. Needs to be less than 100.

Value

A data frame with suggested postcodes.

Examples


postcode_autocomplete("E1")
postcode_autocomplete("E1", limit = 11)



Postcode lookup

Description

Lookup a postcode.

Usage

postcode_lookup(postcode)

Arguments

postcode

A string. One valid UK postcode. This function is case- and space-insensitive. For more than one postcode use bulk_postcode_lookup. For Scottish postcodes use scottish_postcode_lookup.

Value

A data frame. Returns all available data if found. Returns NAs if postcode does not exist (404).

See https://postcodes.io/docs for more details.

Examples


postcode_lookup("EC1Y8LX")
postcode_lookup("EC1Y 8LX") # spaces are ignored
postcode_lookup("DE3 5LF") # terminated postcode returns NAs



Postcode query

Description

Submit a postcode query and receive a complete list of postcode matches and all associated postcode data.

Usage

postcode_query(postcode, limit = 10)

Arguments

postcode

A string. Valid UK postcode.

limit

An integer. Limits the number of matches to return. Defaults to 10. Needs to be less than 100.

Value

A list of geographic properties. To return a data frame use postcode_lookup.

Examples


postcode_query("EC1Y8LX")
postcode_query("EC1", limit = 11)



Postcode validation

Description

Convenience method to validate a postcode.

Usage

postcode_validation(postcode)

Arguments

postcode

A string. Valid UK postcode.

Value

A logical vector: True or False (meaning respectively valid or invalid postcode).

Examples


postcode_validation("EC1Y 8LX") # returns TRUE
postcode_validation("XYZ") # returns FALSE



Random place

Description

Returns a random place and all associated data

Usage

random_place()

Value

A data frame describing a random place and all associated data.

See Also

place_lookup for documentation.

Examples


random_place()



Random postcode

Description

Returns a random postcode and all available data for that postcode.

Usage

random_postcode(outcode = NULL)

Arguments

outcode

A string. Filters random postcodes by outcode. Returns null if invalid outcode. Optional.

Value

A list with a random postcode with corresponding characteristics.

See Also

postcode_lookup for documentation.

Examples


random_postcode()
random_postcode("N1")



Reverse geocoding

Description

Returns nearest postcodes for a given longitude and latitude.

Usage

reverse_geocoding(
  longitude,
  latitude,
  limit = 10,
  radius = 100,
  wideSearch = NULL
)

Arguments

longitude

A string or numeric. Needs to have at least three decimal points.

latitude

A string or numeric. Needs to have at least three decimal points.

limit

An integer. Limits number of postcodes matches to return. Defaults to 10. Needs to be less than 100.

radius

An integer. Limits number of postcodes matches to return. Defaults to 100m. Needs to be less than 2,000m.

wideSearch

TRUE or FALSE. Search up to 20km radius, but subject to a maximum of 10 results. Since lookups over a wide area can be very expensive, we've created this method to allow you choose to make the trade off between search radius and number of results. Defaults to false. When enabled, radius and limits over 10 are ignored.

Value

A list with available data.

See Also

postcode_lookup for documentation.

Examples


reverse_geocoding(0.127, 51.507)
reverse_geocoding("0.1275", "51.5073", limit = 3)
reverse_geocoding("0.1275", "51.5073", limit = 11, radius = 200)



Scottish postcode lookup

Description

Lookup a Scottish postcode.

Usage

scottish_postcode_lookup(postcode)

Arguments

postcode

A string. One valid Scottish postcode. This function is case- and space-insensitive. For non-Scottish postcodes use postcode_lookup. For more than one non-Scottish postcode use bulk_postcode_lookup.

Value

A data frame. Returns all available data if found. Returns NAs if postcode does not exist (404).

See https://postcodes.io/docs for more details.

Examples


scottish_postcode_lookup("EH12NG")


Terminated postcode lookup

Description

Returns month and year if a postcode was terminated or is no longer active.

Usage

terminated_postcode(postcode)

Arguments

postcode

A string. Terminated UK postcode.

Value

A data frame with data about terminated postcode. NULL if postcode is active.

See https://postcodes.io/docs for more details.

Examples


terminated_postcode("EC1Y 8LX") # existing postcode
terminated_postcode("E1W 1UU") # terminated postcode