Cumulative deprecated functions and methods from rgeos prior to package retirement/archiving during 2023.

gBuffer(spgeom, byid=FALSE, id=NULL, width=1.0, quadsegs=5, capStyle="ROUND",
 joinStyle="ROUND", mitreLimit=1.0)
gDifference(spgeom1, spgeom2, byid=FALSE, id=NULL, drop_lower_td=FALSE,
 unaryUnion_if_byid_false=TRUE, checkValidity=NULL)
gSymdifference(spgeom1, spgeom2, byid=FALSE, id=NULL, drop_lower_td=FALSE,
 unaryUnion_if_byid_false=TRUE, checkValidity=NULL)
gIntersection(spgeom1, spgeom2, byid=FALSE, id=NULL, drop_not_poly,
 drop_lower_td=FALSE, unaryUnion_if_byid_false=TRUE, checkValidity=NULL)
gUnion(spgeom1, spgeom2, byid=FALSE, id=NULL, drop_lower_td=FALSE,
 unaryUnion_if_byid_false=TRUE, checkValidity=NULL)

Arguments

spgeom

sp object as defined in package sp

byid

Logical determining if the function should be applied across subgeometries (TRUE) or the entire object (FALSE)

id

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

width

Distance from original geometry to include in the new geometry. Negative values are allowed. Either a numeric vector of length 1 when byid is FALSE; if byid is TRUE: of length 1 replicated to the number of input geometries, or of length equal to the number of input geometries

quadsegs

Number of line segments to use to approximate a quarter circle.

capStyle

Style of cap to use at the ends of the geometry. Allowed values: ROUND,FLAT,SQUARE

joinStyle

Style to use for joints in the geometry. Allowed values: ROUND,MITRE,BEVEL

mitreLimit

Numerical value that specifies how far a joint can extend if a mitre join style is used.

spgeom1, spgeom2

