Geometry Relationships - Equality
Function for testing equivalence of the given geometries
gEquals(spgeom1, spgeom2 = NULL, byid = FALSE, returnDense=TRUE, checkValidity=FALSE) gEqualsExact(spgeom1, spgeom2 = NULL, tol=0.0, byid = FALSE, returnDense=TRUE, checkValidity=FALSE)
spgeom1, spgeom2 |
sp objects as defined in package sp. If spgeom2 is NULL then spgeom1 is compared to itself. |
byid |
Logical vector determining if the function should be applied across ids (TRUE) or the entire object (FALSE) for spgeom1 and spgeom2 |
tol |
Numerical value of tolerance to use when assessing equivalence |
returnDense |
default TRUE, if false returns a list of the length of spgeom1 of integer vectors listing the |
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, |
gEquals
returns TRUE if geometries are "spatially equivalent" which requires that spgeom1
is within spgeom2
and spgeom2
is within spgeom1
, this ignores ordering of points within the geometries. Note that it is possible for geometries with different coordinates to be "spatially equivalent".
gEqualsExact
returns TRUE if geometries are "exactly equivalent" which requires that spgeom1
and spgeom1
are "spatially equivalent" and that their constituent points are in the same order.
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
# p1 and p2 are spatially identical but not exactly identical due to point ordering p1=readWKT("POLYGON((0 0,1 0,1 1,0 1,0 0))") p2=readWKT("POLYGON((1 1,0 1,0 0,1 0,1 1))") p3=readWKT("POLYGON((0.01 0.01,1.01 0.01,1.01 1.01,0.01 1.01,0.01 0.01))") gEquals(p1,p2) gEquals(p1,p3) gEqualsExact(p1,p2) gEqualsExact(p1,p3,tol=0) gEqualsExact(p1,p3,tol=0.1) # pt1 and p2t are spatially identical but not exactly identical due to point ordering pt1 = readWKT("MULTIPOINT(1 1,2 2,3 3)") pt2 = readWKT("MULTIPOINT(3 3,2 2,1 1)") pt3 = readWKT("MULTIPOINT(1.01 1.01,2.01 2.01,3.01 3.01)") gEquals(pt1,pt2) gEquals(pt1,pt3) gEqualsExact(pt1,pt2) gEqualsExact(pt1,pt3,tol=0) gEqualsExact(pt1,pt3,tol=0.1) # l2 contains a point that l1 does not l1 = readWKT("LINESTRING (10 10, 20 20)") l2 = readWKT("LINESTRING (10 10, 15 15,20 20)") gEquals(l1,l2) gEqualsExact(l1,l2)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.