Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a spatial dataframe back to normal dataframe?

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 ?

like image 733
user2760 Avatar asked Feb 17 '12 18:02

user2760


1 Answers

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)
like image 195
Josh O'Brien Avatar answered Nov 01 '22 01:11

Josh O'Brien