This is a basic question but unfortunately I could not find the relevant command elsewhere.
Is there a way i can convert a Spatial Points Dataframe to an ordinary dataframe in R.
e.g. if the ordinary dataframe is df
with Lat, Lon as location coordinates I can obtain a spatial df as:
coordinates (df)= ~Lat + Lon
How is the reverse possible or is it even possible ?
as.data.frame()
does just what you are looking for:
library(sp)
# Construct a SpatialPointsDataFrame
data(meuse)
xy <- meuse[1:2]
df <- meuse[-1:-2]
SPDF <- SpatialPointsDataFrame(coords=xy, data=df)
# And then convert it (back) to a data.frame
DF <- as.data.frame(SPDF)