geocode | R Documentation |
Geocodes Finnish place names or street addresses using the National Land Survey of Finland (NLS) geocoding REST API. This function converts textual location descriptions into spatial coordinates.
geocode(
search_string,
source = "interpolated-road-addresses",
crs = 3067,
lang = "fi",
size = NULL,
options = NULL,
api_key = getOption("geofi_mml_api_key")
)
search_string |
Character. The place name or street address to geocode
(e.g., |
source |
Character. The data source to search in. Must be one of:
|
crs |
Character. The coordinate reference system (CRS) for the
output data, specified as an EPSG code. Must be one of |
lang |
Character. The language for the API response labels. Must be one of
|
size |
Numeric or NULL. The maximum number of results to return. Must be a
positive integer. If |
options |
Character or NULL. Additional options to pass to the API, specified
as a single string (e.g., |
api_key |
Character. API key for authenticating with the NLS geocoding API.
Defaults to the value stored in |
This function uses the NLS geocoding REST API to convert place names or street addresses into spatial coordinates. It supports multiple data sources, including interpolated road addresses, geographic names, and cadastral units. The function includes robust error handling:
Retries failed requests up to 3 times for transient network issues.
Handles HTTP errors and rate limits (HTTP 429).
Validates inputs to prevent common errors.
An sf
object containing the geocoded locations as points in the
specified crs
. If no results are found, a warning is issued, and
an empty sf
object is returned.
Markus Kainu markus.kainu@kapsi.fi
geocode_reverse
for reverse geocoding.
https://www.maanmittauslaitos.fi/en/rajapinnat/api-avaimen-ohje for
instructions on obtaining an API key.
https://www.maanmittauslaitos.fi/kartat-ja-paikkatieto/aineistot-ja-rajapinnat/paikkatietojen-rajapintapalvelut/geokoodauspalvelu
for more information on the NLS geocoding API.
## Not run:
# Set your API key
options(geofi_mml_api_key = "your_api_key_here")
# Geocode a place name
locations <- geocode(search_string = "Suomenlinna", source = "geographic-names")
print(locations)
# Geocode a street address with a custom size and output CRS
addresses <- geocode(
search_string = "Mannerheimintie 100, Helsinki",
source = "addresses",
crs = "EPSG:4326",
size = 5
)
print(addresses)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.