【发布时间】:2023-04-03 06:39:02
【问题描述】:
我有多个 CSV 作为输入,它们基本上具有经纬度信息,我正在导出 .tiff 图像,这些图像在地图上绘制了这些经度经度。我想知道如何循环这个过程,以便我可以读取多个 CSV,从而生成与这些 CSV 对应的多个地图(.tiff)。任何帮助将不胜感激!
这是我目前使用的代码
rm(list=ls())
sclusters_1 <- readLines("C:\\Users\\D85_H.csv")
skip_second <- sclusters_1[-2]
sclusters <- read.csv(textConnection(skip_second), header = TRUE)
library(grDevices)
library(PBSmapping)
library(maptools)
library(sp)
myShapeFile<-importShapefile("C:\\Users\\st99_d00_shp\\st99_d00",readDBF=TRUE, projection = "LL")
ConvUS <- convUL(myShapeFile)
addressEvents<-as.PolyData(sclusters,projection="LL", zone = 15)
uaddressEvents <- convUL(addressEvents)
sclusters_cl <- unique(sclusters$PID)
len <- length(sclusters_cl)
palette(c("dodgerblue3","red3","olivedrab","purple4","turquoise2","orange3","lightskyblue4","mediumorchid3","saddlebrown","skyblue4"))
setwd("C:/Users/")
name, leave .tiff extension
tiff(filename = "Test.tiff",
width = 3750, height = 3142, units = "px", pointsize = 12,
compression = "lzw",
bg = "transparent")
plotMap(ConvUS , xlim=c(-8000,3500), ylim=c(2000,9500), plt=c(0.07,0.97,0.07,0.98), bg = "white", border = "darkgrey", axes=FALSE, xlab=" ",ylab=" ", lty = 1, lwd = 2)
addPoints(uaddressEvents,col=1:len,cex=2.5, pch = "O")
legend("topright",legend = sclusters_cl, cex=0.7, fill=palette())
#close output file stream
dev.off()
【问题讨论】: