pred-binary-gEquals.Rd
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)
sp objects as defined in package sp. If spgeom2 is NULL then spgeom1 is compared to itself.
Logical vector determining if the function should be applied across ids (TRUE) or the entire object (FALSE) for spgeom1 and spgeom2
Numerical value of tolerance to use when assessing equivalence
default TRUE, if false returns a list of the length of spgeom1 of integer vectors listing the 1:length(spgeom2)
indices which would be TRUE in the dense logical matrix representation; useful when the sizes of the byid=TRUE returned matrix is very large and it is sparse; essential when the returned matrix would be too large
default FALSE; error meesages from GEOS do not say clearly which object fails if a topology exception is encountered. If this argument is TRUE, gIsValid
is run on each in turn in an environment in which object names are available. If objects are invalid, this is reported and those affected are named
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.
# 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)
#> [1] TRUE
gEquals(p1,p3)
#> [1] FALSE
gEqualsExact(p1,p2)
#> [1] FALSE
gEqualsExact(p1,p3,tol=0)
#> [1] FALSE
gEqualsExact(p1,p3,tol=0.1)
#> [1] TRUE
# 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)
#> [1] TRUE
gEquals(pt1,pt3)
#> [1] FALSE
gEqualsExact(pt1,pt2)
#> [1] FALSE
gEqualsExact(pt1,pt3,tol=0)
#> [1] FALSE
gEqualsExact(pt1,pt3,tol=0.1)
#> [1] TRUE
# 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)
#> [1] TRUE
gEqualsExact(l1,l2)
#> [1] FALSE