From e1c9de14ca94a9bc6a957859c7140808b51eba98 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 16 Nov 2023 08:49:18 +0200 Subject: [PATCH] trying to find srtm *fix stations --- core/utils.py | 2 +- parsers/survex.py | 57 ++++++++++++++++++++++++++++++++++++++--- templates/stations.html | 7 +++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/core/utils.py b/core/utils.py index 12f7615..daf48b3 100644 --- a/core/utils.py +++ b/core/utils.py @@ -363,7 +363,7 @@ def find_nearest_point(points, target_point): #let raw = [[406264.72, 5278037.57, 873.53], #first version: #rawheights = [[406264.72, 5278037.57, 873.53], - +# [[406264.72, 5278037.57, 826.64], from constants.js 14 Nov 2023, i.e. 46.89m lower rawheights = [[406264.72, 5278037.57, 873.53], [406314.69, 5278036.50, 861.60], [406364.66, 5278035.43, 852.51], diff --git a/parsers/survex.py b/parsers/survex.py index 260cc9b..070e413 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -50,8 +50,8 @@ METRESINFEET = 3.28084 UNSEENS = "_unseens.svx" IGNOREFILES = ["dummy_file"] -IGNOREPREFIX = ["surface", "kataster", "fixedpts", "gpx", "deprecated"] -EXCEPTPREFIX = ["surface/terrain", "kataster/kataster-boundaries", "gpx/gpx_publish/essentials", "template", "docs", "deprecated", "subsections", "1623-and-1626-no-schoenberg-hs", "1623-and-1624-and-1626-and-1627", "1623-and-1626", "1623.svx", "1626.svx", "smk-system.svx"] +IGNOREPREFIX = ["surface", "kataster", "gpx", "deprecated"] #"fixedpts", +EXCEPTPREFIX = ["surface/terrain", "kataster/kataster-boundaries", "gpx/gpx_publish", "template", "docs", "deprecated", "subsections", "1623-and-1626-no-schoenberg-hs", "1623-and-1624-and-1626-and-1627", "1623-and-1626", "1623.svx", "1626.svx", "smk-system.svx"] # ignorenoncave = [ # "caves-1623", # "caves-1623/2007-NEU", @@ -255,6 +255,7 @@ class LoadingSurvex: rx_end2 = re.compile("(?i)end$") rx_title = re.compile(r"(?i)title$") rx_title2 = re.compile("(?i)title$") + rx_fix = re.compile(r"(?i)fix$") rx_ref = re.compile(r"(?i)ref$") rx_data = re.compile(r"(?i)data$") rx_flags = re.compile(r"(?i)flags$") @@ -307,6 +308,7 @@ class LoadingSurvex: datastar = {} flagsstar = {} + fixes = {} units = "metres" unitsfactor = None slength = 0.0 @@ -356,7 +358,7 @@ class LoadingSurvex: def LoadSurvexFallThrough(self, survexblock, line, cmd): if cmd == "require": pass # should we check survex version available for processing? - elif cmd in ["equate", "fix", "calibrate", "cs", "export", "case", "declination", "infer", "instrument", "sd"]: + elif cmd in ["equate", "calibrate", "cs", "export", "case", "declination", "infer", "instrument", "sd"]: pass # we ignore all these, which is fine. else: if cmd in ["include", "data", "flags", "title", "entrance", "set", "units", "alias", "ref"]: @@ -607,6 +609,34 @@ class LoadingSurvex: parser="survex", message=message, url=None, sb=(survexblock.survexfile.path) ) + def LoadSurvexFix(self, survexblock, line): + """*fix is a station geolocation, units depend on a previous *cs setting + """ + #fixline = line.strip().replace("\t"," ").split(" ") # unpack tuples idiom in python 3 + fixline = re.match("(?i)\s*([\w\d_\.\-]+)\s+(?:reference)?\s*([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)\s*(;.*)?$", line) + if not fixline: + message = f'BAD fix regex {line.replace(" ","|")} {survexblock.survexfile.path}:{survexblock}' + print(self.insp + message) + stash_data_issue(parser="survex", message=message) + else: + name, *fixdata = fixline.groups() + if name in self.fixes: + message = f"! Duplicate *FIX: id '{line}' ({survexblock}) {survexblock.survexfile.path}" + print(self.insp + message) + stash_data_issue(parser="survex", message=message) + + # do not store duplicates, they will be gpx/publish stuff + return + + try: + #_, _, alt, *rest = (fixdata + [None]*4)[:4] + _, _, alt, comment = fixdata + fixid = str(survexblock)+name + self.fixes[fixid] = (survexblock, alt, comment) + except: + print(f'BAD fix {name}, {fixdata=}\n{line.replace(" ","|")}\n{survexblock.survexfile.path}:{survexblock}', file=sys.stderr) + + def LoadSurvexEntrance(self, survexblock, line): # Not using this pass @@ -1796,6 +1826,8 @@ class LoadingSurvex: self.LoadSurvexEntrance(survexblock, args) elif self.rx_date.match(cmd): self.LoadSurvexDate(survexblock, args) + elif self.rx_fix.match(cmd): + self.LoadSurvexFix(survexblock, args) elif self.rx_units.match(cmd): self.LoadSurvexUnits(survexblock, args) elif self.rx_team.match(cmd): @@ -2277,8 +2309,9 @@ def FindAndLoadSurvex(): omit_scan.depthinclude = 0 fullpathtotop = str(Path(settings.SURVEX_DATA, UNSEENS)) - # copy the list to prime the next pass through the files + # copy the lists to prime the next pass through the files omit_scan.svxfileslist = svx_scan.svxfileslist[:] + svx_scan.svxfileslist = [] # free memory svx_scan = None # Hmm. Does this actually delete all the instance variables if they are lists, dicts etc.? @@ -2357,13 +2390,29 @@ def FindAndLoadSurvex(): sys.stdout = stdout_orig legsnumber = svx_load.legsnumber + fixnumber = len(svx_load.fixes) mem1 = get_process_memory() print(f" - Number of SurvexDirectories: {len(svx_load.svxprim):,}") tf = SurvexFile.objects.all().count() - len(removals) print(f" - Number of SurvexFiles: {tf:,}") + print(f" - Number of Survex *fix: {fixnumber:,}") print(f" - Number of Survex legs: {legsnumber:,}") + + for f in svx_load.fixes: + # why are we seeing no *fixes from fixedpts/gps18.svx etc. ? They are parsed ! + survexblock, altitude, comment = svx_load.fixes[f] + if comment: + print(f"{a} {b} {comment}") + if re.match("(?i)[^s]*srtm[\s\S]*", comment.lower()): + print(f"{f} - {comment}") + else: + if str(f).startswith("162"): + print(f"{f} - {survexblock.survexfile}:{survexblock} - {altitude=}") + svx_load = None + + return legsnumber diff --git a/templates/stations.html b/templates/stations.html index 36b9b98..9fa6d58 100644 --- a/templates/stations.html +++ b/templates/stations.html @@ -112,6 +112,13 @@ Coordinate systems in Austria are explained in:
Troggle UTM and lat./lomg. and altitude report
Troggle entrances
+

These stations have the altitude set equal to SRTM

+{% for s in stations %} +{% if '>0<' in s.srtm_diff.0 %} +{{s}} {{s.srtm_diff.0|safe}} ref={{s.srtm_diff.1|floatformat:0}}
+{% endif %} +{% endfor %} +