df2sf {SUNGEO} | R Documentation |
Convert data.frame object into simple features object
Description
Function takes in x-, y-coordinates, and a data.frame of variables (optional) and returns an SFC object
Usage
df2sf(
x_coord,
y_coord,
input_data = NULL,
file = NULL,
n_max = Inf,
start = 0,
projection_input = "EPSG:4326",
zero.policy = FALSE,
show_removed = FALSE
)
Arguments
x_coord |
Numeric vector with longitude or easting projected coordinates. When |
y_coord |
Numeric vector with latitude or northing projected coordinates. Must be equal to the vector length of |
input_data |
Optional data frame object, containing |
file |
Optional path to csv file. Overrides |
n_max |
Maximum number of rows to read in |
start |
Number of rows to skip in |
projection_input |
Projection string associated with |
zero.policy |
If |
show_removed |
If |
Value
If show_removed==FALSE
, returns an sf
object, with rows corresponding to non-usable coordinates removed. If show_removed==TRUE
, returns a list, with an sf
object (Spatial_Coordinates
), and a vector of indices corresponding to non-usable coordinates removed (Removed_Rows
).
Examples
# Coordinates supplied as vectors
## Not run:
data(clea_deu2009_df)
out_1 <- df2sf(x_coord=clea_deu2009_df$longitude,y_coord = clea_deu2009_df$latitude)
class(out_1)
plot(out_1$geometry)
## End(Not run)
# Coordinates supplied as column mames
## Not run:
out_2 <- df2sf(x_coord="longitude",y_coord ="latitude", input_data = clea_deu2009_df)
plot(out_2["geometry"])
## End(Not run)
# Load from external file
## Not run:
tmp <- tempfile()
write.csv(clea_deu2009_df,file=tmp)
out_3 <- df2sf(x_coord="longitude",y_coord ="latitude", file=tmp)
plot(out_3["geometry"])
## End(Not run)