Created
July 1, 2024 12:28
-
-
Save PietrH/7a21af67fbffd848eb54bb5c48b7717a to your computer and use it in GitHub Desktop.
Round coordinates in WKT strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
round_coordinates <- function(wkt_string, digits = 4) { | |
wkt_object_type <- wkt_string %>% | |
stringr::str_extract(".*?(?=\\()") | |
x_coord <- wkt_string %>% | |
stringr::str_extract("(?<=POINT\\()[0-9]+\\.[0-9]+") %>% | |
as.numeric() | |
y_coord <- wkt_string %>% | |
stringr::str_extract("[0-9]+\\.[0-9]+(?=\\))") %>% | |
as.numeric() | |
x_rounded <- round(x_coord, digits = digits) | |
y_rounded <- round(y_coord, digits = digits) | |
glue::glue("{wkt_object_type}({x_rounded} {y_rounded})") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment