[GIS] Convert csv file to shapefile in R

rrgdalshapefile

Below is so far I've done to convert .csv file into shapefile

Mydata <- read.csv("londonburglary201402.csv", header = T, sep = ",")
class(Mydata)
coordinates(Mydata) <- ~Longitude + Latitude
class(Mydata)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"

but I don't know how to write the shapefile with projection.
I am trying to use rgdal packages to do.

Best Answer

Easiest is probably with the raster package:

require(raster)
projection(Mydata) = "+init=espg:4326" # WGS84 coords
shapefile(Mydata, "Mydata.shp")

But with sp and rgdal:

proj4string(Mydata) = CRS("+init=epsg:4326")
writeOGR(Mydata, ".","Mydata", "ESRI Shapefile")

The "." is the current directory, and "Mydata" is the root name of the files that make up the shapefile.