Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created October 27, 2016 00:51
Show Gist options
  • Save mdsumner/e081c0f843e4ba8a005351641bd256fa to your computer and use it in GitHub Desktop.
Save mdsumner/e081c0f843e4ba8a005351641bd256fa to your computer and use it in GitHub Desktop.
```{r}
library(rgdal)
data(meuse)
listcoords <- lapply(split(meuse, meuse$landuse), function(x) cbind(x$x, x$y))
spmdf <- SpatialMultiPointsDataFrame(listcoords, data.frame(name = names(listcoords), count = sapply(listcoords, nrow), stringsAsFactors = FALSE))
proj4string(spmdf ) <- CRS("+init=epsg:28992")
## there are 15 features with differing numbers of coordinates each
#plot(spmdf, col = viridis::viridis(length(spmdf)))
writeOGR(spmdf, ".", "spmdf", "ESRI Shapefile")
## or for the righteous and good
#writeOGR(spmdf, "spmdf.gpkg", "spmdf", "GPKG")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment