Package 'caRtociudad'

Title: Interface to Cartociudad API
Description: Access to Cartociudad cartography API, which provides mapping and other related services for Spain.
Authors: Carlos J. Gil Bellosta [cre, aut], Luz Frías [aut]
Maintainer: Carlos J. Gil Bellosta <[email protected]>
License: GPL-3
Version: 0.6.3
Built: 2024-08-20 02:28:42 UTC
Source: https://github.com/rOpenSpain/caRtociudad

Help Index


Interface to Cartociudad geolocation API

Description

Geolocation of Spanish addresses via Cartociudad API calls, providing the full address in a single text string via full_address. It is advisable to add the street type (calle, etc.) and to omit the country name.

Usage

cartociudad_geocode(full_address, on.error = "fail", ...)

Arguments

full_address

Character string providing the full address to be geolocated; e.g., "calle miguel servet 5, zaragoza". Adding the country may cause problems.

on.error

Defaults to fail; in such case, in case of errors in the API call, the process will fail. Set it to "warn" and, in case of errors, the function will return NULL and a warning.

...

Other parameters for the API. See Details section below.

Details

The entity geolocation API admits more parameters beyond the address field such as id or type. You can use these extra arguments (see the References or the Examples sections below for further information) at your own risk.

Value

A data frame consisting of a single row per guess. See the reference below for an explanation of the data frame columns.

Author(s)

Carlos J. Gil Bellosta

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

# standard usage
res <- cartociudad_geocode(full_address = "plaza de cascorro 11, 28005 madrid")

#' # km 41 of A-23 motorway
res <- cartociudad_geocode("A-23 41")

# specific usage (see References for details)
res <- cartociudad_geocode("A-23 41", type = "portal", id = "600000000045", portal = 41)

# vectorized call
## Not run: 
addresses <- paste("A-23", 1:10)
res <- lapply(addresses, cartociudad_geocode, on.error = "warn")

## End(Not run)

Area calculation

Description

Returns the polygon that describes the area

Usage

cartociudad_get_area(latitude, longitude, radius)

Arguments

latitude

Point latitude in geographical coordinates (e.g., 40.3930144)

longitude

Point longitude in geographical coordinates (e.g., -3.6596683)

radius

Distance in meters (e.g., 500)

Details

This function calculates the area given a point and a radius in meters

Value

A dataframe with the polygon that describes the area.

Author(s)

Luz Frias

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

cartociudad_get_area(40.3930144, -3.6596683, 500)

Administrative information for a location

Description

Returns the administrative information related to a geographical point in Spain: province, municipality, censal district, censal section, cadastral reference and reverse geocoding data.

Usage

cartociudad_get_location_info(latitude, longitude, year = 2016,
  info.source = c("census", "cadastre", "reverse"))

Arguments

latitude

Point latitude in geographical coordinates (e.g., 40.473219)

longitude

Point longitude in geographical coordinates (e.g., -3.7227241)

year

Reference year; see Details section

info.source

A character vector specifying the APIs to consult. Possible values are "census", "cadastre" and "reverse"

Details

This function consults administrative information for a point within Spain. Censal information is consulted from a different set of layers, each one corresponding to a different year. Whereas provincial and municipal information is mostly stable, censal districts and sections may be subject to greater changes over the years.

Value

A list contaning the administrative information for the given point. For info.source = "census" it contains the province, municipality, censal discrict and censal section codes. For info.source = "cadastre" it contains the cadastral reference and the url to the spanish cadastre website. For info.source = "reverse" it contains the details of the address closest to the specified location, such us road type, number, zip code, street name, ... More information about reverse geocoding in cartociudad_reverse_geocode.

Author(s)

Luz Frías with small edits by Carlos J. Gil Bellosta

References

INE's web service is mostly undocumented and the function has been built by reverse engineering API calls. However, users may want to check the capabilities of INEs WMS service at http://goo.gl/aKn3vj. Cadastre web service documentation can be consulted at http://goo.gl/lKkwK and WMS service capabilities at http://goo.gl/5JAd9N.

Examples

cartociudad_get_location_info(40.473219, -3.7227241)

Get a Cartociudad Map

Description

Downloads static maps using Cartociudad API. These maps can be then plotted by functions such as ggmap.

Usage

cartociudad_get_map(center, radius, add.censal.section = FALSE,
   add.postcode.area = FALSE, add.cadastral.layer = FALSE,
   height = 800, width = 1200)

Arguments

center

a pair of numbers (latitude and longitude of the center of the map)

radius

approximate map "width" in kilometers

add.censal.section

whether to add the limit of censal sections and districts to the base map; note that this layer may not be available at low zoom levels

add.postcode.area

whether to add the limit of postal code areas to the base map; note that this layer may not be available at low zoom levels

add.cadastral.layer

whether to add cadastral information

height

map height in pixels

width

map width in pixels

Details

This function, similar to get_googlemap or get_openstreetmap downloads a map from Cartociudad API and creates a ggmap compatible version of it.

Value

An object of class ggmap and raster which can be used within the ggmapframework.

Author(s)

Carlos J. Gil Bellosta

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

## Not run: 
  soria <- cartociudad_geocode("plaza de san esteban, soria")
  soria_map <- cartociudad_get_map(c(soria$lat, soria$lng), 1)
  ggmap::ggmap(soria_map)

## End(Not run)

Driving and walking directions from Cartociudad API

Description

Cartociudad API provides driving and walking routes between two points. This function quieries the API and provides the user the data in convenient form.

Usage

