Title: | Coordinates to 'Plus Code' Conversion Tool |
---|---|
Description: | Generates 'Plus Code' of geometric objects or data frames that contain them, giving the possibility to specify the precision of the area. The main feature of the package comes from the open-source code developed by 'Google Inc.' present in the repository <https://github.com/google/open-location-code/blob/main/java/src/main/java/com/google/openlocationcode/OpenLocationCode.java>. For details about 'Plus Code', visit <https://maps.google.com/pluscodes/> or <https://github.com/google/open-location-code>. |
Authors: | Armando d'Aniello [aut, cre, cph], Google Inc. [cph] (© 2014 Google Inc. All rights reserved.) |
Maintainer: | Armando d'Aniello <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-27 02:44:58 UTC |
Source: | https://github.com/armando-d/pluscode2 |
Checks on the input object and any conversions:
- Check that the input object is of length 1, if it is not an error appears.
- Verifies that the input object is of the sfc (Simple Features Collection) class, if it is not, it returns NA and reports a warning.
- If the input object is of sfc class, checks that it is of type POINT, if it is not, the centroid of the geometric object is calculated.
- If the input object is of the sfc_POINT class, check that it has a reference system and that this is the WGS84 for the decimal coordinates; if it is not, it is set or converted.
checkAndConvert(x)
checkAndConvert(x)
x |
A generic object. |
An object of class sfc_POINT.
library(sf) checkAndConvert(0) ### polygon <- st_sfc(st_polygon(list(cbind(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0))))) checkAndConvert(polygon) ### point <- st_sfc(st_point(c(0, 0))) checkAndConvert(point)
library(sf) checkAndConvert(0) ### polygon <- st_sfc(st_polygon(list(cbind(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0))))) checkAndConvert(polygon) ### point <- st_sfc(st_point(c(0, 0))) checkAndConvert(point)
Calculates the latitude precision value for a given code length. Lengths <= 10 have the same precision for latitude and longitude, but lengths > 10 have different precisions due to the grid method having fewer columns than rows.
computeLatitudePrecision(codeLength)
computeLatitudePrecision(codeLength)
codeLength |
A number. |
A number.
computeLatitudePrecision(10) computeLatitudePrecision(12)
computeLatitudePrecision(10) computeLatitudePrecision(12)
Adapt the genPluscode function to a class object (sf, data.frame), it returns a vector containing the pluscode of the coordinates in the records of the input data frame.
dealWithDf(x, codeLength)
dealWithDf(x, codeLength)
x |
An object of class (sf, data.frame). |
codeLength |
A number. |
A character vector of length nrow(x).
library(sf) coordinates <- data.frame(lon = -6.56718, lat = 52.50145) geom_df <- st_as_sf(coordinates, coords = c("lon", "lat"), crs = 4326) dealWithDf(geom_df, 12) ### coordinates_df <- data.frame(lon = c(-6.56718, -6), lat = c(52.50145, 52)) geom_df <- st_as_sf(coordinates_df, coords = c("lon", "lat"), crs = 4326) dealWithDf(geom_df, 12)
library(sf) coordinates <- data.frame(lon = -6.56718, lat = 52.50145) geom_df <- st_as_sf(coordinates, coords = c("lon", "lat"), crs = 4326) dealWithDf(geom_df, 12) ### coordinates_df <- data.frame(lon = c(-6.56718, -6), lat = c(52.50145, 52)) geom_df <- st_as_sf(coordinates_df, coords = c("lon", "lat"), crs = 4326) dealWithDf(geom_df, 12)
Main function of the package. It generates a plus code giving as input a sfc object or a sf data.frame and a code length. Code length is related to the precision as dimension of the area. The precision of a plus code is indicated by the number of digits after the "+" sign. For example:
10 (2 digits after "+") -> area of 13.7 by 13.7 meters.
11 (3 digits after "+") -> area of 2.7 by 3.5 meters.
12 (4 digits after "+") -> area of 0.5 by 0.8 meters.
genPluscode(geom, codeLength = 10)
genPluscode(geom, codeLength = 10)
geom |
An object of class sfc or (sf, data.frame). |
codeLength |
An optional number between 4 and 15 exluding 5, 7, 9; default is 10. |
Depending on input it returns a character or an object of class (sf, data.frame).
library(sf) point <- st_sfc(st_point(c(0, 0))) genPluscode(point,10) ### coordinates_df <- data.frame(lon = c(-6.56718, -6), lat = c(52.50145, 52)) geom_df <- st_as_sf(coordinates_df, coords = c("lon", "lat"), crs = 4326) genPluscode(geom_df)
library(sf) point <- st_sfc(st_point(c(0, 0))) genPluscode(point,10) ### coordinates_df <- data.frame(lon = c(-6.56718, -6), lat = c(52.50145, 52)) geom_df <- st_as_sf(coordinates_df, coords = c("lon", "lat"), crs = 4326) genPluscode(geom_df)
Limit latitude within coherence range (-90, 90)
normalizeLatitude(latitude)
normalizeLatitude(latitude)
latitude |
A number. |
A number.
normalizeLatitude(80) normalizeLatitude(100)
normalizeLatitude(80) normalizeLatitude(100)
Limit longitude within coherence range (-180, 180)
normalizeLongitude(longitude)
normalizeLongitude(longitude)
longitude |
A number. |
A number.
normalizeLongitude(100) normalizeLongitude(181)
normalizeLongitude(100) normalizeLongitude(181)