sp objects as defined in package sp

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 byid takes a FALSE in either position, the subgeometries are combined first to avoid possible topology exceptions (change in 0.3-13, previous behaviour did not combine subgeometries, and may be achieved by setting this argument FALSE

checkValidity

default NULL, integer 0L (no action), 1L (check), 2L (check and try to buffer by zero distance to repair). If NULL, a value set to 0L for GEOS < 3.7.2, 1L for GEOS >= 3.7.2 is read from values assigned on load. Error meesages from GEOS do not say clearly which object fails if a topology exception is encountered. If this argument is > 0L, gIsValid is run on each in turn

drop_not_poly

deprecated argument, use drop_lower_td

Examples

p1 = readWKT("POLYGON((0 1,0.95 0.31,0.59 -0.81,-0.59 -0.81,-0.95 0.31,0 1))")
p2 = readWKT("POLYGON((2 2,-2 2,-2 -2,2 -2,2 2),(1 1,-1 1,-1 -1,1 -1,1 1))")

par(mfrow=c(2,3))
plot(gBuffer(p1,width=-0.2),col='black',xlim=c(-1.5,1.5),ylim=c(-1.5,1.5))
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(p1,border='blue',lwd=2,add=TRUE);title("width: -0.2")
plot(gBuffer(p1,width=0),col='black',xlim=c(-1.5,1.5),ylim=c(-1.5,1.5))
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(p1,border='blue',lwd=2,add=TRUE);title("width: 0")
plot(gBuffer(p1,width=0.2),col='black',xlim=c(-1.5,1.5),ylim=c(-1.5,1.5))
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(p1,border='blue',lwd=2,add=TRUE);title("width: 0.2")

plot(gBuffer(p2,width=-0.2),col='black',pbg='white',xlim=c(-2.5,2.5),ylim=c(-2.5,2.5))
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(p2,border='blue',lwd=2,add=TRUE);title("width: -0.2")
plot(gBuffer(p2,width=0),col='black',pbg='white',xlim=c(-2.5,2.5),ylim=c(-2.5,2.5))
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(p2,border='blue',lwd=2,add=TRUE);title("width: 0")
plot(gBuffer(p2,width=0.2),col='black',pbg='white',xlim=c(-2.5,2.5),ylim=c(-2.5,2.5))
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(p2,border='blue',lwd=2,add=TRUE);title("width: 0.2")


p3 <- readWKT(paste("GEOMETRYCOLLECTION(",
 "POLYGON((0 1,0.95 0.31,0.59 -0.81,-0.59 -0.81,-0.95 0.31,0 1)),",
 "POLYGON((2 2,-2 2,-2 -2,2 -2,2 2),(1 1,-1 1,-1 -1,1 -1,1 1)))"))

par(mfrow=c(1,1))
plot(gBuffer(p3, byid=TRUE, width=c(-0.2, -0.1)),col='black',pbg='white',
xlim=c(-2.5,2.5),ylim=c(-2.5,2.5))
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(p3,border=c('blue', 'red'),lwd=2,add=TRUE);title("width: -0.2, -0.1")

library(sp)
p3df <- SpatialPolygonsDataFrame(p3, data=data.frame(i=1:length(p3),
 row.names=row.names(p3)))
dim(p3df)
#> [1] 2 1
row.names(p3df)
#> [1] "1" "2"
dropEmpty = gBuffer(p3df, byid=TRUE, id=letters[1:nrow(p3df)], width=c(-1, 0))
#> Warning: GEOS support is provided by the sf and terra packages among others
dim(dropEmpty)
#> [1] 1 1
row.names(dropEmpty)
#> [1] "b"
row.names(slot(dropEmpty, "data"))
#> [1] "b"
plot(dropEmpty, col='black', pbg='white', xlim=c(-2.5,2.5),ylim=c(-2.5,2.5))
plot(p3df,border=c('blue'),lwd=2,add=TRUE);title("width: -1, 0")

par(mfrow=c(2,3))


#Style options
l1 = readWKT("LINESTRING(0 0,1 5,4 5,5 2,8 2,9 4,4 6.5)")
par(mfrow=c(2,3))
plot(gBuffer(l1,capStyle="ROUND"));plot(l1,col='blue',add=TRUE);title("capStyle: ROUND")
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(gBuffer(l1,capStyle="FLAT"));plot(l1,col='blue',add=TRUE);title("capStyle: FLAT")
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(gBuffer(l1,capStyle="SQUARE"));plot(l1,col='blue',add=TRUE);title("capStyle: SQUARE")
#> Warning: GEOS support is provided by the sf and terra packages among others

plot(gBuffer(l1,quadsegs=1));plot(l1,col='blue',add=TRUE);title("quadsegs: 1")
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(gBuffer(l1,quadsegs=2));plot(l1,col='blue',add=TRUE);title("quadsegs: 2")
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(gBuffer(l1,quadsegs=5));plot(l1,col='blue',add=TRUE);title("quadsegs: 5")
#> Warning: GEOS support is provided by the sf and terra packages among others




l2 = readWKT("LINESTRING(0 0,1 5,3 2)")
par(mfrow=c(2,3))
plot(gBuffer(l2,joinStyle="ROUND"));plot(l2,col='blue',add=TRUE);title("joinStyle: ROUND")
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(gBuffer(l2,joinStyle="MITRE"));plot(l2,col='blue',add=TRUE);title("joinStyle: MITRE")
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(gBuffer(l2,joinStyle="BEVEL"));plot(l2,col='blue',add=TRUE);title("joinStyle: BEVEL")
#> Warning: GEOS support is provided by the sf and terra packages among others

plot(gBuffer(l2,joinStyle="MITRE",mitreLimit=0.5));plot(l2,col='blue',add=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
 title("mitreLimit: 0.5")
plot(gBuffer(l2,joinStyle="MITRE",mitreLimit=1));plot(l2,col='blue',add=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
 title("mitreLimit: 1")
plot(gBuffer(l2,joinStyle="MITRE",mitreLimit=3));plot(l2,col='blue',add=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
 title("mitreLimit: 3")

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)
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(d,col='red',pbg='white')

# Empty geometry since y is completely contained with x
d2 = gDifference(y,x)
#> Warning: GEOS support is provided by the sf and terra packages among others
pol <- readWKT(paste("POLYGON((-180 -20, -140 55, 10 0, -140 -60, -180 -20),",
 "(-150 -20, -100 -10, -110 20, -150 -20))"))
library(sp)
GT <- GridTopology(c(-175, -85), c(10, 10), c(36, 18))
gr <- as(as(SpatialGrid(GT), "SpatialPixels"), "SpatialPolygons")
try(res <- gIntersection(pol, gr, byid=TRUE))
#> Warning: GEOS support is provided by the sf and terra packages among others
#> output subgeometry 88, row.name: 1 g365
#> subsubgeometry 0: Polygon
#> subsubgeometry 1: Point
#> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false,  : 
#>   Geometry collections may not contain other geometry collections
res <- gIntersection(pol, gr, byid=TRUE, drop_lower_td=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
# Robert Hijmans difficult intersection case
load(system.file("test_cases/polys.RData", package="rgeos"))
try(res <- gIntersection(a, b, byid=TRUE))
#> Warning: GEOS support is provided by the sf and terra packages among others
#> output subgeometry 1, row.name: 109 294
#> subsubgeometry 0: Polygon
#> subsubgeometry 1: Polygon
#> subsubgeometry 2: LineString
#> Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false,  : 
#>   Geometry collections may not contain other geometry collections
res <- gIntersection(a, b, byid=TRUE, drop_lower_td=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
unlist(sapply(slot(res, "polygons"), function(p) sapply(slot(p, "Polygons"), slot, "area")))
#>  [1] 1.700212e+06 3.135474e-08 9.982584e-07 2.087862e-06 1.434509e-06
#>  [6] 3.926317e-07 5.350546e-07 7.269743e+06 3.117775e+05 1.212778e+03
#> [11] 1.424050e+06
# example from Pius Korner 2015-10-25
poly1 <- SpatialPolygons(list(Polygons(list(Polygon(coords=matrix(c(0, 0, 2, 2, 0, 1, 1, 0),
 ncol=2, byrow=FALSE))), ID=c("a")), Polygons(list(Polygon(coords=matrix(c(0, 0, 2, 2, 2, 3, 3, 2),
 ncol=2, byrow=FALSE))), ID=c("b"))))
poly2 <- SpatialPolygons(list(Polygons(list(Polygon(coords=matrix(c(0, 0, 2, 2,
 1, 1, 1, 3, 3, 0, 0, 2), ncol=2, byrow=FALSE))), ID=c("c"))))
plot(poly1, border="orange")
plot(poly2, border="blue", add=TRUE, lty=2, density=8, angle=30, col="blue")
gI <- gIntersection(poly1, poly2, byid=TRUE, drop_lower_td=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(gI, add=TRUE, border="red", lwd=3)
oT <- get_RGEOS_polyThreshold()
oW <- get_RGEOS_warnSlivers()
oD <- get_RGEOS_dropSlivers()
set_RGEOS_polyThreshold(1e-3)
set_RGEOS_warnSlivers(TRUE)
res1 <- gIntersection(a, b, byid=TRUE, drop_lower_td=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
#> Warning: 1: MultiPolygon object 109 294 area 1.02961e-06
#> Warning: 2: MultiPolygon object 202 294 area 3.915e-06
#> Warning: 3: Polygon object 208 294 area 5.35055e-07
#> Warning: Exterior ring 0 of object 109 294 area 3.13547e-08
#> Warning: Exterior ring 1 of object 109 294 area 9.98258e-07
#> Warning: Exterior ring 0 of object 202 294 area 2.08786e-06
#> Warning: Exterior ring 1 of object 202 294 area 1.43451e-06
#> Warning: Exterior ring 2 of object 202 294 area 3.92632e-07
#> Warning: Exterior ring 0 of object 208 294 area 5.35055e-07
unlist(sapply(slot(res1, "polygons"), function(p) sapply(slot(p, "Polygons"), slot, "area")))
#>  [1] 1.700212e+06 3.135474e-08 9.982584e-07 2.087862e-06 1.434509e-06
#>  [6] 3.926317e-07 5.350546e-07 7.269743e+06 3.117775e+05 1.212778e+03
#> [11] 1.424050e+06
set_RGEOS_dropSlivers(TRUE)
res2 <- gIntersection(a, b, byid=TRUE, drop_lower_td=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
#> Warning: 1: MultiPolygon object 109 294 area 1.02961e-06
#> Warning: 2: MultiPolygon object 202 294 area 3.915e-06
#> Warning: 3: Polygon object 208 294 area 5.35055e-07
unlist(sapply(slot(res2, "polygons"), function(p) sapply(slot(p, "Polygons"), slot, "area")))
#> [1] 1700211.935 7269743.131  311777.515    1212.778 1424050.306
set_RGEOS_dropSlivers(FALSE)
oo <- gUnaryUnion(res1, c(rep("1", 3), "2", "3", "4"), checkValidity=2L)
#> Warning: Too few points in geometry component at or near point 3001878.09776633 2416352.9858511998
#> Warning: Too few points in geometry component at or near point 3000956.1033775401 2413481.790976
#> Warning: Too few points in geometry component at or near point 3000956.1033775401 2413481.790976
#> res1 is invalid
#> Warning: GEOS support is provided by the sf and terra packages among others
#> Warning: 1: Polygon object 109 294 area 9.67871e-07
#> Warning: 2: Polygon object 202 294 area 2.02431e-06
#> Warning: Exterior ring 0 of object 109 294 area 9.67871e-07
#> Warning: Exterior ring 0 of object 202 294 area 2.02431e-06
#> Attempting to make res1 valid by zero-width buffering
#> Warning: Exterior ring 1 of object 1 area 2.99218e-06
unlist(sapply(slot(oo, "polygons"), function(p) sapply(slot(p, "Polygons"), slot, "area")))
#> [1] 1.700212e+06 2.992178e-06 7.269743e+06 3.117775e+05 1.212778e+03
#> [6] 1.424050e+06
ooo <- gIntersection(b, oo, byid=TRUE, checkValidity=2L)
#> Warning: GEOS support is provided by the sf and terra packages among others
#> Warning: spgeom1 and spgeom2 have different proj4 strings
#> Warning: Exterior ring 1 of object 294 1 area 2.99216e-06
gArea(ooo, byid=TRUE)
#>     294 1     294 2     294 3     294 4 
#> 1700211.9 7269743.1  312990.3 1424050.3 
unlist(sapply(slot(ooo, "polygons"), function(p) sapply(slot(p, "Polygons"), slot, "area")))
#> [1] 1.700212e+06 2.992165e-06 7.269743e+06 3.117775e+05 1.212778e+03
#> [6] 1.424050e+06
set_RGEOS_dropSlivers(TRUE)
ooo <- gIntersection(b, oo, byid=TRUE, checkValidity=2L)
#> Warning: GEOS support is provided by the sf and terra packages among others
#> Warning: spgeom1 and spgeom2 have different proj4 strings
#> Warning: Exterior ring 1 of object 294 1 area 2.99216e-06
gArea(ooo, byid=TRUE)
#>     294 1     294 2     294 3     294 4 
#> 1700211.9 7269743.1  312990.3 1424050.3 
unlist(sapply(slot(ooo, "polygons"), function(p) sapply(slot(p, "Polygons"), slot, "area")))
#> [1] 1700211.935 7269743.131  311777.515    1212.778 1424050.306
set_RGEOS_polyThreshold(oT)
set_RGEOS_warnSlivers(oW)
set_RGEOS_dropSlivers(oD)
# see thread https://stat.ethz.ch/pipermail/r-sig-geo/2015-September/023468.html
Pol1=rbind(c(0,0),c(0,10),c(10,10),c(10,0),c(0,0))
Pol2=rbind(c(0,0),c(10,0),c(10,-10),c(0,-10),c(0,0))
library(sp)
Pols1=Polygons(list(Polygon(Pol1)),"Pols1")
Pols2=Polygons(list(Polygon(Pol2)),"Pols2")
MyLay=SpatialPolygons(list(Pols1,Pols2))
Pol1l=Pol1+0.5
Pol2l=Pol2+0.5
Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l")
Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l")
MyLayl=SpatialPolygons(list(Pols1l,Pols2l))
inter=gIntersection(MyLay, MyLayl)
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(MyLay)
plot(MyLayl,add=TRUE)
plot(inter, add=TRUE, border="green")
try(gIntersection(MyLay, MyLayl, unaryUnion_if_byid_false=FALSE))
#> Warning: GEOS support is provided by the sf and terra packages among others
#> An object of class "SpatialPolygons"
#> Slot "polygons":
#> [[1]]
#> An object of class "Polygons"
#> Slot "Polygons":
#> [[1]]
#> An object of class "Polygon"
#> Slot "labpt":
#> [1] 5.25 0.25
#> 
#> Slot "area":
#> [1] 185.25
#> 
#> Slot "hole":
#> [1] FALSE
#> 
#> Slot "ringDir":
#> [1] 1
#> 
#> Slot "coords":
#>          x    y
#>  [1,] 10.0 10.0
#>  [2,] 10.0  0.5
#>  [3,] 10.0  0.0
#>  [4,] 10.0 -9.5
#>  [5,]  0.5 -9.5
#>  [6,]  0.5  0.0
#>  [7,]  0.5  0.5
#>  [8,]  0.5 10.0
#>  [9,] 10.0 10.0
#> 
#> 
#> 
#> Slot "plotOrder":
#> [1] 1
#> 
#> Slot "labpt":
#> [1] 5.25 0.25
#> 
#> Slot "ID":
#> [1] "1"
#> 
#> Slot "area":
#> [1] 185.25
#> 
#> 
#> 
#> Slot "plotOrder":
#> [1] 1
#> 
#> Slot "bbox":
#>    min max
#> x  0.5  10
#> y -9.5  10
#> 
#> Slot "proj4string":
#> Coordinate Reference System:
#> Deprecated Proj.4 representation: NA 
#> 
Pol1=rbind(c(0,0),c(0,1),c(1,1),c(1,0),c(0,0))
Pol2=rbind(c(0,0),c(1,0),c(1,-1),c(0,-1),c(0,0))
Pols1=Polygons(list(Polygon(Pol1)),"Pols1")
Pols2=Polygons(list(Polygon(Pol2)),"Pols2")
MyLay=SpatialPolygons(list(Pols1,Pols2))
Pol1l=Pol1+0.1
Pol2l=Pol2+0.1
Pols1l=Polygons(list(Polygon(Pol1l)),"Pols1l")
Pols2l=Polygons(list(Polygon(Pol2l)),"Pols2l")
MyLayl=SpatialPolygons(list(Pols1l,Pols2l))
inter=gIntersection(MyLay, MyLayl, unaryUnion_if_byid_false=FALSE)
#> Warning: GEOS support is provided by the sf and terra packages among others
gEquals(inter, MyLay)
#> [1] FALSE
inter1=gIntersection(MyLay, MyLayl, unaryUnion_if_byid_false=TRUE)
#> Warning: GEOS support is provided by the sf and terra packages among others
gEquals(inter1, MyLay)
#> [1] FALSE
gEquals(inter, inter1)
#> [1] TRUE
plot(MyLay, ylim=c(-1, 1.1))
plot(MyLayl, add=TRUE)
plot(inter, angle=45, density=10, add=TRUE)
plot(inter1, angle=135, density=10, add=TRUE)
inter2=gIntersection(MyLay, MyLayl)
#> Warning: GEOS support is provided by the sf and terra packages among others
gEquals(inter2, MyLay)
#> [1] FALSE
gEquals(inter1, inter2)
#> [1] TRUE
x = readWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))")
y = readWKT("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))")

d = gSymdifference(x,y)
#> Warning: GEOS support is provided by the sf and terra packages among others
plot(d,col='red',pbg='white')