1DF2SpatialPointsDataFrame <- structure(function#change data.frame to SpatialPointsDataFrame 2### This function modifies an object of class data.frame to one of class SpatialPointsDataFrame 3( x, ##<< data frame to be converted 4 coords = c("x", "y"),##<< which columns are coordinates 5 crs = sp::CRS("+init=epsg:28992") ##<< projection scheme 6){ 7 #require(sp) 8 sp::coordinates(x) <- ~x+y #c("x", "y") 9 sp::proj4string(x) <- crs; 10 return(x) 11### the new object of class SpatialPointsDataFrame 12} , ex = function(){ 13 if (requireNamespace("sp", quietly = TRUE)) { 14 data("meuse", package = "sp", envir = environment()) 15 meuseSP = DF2SpatialPointsDataFrame(meuse) 16 17 sp::plot(meuseSP, asp = 1, cex = 4 * meuse$zinc/max(meuse$zinc), 18 pch = 1, col = as.numeric(meuse$ffreq)+1 ) 19 data("meuse.riv", package = "sp", envir = environment()) 20 lines(meuse.riv) 21 } else { 22 print("package sp must be installed for this example") 23 } 24 25 26}) 27