[GIS] Difference between intersect {raster} and gIntersection {rgeos} in polygons – R

intersectionoverlapping-featurespolygonrshapefile

I am interested in knowing the difference between tools: intersect {raster} and gIntersection {rgeos}** tools in R. I have several overlapping polygons and I am interested in their overlap, but mostly in spatially merging their attribute tables. From my resulting shp splitted in multiple polygons, I want to calculate area of each of polygons using gArea {rgeos}.

Are there any pitfalls I should be aware of? For both intersection processes and for subsequent areas calculation?

For the moment I found intersect{raster} more satisfactory for my purpose as it keep "SpatialPolygonsDataFrame" (SPDF) and even merge polygons data.frames. However many online helps propose instead gIntersection {rgeos} which produces just "SpatialPolygons" not even "SPDF". There is not really difference in computation time.

Best Answer

There is no real difference other than the class of the returned object. The raster intersect function is a helper function that, for polygons, calls gIntersection from rgeos (not rgdal). I would recommend using raster's intersect functions because it will save you some steps in getting back to a SpatialPolygonsDataFrame object. One good way to explore these types of questions is to download the package source code and look at how it is structured and what it is doing.