Guest User

Untitled

a guest
Dec 14th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #loading required packages
  2. require(sp)
  3. require(rgdal)
  4. require(maptools)
  5. require(rgeos)
  6.  
  7. #load example data, set "dsn=" to your working directory or specify the path
  8. example <- readOGR(dsn=".",layer="ReproducibleExample")
  9.  
  10. #Attempting a UnionSpatialPolygons based on the COUNTY field
  11. example.df <- as(example, "data.frame")
  12. countycol <- example.df$COUNTY
  13. example.diss <- unionSpatialPolygons(example, countycol)
  14.  
  15. slot(example, "polygons") <- lapply(slot(example, "polygons"), checkPolygonsHoles)
  16.  
  17. fix <- slot(example, "polygons")
  18. fixa <- lapply(fix, checkPolygonsHoles)
  19.  
  20. require(devtools)
  21. install_github("eblondel/cleangeo")
  22. require(cleangeo)
  23.  
  24. #get a report of geometry validity & issues for a sp spatial object
  25. report <- clgeo_CollectionReport(sp)
  26. summary <- clgeo_SummaryReport(report)
  27. issues <- report[report$valid == FALSE,]
  28.  
  29. #get suspicious features (indexes)
  30. nv <- clgeo_SuspiciousFeatures(report)
  31. mysp <- sp[nv[-14],]
  32.  
  33. #try to clean data
  34. mysp.clean <- clgeo_Clean(mysp, print.log = TRUE)
  35.  
  36. #check if they are still errors
  37. report.clean <- clgeo_CollectionReport(mysp.clean)
  38. summary.clean <- clgeo_SummaryReport(report.clean)
  39.  
  40. #try to clean data
  41. mysp <- sp[-9002,]
  42. mysp.clean <- clgeo_Clean(mysp, print.log = TRUE)
  43.  
  44. #check if they are still errors
  45. report.clean <- clgeo_CollectionReport(mysp.clean)
  46. summary.clean <- clgeo_SummaryReport(report.clean)
  47.  
  48. #Attempting a UnionSpatialPolygons based on the COUNTY field
  49. mysp.df <- as(mysp, "data.frame")
  50. countycol <- mysp.df$COUNTY
  51. mysp.diss <- unionSpatialPolygons(mysp.clean, countycol)
  52.  
  53. require(maptools)
  54. mysp <- readShapePoly("ReproducibleExample.shp")
  55.  
  56. #plot the result
  57. plot(mysp, border= "lightgray")
  58. plot(mysp.diss, border="red", add = TRUE)
Add Comment
Please, Sign In to add comment