I would like to do a true GIS Clip in R of soils polygons using a series of single boundary polygons, but I cannot find an R function to properly do it. It should work just like the clip
function in ESRI's ArcMap. I've tried the over
method in sp
package but it doesn't seem to work for polys over polys.
One suggestion was to use the gIntersection
in rgeos
package as a clip using the following code:
#------------------------------------
library(rgeos)
library(maptools)
#Read layers as SpatialPolygonsDataFrame (both the same Albers projection)
Soils_poly = readShapePoly("Soils_polygons") #Note - Has 400 polygons
clipper_poly = readShapePoly("clipper_polygon") #Note - Has 1 polygon
#Try gintersection as clip
Clipped_polys = gIntersection(Clipper_Tile_poly, Soils_poly)
#-----------------------------------
This takes 5 minutes to run (way too slow) and errors with this:
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_not_poly, "rgeos_intersection") : TopologyException: no outgoing dirEdge found at -721459.77681285271 2009506.5980877089
I also tried this code to check for overlap:
gIntersects(Clipper_Tile_poly, Soils_poly)
and the result was TRUE. clip
function in ESRI ArcMap works fine for this data.
Anyone knows of an R function to properly do a clip on spatial polygons using spatial polygons?