From 418555e4706a6bfdc2570b4c9b3c36b51da77466 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 30 Sep 2019 16:05:17 -0400 Subject: [PATCH 1/3] Added gcp.make_micmac_copy Former-commit-id: 2d7552082165374201d932d0bee959f4af81ce46 --- opendm/gcp.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/opendm/gcp.py b/opendm/gcp.py index 9da1df69..745e2c63 100644 --- a/opendm/gcp.py +++ b/opendm/gcp.py @@ -120,6 +120,47 @@ class GCPFile: return gcp_file_output + def make_micmac_copy(self, output_dir, precisionxy=1, precisionz=1, utm_zone = None): + """ + Convert this GCP file in a format compatible with MicMac. + :param output_dir directory where to save the two MicMac GCP files. The directory must exist. + :param utm_zone UTM zone to use for output coordinates (UTM string, PROJ4 or EPSG definition). + If one is not specified, the nearest UTM zone will be selected. + :param precisionxy horizontal precision of GCP measurements in meters. + :param precisionz vertical precision of GCP measurements in meters. + """ + if not os.path.isdir(output_dir): + raise IOError("{} does not exist.".format(output_dir)) + if not isinstance(precisionxy, float) and not isinstance(precisionxy, int): + raise AssertionError("precisionxy must be a number") + if not isinstance(precisionz, float) and not isinstance(precisionz, int): + raise AssertionError("precisionz must be a number") + + gcp_3d_file = os.path.join(output_dir, '3d_gcp.txt') + gcp_2d_file = os.path.join(output_dir, '2d_gcp.txt') + + if os.path.exists(gcp_3d_file): + os.remove(gcp_3d_file) + if os.path.exists(gcp_2d_file): + os.remove(gcp_2d_file) + + if utm_zone is None: + utm_zone = self.wgs84_utm_zone() + + target_srs = location.parse_srs_header(utm_zone) + transformer = location.transformer(self.srs, target_srs) + + with open(gcp_3d_file, 'w') as f3: + with open(gcp_2d_file, 'w') as f2: + gcp_n = 1 + for entry in self.iter_entries(): + utm_x, utm_y, utm_z = transformer.TransformPoint(entry.x, entry.y, entry.z) + f3.write("GCP{} {} {} {} {} {}\n".format(gcp_n, utm_x, utm_y, utm_z, precisionxy, precisionz)) + f2.write("GCP{} {} {} {}\n".format(gcp_n, entry.filename, entry.px, entry.py)) + gcp_n += 1 + + return (gcp_3d_file, gcp_2d_file) + class GCPEntry: def __init__(self, x, y, z, px, py, filename, extras=""): self.x = x From 471a0b1b3e49a75031b9194344ab3338c54cd52c Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 2 Oct 2019 21:03:28 -0400 Subject: [PATCH 2/3] MicMac GCP format fixes Former-commit-id: 6a678c946170b19a7df5e14f6717988d6999416a --- opendm/gcp.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/opendm/gcp.py b/opendm/gcp.py index 745e2c63..57769e42 100644 --- a/opendm/gcp.py +++ b/opendm/gcp.py @@ -150,13 +150,25 @@ class GCPFile: target_srs = location.parse_srs_header(utm_zone) transformer = location.transformer(self.srs, target_srs) + gcps = {} + for entry in self.iter_entries(): + utm_x, utm_y, utm_z = transformer.TransformPoint(entry.x, entry.y, entry.z) + k = "{} {} {}".format(utm_x, utm_y, utm_z) + if not k in gcps: + gcps[k] = [entry] + else: + gcps[k].append(entry) + + with open(gcp_3d_file, 'w') as f3: with open(gcp_2d_file, 'w') as f2: gcp_n = 1 - for entry in self.iter_entries(): - utm_x, utm_y, utm_z = transformer.TransformPoint(entry.x, entry.y, entry.z) - f3.write("GCP{} {} {} {} {} {}\n".format(gcp_n, utm_x, utm_y, utm_z, precisionxy, precisionz)) - f2.write("GCP{} {} {} {}\n".format(gcp_n, entry.filename, entry.px, entry.py)) + for k in gcps: + f3.write("GCP{} {} {} {}\n".format(gcp_n, k, precisionxy, precisionz)) + + for entry in gcps[k]: + f2.write("GCP{} {} {} {}\n".format(gcp_n, entry.filename, entry.px, entry.py)) + gcp_n += 1 return (gcp_3d_file, gcp_2d_file) From b90c741b62fbef772d3c24bfbde08cc593ace87c Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 18 Oct 2019 13:45:36 -0400 Subject: [PATCH 3/3] Better bad GCP handling Former-commit-id: 4fa4088d8eac310485e3e47dfa25800e0604af0a --- opendm/location.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendm/location.py b/opendm/location.py index ccc9bbb8..c697964d 100644 --- a/opendm/location.py +++ b/opendm/location.py @@ -140,7 +140,7 @@ def parse_srs_header(header): elif header.lower().startswith("epsg:"): srs = CRS.from_epsg(header.lower()[5:]) else: - log.ODM_ERROR('Could not parse coordinates. Bad SRS supplied: %s' % header) + raise RuntimeError('Could not parse coordinates. Bad SRS supplied: %s' % header) except RuntimeError as e: log.ODM_ERROR('Uh oh! There seems to be a problem with your coordinates/GCP file.\n\n' 'The line: %s\n\n'