Skip to content

Commit

Permalink
Merge pull request #1697 from pierotofy/321
Browse files Browse the repository at this point in the history
Compress GCP data before VLR inclusion
  • Loading branch information
pierotofy authored Sep 8, 2023
2 parents 2930927 + d78b8ff commit 7277eab
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions stages/odm_georeferencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fiona
import fiona.crs
import json
import zipfile
from collections import OrderedDict
from pyproj import CRS

Expand Down Expand Up @@ -32,6 +33,7 @@ def process(self, args, outputs):
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)
Expand Down Expand Up @@ -104,6 +106,9 @@ def process(self, args, outputs):

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)
Expand Down Expand Up @@ -131,11 +136,14 @@ def process(self, args, outputs):
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\\\": 1, \\\"description\\\": \\\"Ground Control Points (GeoJSON)\\\"}"' % gcp_geojson_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))

Expand Down

0 comments on commit 7277eab

Please sign in to comment.