sp_from_data_frame: Function to promoting a data frame to a...

View source: R/sp_from_data_frame.R

sp_from_data_frameR Documentation

Function to promoting a data frame to a SpatialPointsDataFrame, SpatialLinesDataFrame, or SpatialPolygonsDataFrame.

Description

Function to promoting a data frame to a SpatialPointsDataFrame, SpatialLinesDataFrame, or SpatialPolygonsDataFrame.

Usage

sp_from_data_frame(
  df,
  type,
  latitude = "latitude",
  longitude = "longitude",
  projection = projection_wgs84(),
  keep = FALSE,
  id = NA
)

Arguments

df

Data frame to be converted into spatial data frame.

type

Type of geomerty. Type must be one of "points", "lines", or "polygons" and there is no default.

latitude

df's latitude variable name.

longitude

df's longitude variable name.

projection

df's latitude and longitude projection system. Default is WGS84.

keep

For when type is "points", should latitude and longitude be kept in the SpatialPointsDataFrame's data slot?

id

Variable in df which codes for spatial object's id. This is used when a data frame contains many seperate geometries. id is not used for points because each point is a seperate geometry.

Value

A SpatialPointsDataFrame, SpatialLinesDataFrame, or SpatialPolygonsDataFrame.

Author(s)

Stuart K. Grange

Examples

## Not run: 

# Promote to different geometry types
# Points
sp_points <- sp_from_data_frame(data_drawn, type = "points")

# Lines
sp_lines <- sp_from_data_frame(data_drawn, type = "lines")
# Lines with seperate geometries
sp_lines <- sp_from_data_frame(data_drawn, type = "lines", id = "name")

# Polygons
sp_polygons <- sp_from_data_frame(data_drawn, type = "polygons")
# Polygons with seperate geometries
sp_polygons <- sp_from_data_frame(data_drawn, type = "polygons", id = "name")


## End(Not run)


MohoWu/ricardor documentation built on March 24, 2022, 4:39 p.m.