geometry retrieves the SpatialXxx object from a SpatialXxxDataFrame object,
with Xxx Lines, Points, Polygons, Grid, or Pixels. geometry<- converts a
data.frame into a Spatial object.
geometry(obj)
geometry(obj) <- value
Arguments
- obj
in case of assignment, a data.frame, else an object of class Spatial
- value
object of class Spatial
Methods
- obj = "Spatial"
- obj = "SpatialPointsDataFrame"
- obj = "SpatialMultiPointsDataFrame"
- obj = "SpatialPolygonsDataFrame"
- obj = "SpatialPixelsDataFrame"
- obj = "SpatialGridDataFrame"
- obj = "SpatialLinesDataFrame"
Examples
data(meuse)
m = meuse
coordinates(m) = meuse[, c("x", "y")]
pts = geometry(m)
class(pts)
#> [1] "SpatialPoints"
#> attr(,"package")
#> [1] "sp"
geometry(meuse) = pts
class(meuse)
#> [1] "SpatialPointsDataFrame"
#> attr(,"package")
#> [1] "sp"
identical(m, meuse) # TRUE
#> [1] TRUE