Sunday, 8 December 2019

r - Creating new shapefile after merge operation using unionSpatialPolygons


I only recently started playing with shapefiles and R packages for manipulating them. I am looking at creating a new shapefile based on merged polyons by following this example, however, I cannot seem to figure out what I am suppose to feed the as.data.frame("youData").


Using the Zambia shapefiles as an example, how would one go about creating a new shapefile composed of a superset district-level data?


require(maptools)
require(rgadl)

zambia <- readShapeSpatial("ZMB_adm2.shp")
zambiap <- unionSpatialPolygons(zambia, ID=zambia@data$ID_1)


zambiapd <- SpatialPolygonsDataFrame(ob,data=as.data.frame("yourData"),proj4string=CRS("+proj= aea > +ellps=GRS80 +datum=WGS84"))
writeOGR(zambiapd,"shapes","testShape",driver="ESRI Shapefile",)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...