spatialwidget icon indicating copy to clipboard operation
spatialwidget copied to clipboard

aggregate functions for data.frames with ID columns

Open SymbolixAU opened this issue 6 years ago • 1 comments

for example, googleway can accept lines denoted with an 'id' value.

df <- data.frame(myId = c(1,1,1,1,1,1,2,2,2),
      lineId = c(1,1,1,2,2,2,1,1,1),
      lat = c(26.774, 18.466, 32.321, 28.745, 29.570, 27.339, 22, 23, 22),
      lon = c(-80.190, -66.118, -64.757, -70.579, -67.514, -66.668, -50, -49, -51),
      colour = c(rep("#00FF0F", 6), rep("#FF00FF", 3)),
      stringsAsFactors = FALSE)

SymbolixAU avatar May 20 '19 21:05 SymbolixAU

Can use sfheaders for this

sf <- sfheaders::sf_polygon(df, x = "lon", y = "lat", polygon_id = "myId", linestring_id = "lineId")
sf <- merge(
  x = sf
  , y = unique( df[, c("myId", "colour")] )
  , by.x = "id"
  , by.y = "myId"
)

SymbolixAU avatar Sep 25 '19 22:09 SymbolixAU