DM_numpy_export.py
1 ## @package python.demo.DM_numpy_export
2 # "
3 # example script showing how to write a point cloud file from numpy dictionary
4 #
5 
6 from opals import pyDM
7 import numpy as np
8 
9 f = pyDM.AddInfoLayoutFactory()
10 f.addColumn(pyDM.ColumnSemantic.Amplitude)
11 layout = f.getLayout()
12 
13 # 4 example points including a Amplitude attribute
14 pts = {}
15 pts["x"] = np.array([0.1, 0.2, 10, 10])
16 pts["y"] = np.array([0, 10, 10, 0])
17 pts["z"] = np.array([0, 1, 2, 3])
18 pts[layout.name(0)] = np.array([5.343, 30.234, 22.32, 30])
19 
20 # filename stem and output format
21 filename_stem = "pts"
22 oformat = pyDM.DataFormat.las
23 
24 exp = None
25 # some export formats require specific initialisation for attributes
26 if oformat == pyDM.DataFormat.shp:
27  dbfTable = pyDM.ShapeTableDefinition(layout)
28  exp = pyDM.ExportShape(filename_stem+".shp", dbfTable=dbfTable,layout=layout)
29  exp.setShapeGeometryType(pyDM.ShapeGeometry.point) #write single points
30 elif oformat == pyDM.DataFormat.odm:
31  exp = pyDM.Export(filename_stem+".odm")
32 elif oformat == pyDM.DataFormat.las:
33  exp = pyDM.ExportLAS(filename_stem+".laz")
34  exp.exportExtraBytes(layout.semantic(0))
35 
36 if not exp:
37  Exception("Unable to create export object")
38 
39 print(f"Writing file '{exp.getFilename()}'...")
40 pyDM.NumpyConverter.export(exp, pts, noDataObj=np.nan) # if a value is nan it is treated as null
41 exp.close()
42 print("done")