File: utm-converter

package info (click to toggle)
utm 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 164 kB
  • sloc: python: 648; makefile: 4
file content (35 lines) | stat: -rwxr-xr-x 1,524 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python

from __future__ import print_function

import argparse
import utm

parser = argparse.ArgumentParser(description='Bidirectional UTM-WGS84 converter for python')
subparsers = parser.add_subparsers()

parser_latlon = subparsers.add_parser('latlon', help='Convert a latitude/longitude pair WGS84 to UTM')
parser_latlon.add_argument('latitude', type=float, help='Latitude of the WGS84 coordinate')
parser_latlon.add_argument('longitude', type=float, help='Longitude of the WGS84 coordinate')

parser_utm = subparsers.add_parser('utm', help='Convert a UTM coordinate to WGS84')
parser_utm.add_argument('easting', type=int, help='Easting component of the UTM coordinate')
parser_utm.add_argument('northing', type=int, help='Northing component of the UTM coordinate')
parser_utm.add_argument('zone_number', type=int, help='Zone number of the UTM coordinate')
parser_utm.add_argument('zone_letter', help='Zone letter of the UTM coordinate')

args = parser.parse_args()

if all(arg in args for arg in ['easting', 'northing', 'zone_number', 'zone_letter']):
    if args.zone_letter == '':
        parser_utm.print_usage()
        print("utm-converter utm: error: too few arguments")
        exit()

    coordinate = utm.to_latlon(args.easting, args.northing,
                               args.zone_number, args.zone_letter)

elif all(arg in args for arg in ['latitude', 'longitude']):
    coordinate = utm.from_latlon(args.latitude, args.longitude)

print(','.join(str(component) for component in coordinate))