Rgeos drops associated values when intersecting polygons

The behaviour of gIntersection is not to pass any intersected data by design:

Since there are no general matches between intersected spatial objects, any arbitrary operations on attributes require assumptions about unknown user intentions. This is why no data slots should be passed through ...

... The design of gIntesection() is inentional, because only the user can know what to do with attributes of entities that have their geometries changed. Different users may make different assumptions, but there is no general solution beyond passing through the IDs of the intersecting geometries, as is done in the row.names() mechanism.

To my surprise, the raster package has a intersection function, which simply intersects and hands over the data as well.

The raster package has a few functions that extend rgeos by also attempting to handle attribute data as well. In this case, see raster::intersect And the list of functions here: ?"raster-package" (section XIV)

The complete info I got on this: http://r-sig-geo.2731867.n2.nabble.com/Intended-usage-of-gIntersection-td7587120.html


For some project i had the same need. Much more than keeping the data.frame, we had to put in place further code to manage output geometry type, and proceed to some cleaning (e.g. clean geometry collections), to have some complete intersection geoprocess. In case you still need to do such a task in R, you can try the RFigisGeo package:

#install RFigisGeo
require(devtools) 
install_github("RFigisGeo", "openfigis")
require(RFigisGeo)

#compute intersection
result <- getIntersection(features1, features2)