df2sf | R Documentation |
While the SpatialFeatureExperiment
constructor and *Geometry
replacement methods can convert properly formatted ordinary data frames into
sf
objects which are used to store the geometries internally, the user
might want to do the conversion, check if the geometry is valid, and inspect
and fix any invalid geometries.
df2sf(
df,
spatialCoordsNames = c("x", "y"),
spotDiameter = NA,
geometryType = c("POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING",
"MULTIPOLYGON"),
BPPARAM = SerialParam()
)
df |
An ordinary data frame, i.e. not |
spatialCoordsNames |
Column names in |
spotDiameter |
Spot diameter for technologies with arrays of spots of fixed diameter per slide, such as Visium, ST, DBiT-seq, and slide-seq. The diameter must be in the same unit as the coordinates in the *Geometry arguments. Ignored for geometries that are not POINT or MULTIPOINT. |
geometryType |
Type of geometry to convert the ordinary data frame to.
If the geometry in |
BPPARAM |
An optional |
An sf
object.
# Points, use spotDiameter to convert to circle polygons
# This is done to Visium spots
pts_df <- readRDS(system.file("extdata/pts_df.rds",
package = "SpatialFeatureExperiment"
))
sf_use <- df2sf(pts_df, geometryType = "POINT", spotDiameter = 0.1)
# Linestring
ls_df <- readRDS(system.file("extdata/ls_df.rds",
package = "SpatialFeatureExperiment"
))
sf_use <- df2sf(ls_df, geometryType = "LINESTRING")
# Polygon
pol_df <- readRDS(system.file("extdata/pol_df.rds",
package = "SpatialFeatureExperiment"
))
sf_use <- df2sf(pol_df,
geometryType = "POLYGON",
spatialCoordsNames = c("V1", "V2")
)
# Multipolygon
mpol_df <- readRDS(system.file("extdata/mpol_df.rds",
package = "SpatialFeatureExperiment"
))
sf_use <- df2sf(mpol_df,
geometryType = "MULTIPOLYGON",
spatialCoordsNames = c("V1", "V2")
)
# Multiple sample_ids present
multipts_df <- readRDS(system.file("extdata/multipts_df.rds",
package = "SpatialFeatureExperiment"
))
sf_use <- df2sf(multipts_df, geometryType = "MULTIPOINT")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.