cartociudad_get_route(latlon.orig, latlon.dest, vehicle = "car")

Arguments

latlon.orig

Latitude and longitude of the starting point

latlon.dest

Latitude and longitude of the destination point

vehicle

Either car or walking

Value

A list containing the fields described in Cartociudad API documentation (see the link below).

Author(s)

Carlos J. Gil Bellosta

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

res <- cartociudad_get_route(c(39.48,-0.37),
   c(39.484336,-0.358171),
   vehicle = "car")

Reverse geocoding of locations

Description

Returns the address details of a geographical point in Spain.

Usage

cartociudad_reverse_geocode(latitude, longitude)

Arguments

latitude

Point latitude in geographical coordinates (e.g., 40.473219)

longitude

Point longitude in geographical coordinates (e.g., -3.7227241)

Details

This function performs reverse geocoding of a location. It returns the details of the closest address in Spain.

Value

A list with the following items:

tipo

type of location.

tipo.via

road type.

nombre.via

road name.

num.via

road number.

num.via.id

internal id of this address in cartociudad database.

municipio

town.

provincia

province.

cod.postal

zip code.

Author(s)

Luz Frias

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

cartociudad_reverse_geocode(40.473219, -3.7227241)

Area calculation

Description

Returns the polygon that describes the area

Usage

get_cartociudad_area(latitude, longitude, radius)

Arguments

latitude

Point latitude in geographical coordinates (e.g., 40.3930144)

longitude

Point longitude in geographical coordinates (e.g., -3.6596683)

radius

Distance in meters (e.g., 500)

Details

This function calculates the area given a point and a radius in meters

Value

A dataframe with the polygon that describes the area.

Author(s)

Luz Frias

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

## Not run: 
get_cartociudad_area(40.3930144, -3.6596683, 500)

## End(Not run)

Administrative information for a location

Description

Returns the administrative information related to a geographical point in Spain: province, municipality, censal district, censal section, cadastral reference and reverse geocoding data.

Usage

get_cartociudad_location_info(latitude, longitude, year = 2016,
  info.source = c("census", "cadastre", "reverse"))

Arguments

latitude

Point latitude in geographical coordinates (e.g., 40.473219)

longitude

Point longitude in geographical coordinates (e.g., -3.7227241)

year

Reference year; see Details section

info.source

A character vector specifying the APIs to consult. Possible values are "census", "cadastre" and "reverse"

Details

This function consults administrative information for a point within Spain. Censal information is consulted from a different set of layers, each one corresponding to a different year. Whereas provincial and municipal information is mostly stable, censal districts and sections may be subject to greater changes over the years.

Value

A list contaning the administrative information for the given point. For info.source = "census" it contains the province, municipality, censal discrict and censal section codes. For info.source = "cadastre" it contains the cadastral reference and the url to the spanish cadastre website. For info.source = "reverse" it contains the details of the address closest to the specified location, such us road type, number, zip code, street name, ... More information about reverse geocoding in cartociudad_reverse_geocode.

Author(s)

Luz Frías with small edits by Carlos J. Gil Bellosta

References

INE's web service is mostly undocumented and the function has been built by reverse engineering API calls. However, users may want to check the capabilities of INEs WMS service at http://goo.gl/aKn3vj. Cadastre web service documentation can be consulted at http://goo.gl/lKkwK and WMS service capabilities at http://goo.gl/5JAd9N.

Examples

## Not run: 
get_cartociudad_location_info(40.473219, -3.7227241)

## End(Not run)

Get a Cartociudad Map

Description

Downloads static maps using Cartociudad API. These maps can be then plotted by functions such as ggmap.

Usage

get_cartociudad_map(center, radius, add.censal.section = FALSE,
   add.postcode.area = FALSE, add.cadastral.layer = FALSE,
   height = 800, width = 1200)

Arguments

center

a pair of numbers (latitude and longitude of the center of the map)

radius

approximate map "width" in kilometers

add.censal.section

whether to add the limit of censal sections and districts to the base map; note that this layer may not be available at low zoom levels

add.postcode.area

whether to add the limit of postal code areas to the base map; note that this layer may not be available at low zoom levels

add.cadastral.layer

whether to add cadastral information

height

map height in pixels

width

map width in pixels

Details

This function, similar to get_googlemap or get_openstreetmap downloads a map from Cartociudad API and creates a ggmap compatible version of it.

Value

An object of class ggmap and raster which can be used within the ggmapframework.

Author(s)

Carlos J. Gil Bellosta

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

## Not run: 
  soria <- cartociudad_geocode("plaza de san esteban, soria")
  soria_map <- get_cartociudad_map(c(soria$lat, soria$lng), 1)
  ggmap::ggmap(soria_map)

## End(Not run)

Driving and walking directions from Cartociudad API

Description

Cartociudad API provides driving and walking routes between two points. This function quieries the API and provides the user the data in convenient form.

Usage

get_cartociudad_route(latlon.orig, latlon.dest, vehicle = "car")

Arguments

latlon.orig

Latitude and longitude of the starting point

latlon.dest

Latitude and longitude of the destination point

vehicle

Either car or walking

Value

A list containing the fields described in Cartociudad API documentation (see the link below).

Author(s)

Carlos J. Gil Bellosta

References

http://www.cartociudad.es/recursos/Documentacion_tecnica/CARTOCIUDAD_ServiciosWeb.pdf

Examples

## Not run: 
res <- get_cartociudad_route(c(39.48,-0.37),
   c(39.484336,-0.358171),
   vehicle = "car")

## End(Not run)