Function for determining the difference between the two given geometries.

1 2 |

`spgeom1, spgeom2` |
sp objects as defined in package sp |

`byid` |
Logical vector determining if the function should be applied across ids (TRUE) or the entire object (FALSE) for spgeom1 and spgeom2 |

`id` |
Character vector defining id labels for the resulting geometries, if unspecified returned geometries will be labeled based on their parent geometries' labels. |

`drop_lower_td` |
default FALSE; if TRUE, objects will be dropped from output GEOMETRYCOLLECTION objects to simplify output if their topological dinension is less than the minimum topological dinension of the input objects. |

`unaryUnion_if_byid_false` |
default TRUE; if |

`checkValidity` |
default FALSE; error meesages from GEOS do not say clearly which object fails if a topology exception is encountered. If this argument is TRUE, |

Returns the regions of spgeom1 that are not within spgeom2. If the geometries do not intersect then the result is just spgeom1. Note that the function is not symmetric for spgeom1 and spgeom2.

Error messages from GEOS, in particular topology exceptions, report 0-based object order, so geom 0 is spgeom1, and geom 1 is spgeom2.

Roger Bivand & Colin Rundel

`gIntersection`

`gSymdifference`

`gUnion`

1 2 3 4 5 6 7 8 | ```
x = readWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))")
y = readWKT("POLYGON ((3 3, 7 3, 7 7, 3 7, 3 3))")
d = gDifference(x,y)
plot(d,col='red',pbg='white')
# Empty geometry since y is completely contained with x
d2 = gDifference(y,x)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.