| Title: | Geocode Place Names via Nominatim |
|---|---|
| Description: | A minimal interface to the Nominatim geocoding API (OpenStreetMap). Converts place name strings to coordinates and returns structured results. Designed to be used by other packages that need lightweight geocoding. |
| Authors: | Michael Sumner [aut, cre] |
| Maintainer: | Michael Sumner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9001.9001 |
| Built: | 2026-06-05 07:21:08 UTC |
| Source: | https://github.com/hypertidy/location |
Queries the Nominatim geocoding API (OpenStreetMap) to look up coordinates for one or more place name strings. Returns a data frame with one row per input.
loc( x, limit = 1L, full = FALSE, api_url = "https://nominatim.openstreetmap.org" )loc( x, limit = 1L, full = FALSE, api_url = "https://nominatim.openstreetmap.org" )
x |
character vector of place names, e.g. |
limit |
integer. Maximum number of results to return per query. Usually 1 is what you want. The Nominatim API caps this at 50. |
full |
logical. If |
api_url |
base URL for the Nominatim API. Override to use a local
instance: |
Results are cached for the duration of the R session, so repeated calls
with the same query string are free. The cache can be inspected with
loc_cache_show() and cleared with loc_cache_clear().
Nominatim's usage policy requires a descriptive User-Agent and a maximum
rate of one request per second. loc() enforces the rate limit automatically
and warns if the service is being queried heavily. See
https://operations.osmfoundation.org/policies/nominatim/.
A data frame with columns:
longitude (numeric, or NA if not found)
latitude (numeric, or NA if not found)
full place name as returned by Nominatim
the original input string
OSM object type: "node", "way", or "relation"
When full = TRUE, all additional Nominatim fields are included as
list-columns.
## Not run: loc("Hobart") loc("Jackson, TN") loc(c("Davis Station", "Casey Station", "Mawson Station")) # repeated calls hit the cache, not Nominatim loc("Hobart") # inspect what's been cached this session loc_cache_show() ## End(Not run)## Not run: loc("Hobart") loc("Jackson, TN") loc(c("Davis Station", "Casey Station", "Mawson Station")) # repeated calls hit the cache, not Nominatim loc("Hobart") # inspect what's been cached this session loc_cache_show() ## End(Not run)
loc() caches results within the R session so repeated queries don't hit
Nominatim again. Call this if you need fresh results, e.g. after updating
your query strings.
loc_cache_clear()loc_cache_clear()
invisibly NULL
Show the session cache
loc_cache_show()loc_cache_show()
a data frame of all cached results, or an empty data frame if the cache is empty.
A convenience wrapper that geocodes a place name with loc() and then
looks up the IANA timezone via the lutz package.
loc_tz(x, method = "fast", ...)loc_tz(x, method = "fast", ...)
x |
character vector of place names. |
method |
passed to |
... |
passed to |
A character vector of IANA timezone names (e.g.
"America/Chicago"), the same length as x. NA where geocoding or
timezone lookup failed.
## Not run: loc_tz("Jackson, TN") loc_tz("Davis Station, Antarctica") loc_tz(c("Hobart", "McMurdo")) ## End(Not run)## Not run: loc_tz("Jackson, TN") loc_tz("Davis Station, Antarctica") loc_tz(c("Hobart", "McMurdo")) ## End(Not run)