0

I am able to take a spatialPolygonDataFrame and turn it into a dataframe, but how do I undo this conversion? Ie take a data.frame and convert it back to the original spatialPolygonDataFram:

Example taken from: https://github.com/tidyverse/ggplot2/wiki/plotting-polygon-shapefiles

  utah = readOGR(dsn=".", layer="eco_l3_ut") ## class(utah) SpatialPolygonsDataFrame
  utah@data$id = rownames(utah@data)
  utah.points = fortify(utah, region="id")
  utah.df = join(utah.points, utah@data, by="id")

How can I take utah.df and make it identical to utah again?

Rafael
  • 3,096
  • 1
  • 23
  • 61
  • 1
    Since you've tagged this with `sf`, would you have any interest in making it an `sf` object? That way, you likely wouldn't need to really change much since it natively handles both data and geometry together. Also looks like [this post](https://stackoverflow.com/q/19025898/5325862) is very similar – camille Mar 19 '20 at 14:47
  • the end goal is to be able to pass utah to `maps::SpatialPolygons2map(utah, ...)` if I can do that with `sf` that's fantastic. – Rafael Mar 19 '20 at 14:50
  • 1
    The wiki you linked to says it's outdated and to use the main docs site instead. And in the time since then, they've added a `geom_sf` that's designed to plot `sf` objects if that's part of your end goal – camille Mar 19 '20 at 14:55

0 Answers0