Skip to content
Prev 28985 / 29559 Next

df with embedded wkt lists to sf

Hey Tim,

The key thing here is to separate the long / lat points into elements in a
vector. You can do this with a string split. Afterwards, separate these
into their own rows like I've done below.

I think this should get you on the right path!


dat <- dget(textConnection(txtString))

dat |>
  tidyr::unnest(c(longitude, latitude)) |>
  dplyr::mutate(longitude = strsplit(longitude, "; "),
                latitude = strsplit(latitude, "; ")) |>
  tidyr::unnest(c(longitude, latitude)) |>
  sf::st_as_sf(coords = c(2, 3), crs = 4326)

On Thu, Jun 9, 2022 at 3:48 PM Howard, Tim G (DEC) via R-sig-Geo <
r-sig-geo at r-project.org> wrote:

            

  
  
Message-ID: <CAL3ufU+Uzwu6C2Qb537rw=qhy7jUkSE7r=amXsx=N4z07jQiGg@mail.gmail.com>
In-Reply-To: <SA1PR09MB77928623770FE8533E634261A8A79@SA1PR09MB7792.namprd09.prod.outlook.com>