SymbolixAU / googlePolylines

R package for encoding objects using Google's Polyline Encoding Algorithm
Other
16 stars 6 forks source link

Decode to sf / constructing sfencoded #41

Open Zedseayou opened 5 years ago

Zedseayou commented 5 years ago

Thanks for this cool package! I currently have a use case where I get given a long vector of polylines, and I'm wondering whether it makes sense to have one of:

  1. A version or option for decode that produces an sf object instead of requiring the user to convert the list of dataframes themselves.
  2. A constructor for sfencoded that does the work of creating an encoded column and sets class so that polyline_wkt %>% st_as_sf can be used.

Both of these are certainly convenience functions. I can try a PR in the next few days once I read over the code a bit also.

SymbolixAU commented 5 years ago

Number 1 is certainly feasible and I think will just mean attaching sfc attributes here.

We can also add functionality so a data.frame of polylines gets decoded into an sf object.

Example data to work with

polylines <- c(
  "ohlbDnbmhN~suq@am{tAw`qsAeyhGvkz`@fge}A",
  "ggmnDt}wmLgc`DesuQvvrLofdDorqGtzzV"
)

## option to convert to `sfc`
decode(polylines)

df <- data.frame(
  id = 1:2
  , pl = polylines
)

## this will then get converted to `sf`
# decode(df)

For Number 2 are you after

df <- data.frame(
  geom = "POINT(0 1)"
)

sf::st_as_sf(df, wkt = "geom")