From da37dae0c1a6f6309f23f74ac9940d7ede9f5d73 Mon Sep 17 00:00:00 2001 From: pux Date: Sun, 3 Sep 2023 18:39:31 +0200 Subject: neatification --- gk2kml.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'gk2kml.py') diff --git a/gk2kml.py b/gk2kml.py index aad7408..24d842c 100755 --- a/gk2kml.py +++ b/gk2kml.py @@ -12,15 +12,17 @@ import argparse from textwrap import dedent from sys import exit -from pyproj import CRS # Coordinate Reference System +# Coordinate Reference System +# from pyproj import CRS from pyproj import Transformer # https://spatialreference.org/ref/epsg/wgs-84/ # https://en.wikipedia.org/wiki/World_Geodetic_System # https://epsg.io/?q=Gauss-Kruger%20kind%3APROJCRS + def run_argparser(): - argparser = argparse.ArgumentParser(\ + argparser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, description=dedent(''' Convert Gauss-Kru(e)ger Coordinates to WGS84 @@ -57,6 +59,7 @@ def run_argparser(): args = argparser.parse_args() return args + def main(): args = run_argparser() @@ -73,36 +76,31 @@ def main(): northing += '0' # set zone - if args.zone == '2': - src_crs = 'EPSG:5682' - elif args.zone == '3': - src_crs = 'EPSG:5683' - elif args.zone == '4': - src_crs = 'EPSG:5684' - elif args.zone == '5': - src_crs = 'EPSG:5685' + if int(args.zone) >= 2 and int(args.zone) <= 5: + # EPS:5682 .. EPS:5685 + src_crs = 'EPSG:568' + args.zone else: print('Error: Wrong zone!') exit() transformer = Transformer.from_crs(src_crs, 'EPSG:4326') result = transformer.transform(easting, northing) - - if(str(result[0]) != 'inf'): + + if (str(result[0]) != 'inf'): print(str(result[0]) + ', ' + str(result[1])) if args.write: print('Writing to kml file: ' + args.write + '.kml') template = open('template/template.kml', 'r', encoding='utf-8') - outf = open(args.write + '.kml', 'w', encoding='utf-8',\ - errors='ignore') + outf = open(args.write + '.kml', 'w', encoding='utf-8', + errors='ignore') line = template.readline() while line: line = line.replace('$NAME', args.write) line = line.replace('$LON', str(result[1])) line = line.replace('$LAT', str(result[0])) - #print(line, end='') + # print(line, end='') outf.write(line) line = template.readline() @@ -111,5 +109,6 @@ def main(): else: print('Error: no valid result! Check input coords!') + if __name__ == '__main__': main() -- cgit v1.2.2-1-g5e49