您應該有關於您的座標參考系統的更多信息。我不確定你的'多邊形'是什麼意思:我認爲.csv只能包含座標點。
下面是一個工作流的例子:創建一個簡單的data.frame;設置座標;寫shapefile;讀回形狀文件;並繪製簡單的地圖。希望能幫助到你。而不是創建一個data.frame,你可以導入你的.csv。
# Load libraries
library(sp)
library(rgdal)
# set CRS . For epsg code, see http://spatialreference.org/
projTest<-CRS("+init=epsg:28992")
# create a temp dir for shapefiles
trashMap<-tempdir()
# create dumb data:
occData<-data.frame(x=c(12,13,14,20),y=c(0,1,4,9),obs=c("a","b","c","d"))
# set x and y as coordinates
coordinates(occData)<-c('x','y')
# assign CRS
proj4string(occData)<-projTest
# write simple shapefile in trashMap dir
writeOGR(occData, trashMap, layer='testLayer', driver="ESRI Shapefile")
# get list of Layers
layers<-ogrListLayers(trashMap)
# read shapefile and selected layer
occData2<-readOGR(trashMap, layers)
# Modify data
occData2$newColumn<-c('no','stress','','dude')
occData2
# verify that is projected
is.projected(occData2)
# display projection type
proj4string(occData2)
# print maps before and after export in shapefile.
print(spplot(occData, auto.key=F, col.regions='black', scales=list(draw=T), pch=2, cex=1))
print(spplot(occData2, auto.key=F, col.regions='black', scales=list(draw=T), pch=2, cex=1))
來源
2014-03-12 18:54:47
fxi
你更容易得到幫助,如果你提供至少你的數據的代表性樣本,以表明你已經嘗試過,並說明爲什麼/怎麼沒有奏效。 – jlhoward
另外,「地圖上的多邊形」是什麼意思?如果你有UTM座標,你可以將它們繪製成點。 – jlhoward