topo-unary-gEnvelope.Rd
Function calculates the rectangular bounding box for the given geometry
gEnvelope(spgeom, byid=FALSE, id = NULL)
sp object as defined in package sp
Logical determining if the function should be applied across subgeometries (TRUE) or the entire object (FALSE)
Character vector defining id labels for the resulting geometries, if unspecified returned geometries will be labeled based on their parent geometries' labels.
Returns the rectangular bounding box as a SpatialPolygons object. If spgeom is a degenerate case (horizontal/vertical line, single point) then the function may return an object with lower dimension (SpatialLines or SpatialPoints) or an invalid polygon.
x = readWKT(paste("POLYGON((0 40,10 50,0 60,40 60,40 100,50 90,60 100,60",
"60,100 60,90 50,100 40,60 40,60 0,50 10,40 0,40 40,0 40))"))
env = gEnvelope(x)
plot(x,col='blue',border='blue')
plot(env,add=TRUE)
#Degenerate Cases
gEnvelope(readWKT("POINT(1 1)")) #returns SpatialPoints
#> SpatialPoints:
#> x y
#> 1 1 1
#> Coordinate Reference System (CRS) arguments: NA
gEnvelope(readWKT("LINESTRING(1 1,1 2)")) #invalid polygon
#> An object of class "SpatialPolygons"
#> Slot "polygons":
#> [[1]]
#> An object of class "Polygons"
#> Slot "Polygons":
#> [[1]]
#> An object of class "Polygon"
#> Slot "labpt":
#> [1] 1.0 1.5
#>
#> Slot "area":
#> [1] 0
#>
#> Slot "hole":
#> [1] FALSE
#>
#> Slot "ringDir":
#> [1] 1
#>
#> Slot "coords":
#> x y
#> [1,] 1 1
#> [2,] 1 2
#> [3,] 1 2
#> [4,] 1 1
#> [5,] 1 1
#>
#>
#>
#> Slot "plotOrder":
#> [1] 1
#>
#> Slot "labpt":
#> [1] 1.0 1.5
#>
#> Slot "ID":
#> [1] "1"
#>
#> Slot "area":
#> [1] 0
#>
#>
#>
#> Slot "plotOrder":
#> [1] 1
#>
#> Slot "bbox":
#> min max
#> x 1 1
#> y 1 2
#>
#> Slot "proj4string":
#> Coordinate Reference System:
#> Deprecated Proj.4 representation: NA
#>
gEnvelope(readWKT("LINESTRING(1 1,2 1)")) #invalid polygon
#> An object of class "SpatialPolygons"
#> Slot "polygons":
#> [[1]]
#> An object of class "Polygons"
#> Slot "Polygons":
#> [[1]]
#> An object of class "Polygon"
#> Slot "labpt":
#> [1] 1.5 1.0
#>
#> Slot "area":
#> [1] 0
#>
#> Slot "hole":
#> [1] FALSE
#>
#> Slot "ringDir":
#> [1] 1
#>
#> Slot "coords":
#> x y
#> [1,] 1 1
#> [2,] 1 1
#> [3,] 2 1
#> [4,] 2 1
#> [5,] 1 1
#>
#>
#>
#> Slot "plotOrder":
#> [1] 1
#>
#> Slot "labpt":
#> [1] 1.5 1.0
#>
#> Slot "ID":
#> [1] "1"
#>
#> Slot "area":
#> [1] 0
#>
#>
#>
#> Slot "plotOrder":
#> [1] 1
#>
#> Slot "bbox":
#> min max
#> x 1 2
#> y 1 1
#>
#> Slot "proj4string":
#> Coordinate Reference System:
#> Deprecated Proj.4 representation: NA
#>