python - rbind of list of selected point txt files -
python - rbind of list of selected point txt files -
i have lot of point files in folder. rbind (vertically 1 after in single txt file) per list of selected point file point files nowadays in folder.
rbind of list of selected point txt files
several point files in folder
list of selected point file in csv file
the output single csv file consist of xyz of selected point files.
you can simple loop in r.
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)
the "p" vector defining files iterate through. can subset vector or read in external file defines files combined. here examples of this.
# create wildcard list of files in directory , subset p <- list.files(getwd(), pattern="pts$") ( p <- p[c(1,5,8)] ) # read on disk file , create "p" vector # file format such (one record per line): # bp_005424.pts # bp_005701.pts # bp_005503.pts p <- read.table("datalist.txt") ( p <- as.character(p[,1]) )
you can write out point shapefile, if desired.
require(sp) require(rgdal) coordinates(ptdf) <- ~x+y writeogr(ptdf, getwd(), "outshape", driver="esri shapefile")
python r
Comments
Post a Comment