选定点txt文件列表的列表

accedesoft

我的文件夹中有很多Point文件。我想根据文件夹中存在的所有点文件中选定点文件的列表来进行rbind(垂直地在一个txt文件中一个接一个)。

选定点txt文件列表的列表

文件夹中的几个Point文件

文件夹中的几个Point文件

CSV文件中所选点文件的列表

所选点文件列表

输出将是单个CSV文件,其中包含所选点文件的所有XYZ。

杰弗里·埃文斯(Jeffrey Evans)

您可以使用R中的简单for循环来执行此操作。

 setwd("D:/TEST")
    ( p <- list.files(getwd(), pattern="pts$") )
      ptdf <- read.table(p[1], header=FALSE)
        names(ptdf) <- c("x","y","z") 
          for(i in 2:length(p)) {
            d <- read.table(p[i], header=FALSE)
              names(d) <- c("x","y","z") 
            ptdf <- rbind(ptdf, d) 
           }
       write.csv(ptdf, "FileName.csv", row.names=FALSE, quote=FALSE)

“ p”向量定义了您要遍历的文件。您可以将此向量作为子集,也可以读取一个定义了将要合并的文件的外部文件。这里有一些例子。

# Create a wildcard list of files in directory and then subset
p <- list.files(getwd(), pattern="pts$")
  ( p <- p[c(1,5,8)] )

# Read on disk file and create "p" vector
# File format is such (one record per line):
#   BP_005424.pts
#   BP_005701.pts
#   BP_005503.pts
p <- read.table("DataList.txt")
  ( p <- as.character(p[,1]) ) 

如果需要,您甚至可以写出点shapefile。

require(sp)
require(rgdal)

coordinates(ptdf) <- ~x+y
  writeOGR(ptdf, getwd(), "OutShape", driver="ESRI Shapefile")  

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章