2

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.

1 Answer 1

5

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.

3
  • Thank you ! I even corrected the name of package - sorry, I didn't verified it..
    – maycca
    Aug 5, 2015 at 23:26
  • it is really great and helpful to obtain advise/information from the person much more familiar with R and its functions ;)
    – maycca
    Aug 6, 2015 at 0:09
  • i would like to raise the difference I am getting with gIntersection and raster::intersection: When intersecting a large feature with many small ones (some overlap), the former handles polygon holes while the latter does not.
    – Sam
    Feb 20, 2017 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.