File: generate_itrf2020.py

package info (click to toggle)
proj 9.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,800 kB
  • sloc: sh: 218,851; cpp: 171,440; sql: 83,614; python: 8,422; ansic: 6,254; yacc: 1,349; makefile: 33
file content (75 lines) | stat: -rwxr-xr-x 3,427 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
###############################################################################
# $Id$
#
#  Project:  PROJ
#  Purpose:  Generate ITRF2020 to ITRFxxxx Helmert transformations (geocentric
#            coordinates) from EPSG database.
#  Author:   Even Rouault <even.rouault at spatialys.com>
#
###############################################################################
#  Copyright (c) 2024, Even Rouault <even.rouault at spatialys.com>
#
#  Permission is hereby granted, free of charge, to any person obtaining a
#  copy of this software and associated documentation files (the "Software"),
#  to deal in the Software without restriction, including without limitation
#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
#  and/or sell copies of the Software, and to permit persons to whom the
#  Software is furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included
#  in all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#  DEALINGS IN THE SOFTWARE.
###############################################################################

import subprocess

def change_sign(param):
    tokens = param.split("=")
    if tokens[1] == "0":
        return None
    if tokens[1][0] == '-':
        return tokens[0] + "=" + tokens[1][1:]
    else:
        return tokens[0] + "=-" + tokens[1]

def generate(source, dest):

    process = subprocess.Popen(f"bin/projinfo -s {source} -t {dest} --single-line -o PROJ -q", shell=True,
                               stdout=subprocess.PIPE, 
                               stderr=subprocess.PIPE)
    out, _ = process.communicate()

    steps = out.decode('ASCII').split('+step')
    assert len(steps) == 8
    txt = steps[4]
    txt = txt[:-1]
    assert txt.startswith(" +inv +proj=helmert")
    txt = txt.replace(" +inv ", "")
    new_tokens = []
    for token in txt.split(" "):
        if token.startswith("+x=") or token.startswith("+y=") or token.startswith("+z=") or \
           token.startswith("+dx=") or token.startswith("+dy=") or token.startswith("+dz=") or \
           token.startswith("+rx=") or token.startswith("+ry=") or token.startswith("+rz=") or \
           token.startswith("+drx=") or token.startswith("+dry=") or token.startswith("+drz=") or \
           token.startswith("+s=") or token.startswith("+ds="):
            new_token = change_sign(token)
            if new_token:
                new_tokens.append(new_token)
        elif token.startswith("+proj=") or token.startswith("+t_epoch=") or token.startswith("+convention="):
            new_tokens.append(token)
        else:
            assert False, (txt, token)
    print("<" + dest + "> " + (" ".join(new_tokens)))

for dest in ("ITRF2014", "ITRF2008", "ITRF2005", "ITRF2000", "ITRF97", "ITRF96",
             "ITRF94", "ITRF93", "ITRF92", "ITRF91", "ITRF90", "ITRF89", "ITRF88"):
    generate("ITRF2020", dest)
    print("")