Reputation: 21
I have a data frame EuropeanCities
of latitude and longitude
Latitude Longitude
52.00529 4.173965
51.87938 6.268500
43.36661 -8.406812
Currently these values are of a numeric class however I need to set them to spatial coordinates for spatial data
How do I go about converting the class of these values using the sp
function?
Upvotes: 1
Views: 1064
Reputation: 56935
Just use SpatialPoints
from the sp
package..
mydf <- structure(list(Latitude = c(52.00529, 51.87938, 43.36661), Longitude = c(4.173965,
6.2685, -8.406812)), .Names = c("Latitude", "Longitude"), class = "data.frame", row.names = c(NA,
-3L))
library(sp)
SpatialPoints(mydf)
# SpatialPoints:
# Latitude Longitude
# [1,] 52.00529 4.173965
# [2,] 51.87938 6.268500
# [3,] 43.36661 -8.406812
# Coordinate Reference System (CRS) arguments: NA
(You can supply your own proj string and so on; see ?SpatialPoints
).
Upvotes: 0