@@ -400,12 +400,26 @@ EASIN_Process <- function(
400400
401401 # # Extract coordinates from WKT string ----
402402 IASDT.R :: CatTime(" Extract coordinates from WKT string" , Level = 1 )
403+
403404 WKTs <- dplyr :: distinct(EASIN_Data , WKT ) %> %
404- dplyr :: mutate(Coords = purrr :: map(WKT , IASDT.R :: Text2Coords )) %> %
405- tidyr :: unnest_wider(Coords ) %> %
406405 dplyr :: mutate(
407- dplyr :: across(
408- .cols = c(" Longitude" , " Latitude" ), .fns = ~ round(.x , 5 )))
406+ Points = purrr :: map(
407+ .x = WKT ,
408+ .f = ~ {
409+ # Extract POINT coordinates from WKT string
410+ Points <- stringr :: str_extract_all(
411+ .x , " POINT\\ s*\\ (\\ s*-?\\ d+\\ .\\ d+\\ s+-?\\ d+\\ .\\ d+\\ s*\\ )" )[[1 ]]
412+
413+ if (length(Points ) > 0 ) {
414+ purrr :: map(Points , IASDT.R :: Text2Coords ) %> %
415+ dplyr :: bind_rows() %> %
416+ dplyr :: mutate(
417+ dplyr :: across(
418+ .cols = c(" Longitude" , " Latitude" ), .fns = ~ round(.x , 5 )))
419+ } else {
420+ tibble :: tibble(Longitude = NA_real_ , Latitude = NA_real_ )
421+ }
422+ }))
409423
410424 # # Add coordinates to data and convert to sf ----
411425 IASDT.R :: CatTime(" Add coordinates to data and convert to sf" , Level = 1 )
@@ -416,6 +430,8 @@ EASIN_Process <- function(
416430 dplyr :: pull(" CellCode" )
417431
418432 EASIN_Data <- dplyr :: left_join(EASIN_Data , WKTs , by = " WKT" ) %> %
433+ tidyr :: unnest(Points ) %> %
434+ dplyr :: filter(! is.na(Longitude ) & ! is.na(Latitude )) %> %
419435 # convert to sf object, while keeping original coordinates as columns
420436 sf :: st_as_sf(
421437 coords = c(" Longitude" , " Latitude" ), crs = 4326 , remove = FALSE ) %> %
0 commit comments