I have file containing random x,y,z coordinates. I am trying to write some code to insert a "-"(negative figure) in front of the z value (therefore giving me a negative elevation).
the problem is, I am saving the file as a .csv, unfortunately this does not add any delimiters, so the data is just on one cell per row separated by a space: x_y_z. The "csv" file contains over 1 million points, so editing it in excel is out of the question.
I have tried a couple of methods to do what I want, but i'm falling over when trying to iterate through every row and to write out the data. Any help or pointers would be greatly appreciated.
I've tried 2 things. the first method is probably extremely crude, but it seems to achieve what I want, although it only works on 1 line. I don't know how to really iterate through every line.
The second method will take the first line, and separate the X, Y and Z into different variables, after that I'm lost!
#First method:
import csv
inputfile = csv.reader(open ("\\wk.csv", 'r'))
for row in inputfile:
rowstring = str(row)
x1 = rowstring[2:11]
y1 = rowstring[12:22]
z1 = "-" + rowstring[23:29]
xynz = x1 + " " + y1 + " " + z1
#second method:
with open ("\\wk.csv", 'r+') as f:
for l in f:
x2, y2, z2 = l.split()
z3 = "-"+z2
The first method will give me the result I need for one line only.['555555.55', '4444444.44', '-333.33']
The second method splits out the Z where I can add a negative, but after i'm stuck