Package 'gridpin'

Title: Offline Geocoding with One File per Country
Description: Geocodes addresses and reverse-geocodes coordinates on the local machine, without a server, an API key or a network request per address. Each country is one memory-mapped file built from Overture Maps and open address registers, downloaded once and verified against the release checksums. Answers carry their precision (house, street, city) and a confidence score, so uncertain matches can be checked before use.
Authors: GridPin [aut, cre, cph], Authors of the dependency Rust crates [aut, cph] (see inst/AUTHORS)
Maintainer: GridPin <[email protected]>
License: Apache License (== 2.0)
Version: 0.6.0
Built: 2026-10-31 21:12:23 UTC
Source: https://github.com/gridpin/gridpin

Help Index


Close a geocoder and unmap its sheet

Description

Close a geocoder and unmap its sheet

Usage

gp_close(geocoder)

Arguments

geocoder

A geocoder from [gp_open()].


Download a sheet and verify it

Description

Fetches the sheet of the GridPin release this package was built for, checks its size and SHA-256 against the values pinned in the package, and only then moves it into [gp_home()]. A sheet that is already there is not fetched again. This is the only function that uses the network; set 'GRIDPIN_OFFLINE=1' to forbid it.

Usage

gp_download(country)

Arguments

country

A country code or name from [gp_sheets()].

Value

The path of the sheet, invisibly.


Geocode addresses offline

Description

Every address is matched on your machine against the sheet; nothing is sent anywhere.

Usage

gp_geocode(x, sheet, k = 1, sf = FALSE)

Arguments

x

A character vector of addresses. 'NA' gives a row without coordinates.

sheet

A geocoder from [gp_open()], a country code, or a path to a sheet.

k

How many candidates to return per address. With 'k = 1' the result has one row per address, in input order; with more, one row per candidate and 'rank' numbers them.

sf

Return an 'sf' object with WGS84 points (needs the sf package).

Value

A data frame with 'query', 'rank', 'lat', 'lon', 'precision' ('house', 'interp', 'near', 'street', 'city'), 'confidence', 'weak' ('TRUE' when the answer is too uncertain to use without a check), the matched 'housenumber', 'street', 'postcode', 'commune', and 'flags'. Addresses that are not found keep their row with 'NA' coordinates.

Examples

g <- gp_open(system.file("extdata", "tiny.bin", package = "gridpin"))
gp_geocode(c("3 Main Street, Springfield", "Nowhere 99"), g)

Add coordinates to a data frame column of addresses

Description

Add coordinates to a data frame column of addresses

Usage

gp_geocode_df(df, column, sheet, sf = FALSE)

Arguments

df

A data frame.

column

Name of the column with the address text.

sheet

A geocoder from [gp_open()], a country code, or a path to a sheet.

sf

Return an 'sf' object with WGS84 points (needs the sf package).

Value

'df' with the columns of [gp_geocode()] prefixed 'gp_' (except 'query' and 'rank').


Directory for downloaded sheets

Description

'GRIDPIN_HOME' if set, otherwise the user cache directory for R packages ([tools::R_user_dir()]). Sheets already downloaded by the Python package 'gridpin-mcp' ('~/.cache/gridpin') are found and used without a second download.

Usage

gp_home()

Open a GridPin sheet

Description

Loads a country sheet into memory (the file is memory-mapped, so opening is fast and several R sessions share the pages). Opening the same file again returns the same geocoder.

Usage

gp_open(sheet)

Arguments

sheet

A country code or name from [gp_sheets()] (the sheet must be downloaded, see [gp_download()]) or the path to a '.bin' sheet file.

Value

An object of class 'gridpin_geocoder'.

Examples

g <- gp_open(system.file("extdata", "tiny.bin", package = "gridpin"))
gp_geocode("3 Main Street, Springfield", g)

Reverse geocode: the nearest indexed address to each point

Description

Reverse geocode: the nearest indexed address to each point

Usage

gp_reverse(lat, lon, sheet, k = 1)

Arguments

lat, lon

Numeric vectors of WGS84 coordinates of the same length.

sheet

A geocoder from [gp_open()], a country code, or a path to a sheet.

k

How many candidates to return per address. With 'k = 1' the result has one row per address, in input order; with more, one row per candidate and 'rank' numbers them.

Value

A data frame like [gp_geocode()] with 'distance_m', the distance from the point to the answer. Streets are indexed by their centre, so check 'distance_m' before treating the answer as the building at the point.


SHA-256 of a file

Description

Uses [tools::sha256sum()] (R 4.5 and newer) or, on older R, the digest package.

Usage

gp_sha256(path)

Arguments

path

Path to a file.

Value

Lower-case hexadecimal digest.


Path of a downloaded sheet

Description

Path of a downloaded sheet

Usage

gp_sheet_path(country)

Arguments

country

A country code or name from [gp_sheets()].


Available sheets and whether they are downloaded

Description

Available sheets and whether they are downloaded

Usage

gp_sheets()

Value

A data frame: 'code', 'country', 'size_mb', 'downloaded', 'path'.

Examples

gp_sheets()

Versions, for the methods section of your study

Description

Versions, for the methods section of your study

Usage

gp_version(sheet = NULL)

Arguments

sheet

Optional: a geocoder or sheet, to report its file and size.

Value

A named list: package version, C interface version, sheet release, and the sheet file.