Skip to content

Commit 7277eab

Browse files
authored
Merge pull request #1697 from pierotofy/321
Compress GCP data before VLR inclusion
2 parents 2930927 + d78b8ff commit 7277eab

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

stages/odm_georeferencing.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import fiona
66
import fiona.crs
77
import json
8+
import zipfile
89
from collections import OrderedDict
910
from pyproj import CRS
1011

@@ -32,6 +33,7 @@ def process(self, args, outputs):
3233
gcp_export_file = tree.path("odm_georeferencing", "ground_control_points.gpkg")
3334
gcp_gml_export_file = tree.path("odm_georeferencing", "ground_control_points.gml")
3435
gcp_geojson_export_file = tree.path("odm_georeferencing", "ground_control_points.geojson")
36+
gcp_geojson_zip_export_file = tree.path("odm_georeferencing", "ground_control_points.zip")
3537
unaligned_model = io.related_file_path(tree.odm_georeferencing_model_laz, postfix="_unaligned")
3638
if os.path.isfile(unaligned_model) and self.rerun():
3739
os.unlink(unaligned_model)
@@ -104,6 +106,9 @@ def process(self, args, outputs):
104106

105107
with open(gcp_geojson_export_file, 'w') as f:
106108
f.write(json.dumps(geojson, indent=4))
109+
110+
with zipfile.ZipFile(gcp_geojson_zip_export_file, 'w', compression=zipfile.ZIP_LZMA) as f:
111+
f.write(gcp_geojson_export_file, arcname=os.path.basename(gcp_geojson_export_file))
107112

108113
else:
109114
log.ODM_WARNING("GCPs could not be loaded for writing to %s" % gcp_export_file)
@@ -131,11 +136,14 @@ def process(self, args, outputs):
131136
f'--writers.las.a_srs="{reconstruction.georef.proj4()}"' # HOBU this should maybe be WKT
132137
]
133138

134-
if reconstruction.has_gcp() and io.file_exists(gcp_geojson_export_file):
135-
log.ODM_INFO("Embedding GCP info in point cloud")
136-
params += [
137-
'--writers.las.vlrs="{\\\"filename\\\": \\\"%s\\\", \\\"user_id\\\": \\\"ODM\\\", \\\"record_id\\\": 1, \\\"description\\\": \\\"Ground Control Points (GeoJSON)\\\"}"' % gcp_geojson_export_file.replace(os.sep, "/")
138-
]
139+
if reconstruction.has_gcp() and io.file_exists(gcp_geojson_zip_export_file):
140+
if os.path.getsize(gcp_geojson_zip_export_file) <= 65535:
141+
log.ODM_INFO("Embedding GCP info in point cloud")
142+
params += [
143+
'--writers.las.vlrs="{\\\"filename\\\": \\\"%s\\\", \\\"user_id\\\": \\\"ODM\\\", \\\"record_id\\\": 2, \\\"description\\\": \\\"Ground Control Points (zip)\\\"}"' % gcp_geojson_zip_export_file.replace(os.sep, "/")
144+
]
145+
else:
146+
log.ODM_WARNING("Cannot embed GCP info in point cloud, %s is too large" % gcp_geojson_zip_export_file)
139147

140148
system.run(cmd + ' ' + ' '.join(stages) + ' ' + ' '.join(params))
141149

0 commit comments

Comments
 (0)