Created
October 28, 2016 16:03
-
-
Save andyneff/6f54adafec4f094e4f2315f3f21398b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import csv | |
from StringIO import StringIO | |
import argparse | |
def parser(): | |
argparser = argparse.ArgumentParser() | |
aa = argparser.add_argument | |
aa('input', help="Input filename") | |
aa('output', help="Output filename") | |
aa('--feet', '-f', default=False, action='store_true', | |
help="Convert input units of feet into meter, else assume already meters") | |
return argparser | |
def main(args=None): | |
argparser = parser() | |
args = argparser.parse_args(args) | |
if args.feet: | |
height_conversion = 0.3048 | |
else: | |
height_conversion = 1 | |
with open(args.input, 'r') as fid: | |
geodetic = fid.readline() | |
header = fid.readline() | |
points = fid.read() | |
geodetic = geodetic.strip().split(' ', 1)[1].strip('()') | |
if geodetic == "WGS 84": | |
srid = 4326 | |
else: | |
raise Exception("Unknown geodetic %s" % geodetic) | |
with open(args.output, 'w') as fid: | |
writer = csv.writer(fid, delimiter=',') | |
for point in csv.reader(StringIO(points), delimiter=','): | |
name,point = point | |
#STUPID QT reader CLEARLY claims it's in xyz order, but it's CLEARLY yxz. liars! | |
lat, lon, alt, r, g, b = point.split() | |
writer.writerow([name, srid, lon, lat, alt*height_conversion]) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment