I am trying to intersect two SpatialPolygonsDataFrames and get a SpatialPolygonsDataFrame as the result. Unfortunately, using the gIntersection
function from rgeos
(which works impressively quickly to intersect the polygons), I cannot seem to retrieve the associated dataframes. Consider the following example:
> fracPoly <- gIntersection( toSingle, fromSingle )
> class(toSingle)
[1] "SpatialPolygonsDataFrame"
> class(fromSingle)
[1] "SpatialPolygonsDataFrame"
> class(fracPoly)
[1] "SpatialPolygons"
I can write a wrapper function which handles the transfer of data.frames
, but it will be a minor pain to get all the checking right and before I did I was hoping someone could either confirm that there's no better way or point me towards another function (or option for gIntersection
) which would allow me to retain the associated data.frames
.
Update
On further reflection, this may may be very deliberate behavior by gIntersection
. After all, of the two SPDFs, whose data.frame do you pass along? So I may have to write a wrapper which merges the two.