I have a SpatialPointsDataFrame that has one attribute (let it be called z for convenience), as well as lat / long coordinates.
I want to write this to an XYZ file (i.e. an ASCII file with three columns).
I tried first
write.table(spdf, filename, row.names=FALSE)
but first it wrote down the z value, and then the coordinates on each line. So it was ZXY format, not XYZ. This may not be a big problem, but annoying other people who should use the file.
I am currently using what seems really terrible to do this (see below), but my question is: is there a good and easy way to write SPDF as XYZ with columns in the correct order? It seems like it should be easy!
Thanks for any advice.
mend:
dfOutput <- data.frame(x = coordinates(spdf)[,1], y = coordinates(spdf)[,2]) dfOutput$z <- data.frame(spdf)[,1] write.table(dfOutput, filename, row.names=FALSE)
Flyto source share