From d10bef263109b675f1f4b94ca54594e4da5ee864 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 8 Sep 2023 13:44:50 -0400 Subject: [PATCH 1/2] Compress GCP data before inclusion in VLR --- stages/odm_georeferencing.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stages/odm_georeferencing.py b/stages/odm_georeferencing.py index 64ceb240..8e8d17b4 100644 --- a/stages/odm_georeferencing.py +++ b/stages/odm_georeferencing.py @@ -5,6 +5,7 @@ import pipes import fiona import fiona.crs import json +import zipfile from collections import OrderedDict from pyproj import CRS @@ -32,6 +33,7 @@ class ODMGeoreferencingStage(types.ODM_Stage): gcp_export_file = tree.path("odm_georeferencing", "ground_control_points.gpkg") gcp_gml_export_file = tree.path("odm_georeferencing", "ground_control_points.gml") gcp_geojson_export_file = tree.path("odm_georeferencing", "ground_control_points.geojson") + gcp_geojson_zip_export_file = tree.path("odm_georeferencing", "ground_control_points.zip") unaligned_model = io.related_file_path(tree.odm_georeferencing_model_laz, postfix="_unaligned") if os.path.isfile(unaligned_model) and self.rerun(): os.unlink(unaligned_model) @@ -104,6 +106,9 @@ class ODMGeoreferencingStage(types.ODM_Stage): with open(gcp_geojson_export_file, 'w') as f: f.write(json.dumps(geojson, indent=4)) + + with zipfile.ZipFile(gcp_geojson_zip_export_file, 'w', compression=zipfile.ZIP_LZMA) as f: + f.write(gcp_geojson_export_file, arcname=os.path.basename(gcp_geojson_export_file)) else: log.ODM_WARNING("GCPs could not be loaded for writing to %s" % gcp_export_file) @@ -134,7 +139,7 @@ class ODMGeoreferencingStage(types.ODM_Stage): if reconstruction.has_gcp() and io.file_exists(gcp_geojson_export_file): log.ODM_INFO("Embedding GCP info in point cloud") params += [ - '--writers.las.vlrs="{\\\"filename\\\": \\\"%s\\\", \\\"user_id\\\": \\\"ODM\\\", \\\"record_id\\\": 1, \\\"description\\\": \\\"Ground Control Points (GeoJSON)\\\"}"' % gcp_geojson_export_file.replace(os.sep, "/") + '--writers.las.vlrs="{\\\"filename\\\": \\\"%s\\\", \\\"user_id\\\": \\\"ODM\\\", \\\"record_id\\\": 2, \\\"description\\\": \\\"Ground Control Points (zip)\\\"}"' % gcp_geojson_zip_export_file.replace(os.sep, "/") ] system.run(cmd + ' ' + ' '.join(stages) + ' ' + ' '.join(params)) From d78b8ff39973ee22d533acff3fbe671f1e9ac3ea Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 8 Sep 2023 13:54:45 -0400 Subject: [PATCH 2/2] GCP file size check --- stages/odm_georeferencing.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stages/odm_georeferencing.py b/stages/odm_georeferencing.py index 8e8d17b4..a478ee1d 100644 --- a/stages/odm_georeferencing.py +++ b/stages/odm_georeferencing.py @@ -136,11 +136,14 @@ class ODMGeoreferencingStage(types.ODM_Stage): f'--writers.las.a_srs="{reconstruction.georef.proj4()}"' # HOBU this should maybe be WKT ] - if reconstruction.has_gcp() and io.file_exists(gcp_geojson_export_file): - log.ODM_INFO("Embedding GCP info in point cloud") - params += [ - '--writers.las.vlrs="{\\\"filename\\\": \\\"%s\\\", \\\"user_id\\\": \\\"ODM\\\", \\\"record_id\\\": 2, \\\"description\\\": \\\"Ground Control Points (zip)\\\"}"' % gcp_geojson_zip_export_file.replace(os.sep, "/") - ] + if reconstruction.has_gcp() and io.file_exists(gcp_geojson_zip_export_file): + if os.path.getsize(gcp_geojson_zip_export_file) <= 65535: + log.ODM_INFO("Embedding GCP info in point cloud") + params += [ + '--writers.las.vlrs="{\\\"filename\\\": \\\"%s\\\", \\\"user_id\\\": \\\"ODM\\\", \\\"record_id\\\": 2, \\\"description\\\": \\\"Ground Control Points (zip)\\\"}"' % gcp_geojson_zip_export_file.replace(os.sep, "/") + ] + else: + log.ODM_WARNING("Cannot embed GCP info in point cloud, %s is too large" % gcp_geojson_zip_export_file) system.run(cmd + ' ' + ' '.join(stages) + ' ' + ' '.join(params))