AnsweredAssumed Answered

Parsing text file and output to text file or csv

Question asked by kshah77 on Jun 20, 2016
Latest reply on Jun 20, 2016 by kshah77

Hi

I have a gps text file that has coordinates with other variables. I need to parse the file in order to get Lat, Long and Altitude values from the file and write it into new text file or csv. I tried to read the lines but I got error like this:

Here is my code:

 

# This script reads a GPS data and prints a list of coordinate pairs

import csv

 

# Set up input

gpsdata = open("C:/testdata/telemetry2.txt", "r")

 

 

 

# Set and process CSV reader

csvReader = csv.reader(gpsdata)

header = csvReader.next()

latvalueIndex = header.index("lat")

lonvalueIndex = header.index("long")

altvalueIndex = header.index("alt")

 

# Make an empty list

coordList = []

 

# Loop through the lines in the file and get each coordinate

for row in csvReader:

    lat = row[latvalueIndex]

    lon = row[lonvalueIndex]

    alt = row[altvalueIndex]

 

    coordList.append([lat,lon,alt])

 

# Print the coordinate list

print coordList

 

I have also attached the data sample. I will appreciate for any help to get this fixed. Thanks

Attachments

Outcomes