Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #loading required packages
- require(sp)
- require(rgdal)
- require(maptools)
- require(rgeos)
- #load example data, set "dsn=" to your working directory or specify the path
- example <- readOGR(dsn=".",layer="ReproducibleExample")
- #Attempting a UnionSpatialPolygons based on the COUNTY field
- example.df <- as(example, "data.frame")
- countycol <- example.df$COUNTY
- example.diss <- unionSpatialPolygons(example, countycol)
- slot(example, "polygons") <- lapply(slot(example, "polygons"), checkPolygonsHoles)
- fix <- slot(example, "polygons")
- fixa <- lapply(fix, checkPolygonsHoles)
- require(devtools)
- install_github("eblondel/cleangeo")
- require(cleangeo)
- #get a report of geometry validity & issues for a sp spatial object
- report <- clgeo_CollectionReport(sp)
- summary <- clgeo_SummaryReport(report)
- issues <- report[report$valid == FALSE,]
- #get suspicious features (indexes)
- nv <- clgeo_SuspiciousFeatures(report)
- mysp <- sp[nv[-14],]
- #try to clean data
- mysp.clean <- clgeo_Clean(mysp, print.log = TRUE)
- #check if they are still errors
- report.clean <- clgeo_CollectionReport(mysp.clean)
- summary.clean <- clgeo_SummaryReport(report.clean)
- #try to clean data
- mysp <- sp[-9002,]
- mysp.clean <- clgeo_Clean(mysp, print.log = TRUE)
- #check if they are still errors
- report.clean <- clgeo_CollectionReport(mysp.clean)
- summary.clean <- clgeo_SummaryReport(report.clean)
- #Attempting a UnionSpatialPolygons based on the COUNTY field
- mysp.df <- as(mysp, "data.frame")
- countycol <- mysp.df$COUNTY
- mysp.diss <- unionSpatialPolygons(mysp.clean, countycol)
- require(maptools)
- mysp <- readShapePoly("ReproducibleExample.shp")
- #plot the result
- plot(mysp, border= "lightgray")
- plot(mysp.diss, border="red", add = TRUE)
Add Comment
Please, Sign In to add comment