How to convert csv to shp in R

旧时模样 提交于 2019-12-04 17:24:10

I would suggest using rgdal rather than shapefiles. In order to use rgdal, you'll have to check out the system requirements from http://cran.revolutionanalytics.com/web/packages/rgdal/.

The following code should get you in the right direction:

install.packages(c("rgdal", "sp"))
library(rgdal)
library(sp)
MyData <- read.csv(file="c:/TheDataIWantToReadIn.csv", header=TRUE, sep=",")

The following code snippet comes from Mapping in R using the ggplot2 package.

class(MyData) # data.frame
coordinates(MyData)<-~longitude+latitude # whatever the equivalent is in your 
# data.frame
class(MyData) # [1] "SpatialPointsDataFrame"
          # attr(,"package")
          # [1] "sp"

The following code snippet comes How to write a shapefile with projection - problem solved

writeOGR(crest.sp, "c:/test", "layer name", driver = "ESRI Shapefile")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!