Title: | Open Location Code Handling in R |
---|---|
Description: | 'Open Location Codes' (https://openlocationcode.com/) are a Google- created standard for identifying geographic locations. olctools provides utilities for validating, encoding and decoding entries that follow this standard. |
Authors: | Oliver Keyes |
Maintainer: | Oliver Keyes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.0 |
Built: | 2025-01-19 03:45:07 UTC |
Source: | https://github.com/ironholds/olctools |
decode_olc
takes Open Location Codes and, if they're
valid (see validate_full
) returns the minium, centred and maximum
latitude and longitude for those coordinates.
decode_olc(olcs)
decode_olc(olcs)
olcs |
a vector of Open Location Codes, generated through |
encode_olc
for the opposite operation, and shorten_olc
to convert
"full" Open Location Codes to "short" Open Location Codes.
decode_olc("7FG49Q00+")
decode_olc("7FG49Q00+")
encode_olc
creates Open Location Codes from
latitude and longitude values, of a specified length.
encode_olc(lats, longs, length)
encode_olc(lats, longs, length)
lats |
a numeric vector of latitudes. |
longs |
a numeric vector of longitudes, equivalent in size to |
length |
the length you want the resulting OLCs to be. The conventional lengths
are 10 or 11, with any number above 8 and any even number below it being acceptable. |
decode_olc
for the opposite operation, and shorten_olc
to convert
"full" Open Location Codes to "short" Open Location Codes.
encode_olc(20.375, 2.775,6)
encode_olc(20.375, 2.775,6)
Open Location Codes are a Google-created standard for identifying geographic locations. olctools provides utilities for validating, encoding and decoding entries that follow this standard.
shorten_olc
(and other sources) shorten a code, reducing
the space it occupies. They also limit its ability to be translated back into latitude/longitude
pairs. recover_olc
recovers a full code from a shortened one, allowing it to be decoded with
decode_olc
. Some loss of accuracy or precision is expected - and as it finds
the closest match to the coordinates rather than to the original code, the characters may be very
different.
recover_olc(olcs, lats, longs)
recover_olc(olcs, lats, longs)
olcs |
a vector of short open location codes, generated with |
lats |
a numeric vector of latitudes. |
longs |
a numeric vector of longitudes, equivalent in size to |
# Shorten an OLC and then recover the nearest full code. Note the actual characters differ. shortened_code <- shorten_olc("8FVC9G8F+6X", 47.5, 8.5); recovered_code <- recover_olc(shortened_code, 47.4, 8.6);
# Shorten an OLC and then recover the nearest full code. Note the actual characters differ. shortened_code <- shorten_olc("8FVC9G8F+6X", 47.5, 8.5); recovered_code <- recover_olc(shortened_code, 47.4, 8.6);
One of the things that makes OLCs useful is that they can shortened - you can trim
characters off them, saving space without substantially compromising the accuracy. shorten_olc
takes full-length OLCs (generated with encode_olc
or any other way) and shortens them.
shorten_olc(olcs, lats, longs)
shorten_olc(olcs, lats, longs)
olcs |
a vector of open location codes, generated with |
lats |
a numeric vector of latitudes. |
longs |
a numeric vector of longitudes, equivalent in size to |
encode_olc
to create full Open Location Codes.
#Encode an OLC and then shorten it olc <- encode_olc(51.3708675,-1.217765625, 12) validate_full(olc) # [1] TRUE olc <- shorten_olc(olc, 51.3708675,-1.217765625) validate_short(olc) # [1] TRUE
#Encode an OLC and then shorten it olc <- encode_olc(51.3708675,-1.217765625, 12) validate_full(olc) # [1] TRUE olc <- shorten_olc(olc, 51.3708675,-1.217765625) validate_short(olc) # [1] TRUE
These functions allow a useR to check whether OLCs they've
been provided are valid or not. valid_short
identifies whether
a vector of OLCs are valid "short" codes; valid_long
identifies
whether OLCs are valid "long" codes, and valid_full
identifies
whether OLCs are valid, full stop.
validate_olc(codes) validate_short(codes) validate_full(codes)
validate_olc(codes) validate_short(codes) validate_full(codes)
codes |
a character vector containing Open Location Codes. |
a vector of TRUE and FALSE values, where TRUE corresponds to a valid code and FALSE an invalid.
decode_olc
and encode_olc
for creating
and resolving valid Open Location Codes.
#Validate that a particular OLC is valid validate_olc("WC2345+G6g") #[1] TRUE #It is! Is it a short? validate_short("WC2345+G6g") #[1] TRUE #Yep! #So it's not full? validate_full("WC2345+G6g") #[1] FALSE #Nope!
#Validate that a particular OLC is valid validate_olc("WC2345+G6g") #[1] TRUE #It is! Is it a short? validate_short("WC2345+G6g") #[1] TRUE #Yep! #So it's not full? validate_full("WC2345+G6g") #[1] FALSE #Nope!