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

Description Usage Arguments Value Author(s) Examples

View source: R/sp_from_data_frame.R

Description

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

Usage

1
2
3
4
5
6
7
8
9
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## 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 6, 2021, 4:17 p.m.