1
>>> from liblas import file
2
>>> file.File('notafile.las') #doctest: +IGNORE_EXCEPTION_DETAIL
3
Traceback (most recent call last):
7
>>> f = file.File('../test/data/TO_core_last_clip.las')
9
>>> f.header # doctest: +ELLIPSIS
10
<liblas.header.Header object at ...>
12
>>> f.header.point_records_count
20
(630262.30000000005, 4834500.0, 51.530000000000001)
24
(630320.95999999996, 4834500.0, 55.009999999999998)
34
(630323.57000000007, 4834500.0, 55.020000000000003)
44
(630327.58999999997, 4834500.0, 54.730000000000004)
54
(630282.45000000007, 4834500.0, 51.630000000000003)
60
Test Reading different locations and proper internal overwriting of the file
62
>>> f2 = file.File('../test/data/TO_core_last_clip.las')
63
>>> f2.header.data_offset
67
(630320.95999999996, 4834500.0, 55.009999999999998)
71
>>> p2.x == f2.read(6).x
81
... print i # doctest: +ELLIPSIS
82
<liblas.point.Point object at ...>
83
<liblas.point.Point object at ...>
84
<liblas.point.Point object at ...>
85
<liblas.point.Point object at ...>
86
<liblas.point.Point object at ...>
87
<liblas.point.Point object at ...>
88
<liblas.point.Point object at ...>
89
<liblas.point.Point object at ...>
92
<liblas.point.Point object at ...>
96
[<liblas.point.Point object at ...>, <liblas.point.Point object at ...>, <liblas.point.Point object at ...>]
119
... print i # doctest: +ELLIPSIS
120
<liblas.point.Point object at ...>
121
<liblas.point.Point object at ...>
122
<liblas.point.Point object at ...>
123
<liblas.point.Point object at ...>
124
<liblas.point.Point object at ...>
125
<liblas.point.Point object at ...>
126
<liblas.point.Point object at ...>
127
<liblas.point.Point object at ...>
135
>>> f = file.File('junk.las', mode="w", header=h)
136
>>> f.header.data_offset
141
[630262.30000000005, 4834500.0, 50.899999999999999]
146
>>> pts = file.File('junk.las')
147
Traceback (most recent call last):
149
LASException: File junk.las is already open for write. Close the file or delete the reference to it
156
Go read the new header we've written. It might be out of date because what
157
was written in mode='w' might not equal what was passed in as the header= paramete
159
>>> f2 = file.File('junk.las')
165
>>> f = file.File('junk.las', mode='w+', header=h)
172
>>> f = file.File('junk.las')
180
>>> buffered_header = f.header
183
>>> buffered_header.padding = 1024 - buffered_header.data_offset
184
>>> buffered_header.padding
187
>>> buffered_header.data_offset
190
>>> f3 = file.File('junk2.las',mode='w',header=buffered_header)
199
>>> f4 = file.File('junk2.las')
201
>>> f4.header.data_offset
206
>>> f = file.File('junk2.las')
207
>>> f.header.data_offset
213
... print i # doctest: +ELLIPSIS
214
<liblas.point.Point object at ...>
215
<liblas.point.Point object at ...>
216
<liblas.point.Point object at ...>
217
<liblas.point.Point object at ...>
218
<liblas.point.Point object at ...>
219
<liblas.point.Point object at ...>
220
<liblas.point.Point object at ...>
221
<liblas.point.Point object at ...>
224
... print round(g.x, 6)
234
Now try writing a 1.2 version of the junk2.las file above to ensure that
235
the data_offset *doesn't* change at all
237
>>> buffered_header.data_offset = 1024
238
>>> buffered_header.minor_version = 2
239
>>> f3 = file.File('junk3.las',mode='w',header=buffered_header)
241
>>> f3.header.data_offset
251
>>> f = file.File('junk3.las')
252
>>> f.header.data_offset
258
... print i # doctest: +ELLIPSIS
259
<liblas.point.Point object at ...>
260
<liblas.point.Point object at ...>
261
<liblas.point.Point object at ...>
262
<liblas.point.Point object at ...>
263
<liblas.point.Point object at ...>
264
<liblas.point.Point object at ...>
265
<liblas.point.Point object at ...>
266
<liblas.point.Point object at ...>
269
... print round(g.x, 6)
280
The header's offset will change +=2 if there isn't enough room in the
281
header after you subtract the VLRs
283
>>> from liblas import header
284
>>> h2 = header.Header()
285
>>> h2.data_offset = 227
286
>>> h2.minor_version = 0
287
>>> h2.scale = [0.01, 0.01, 0.01]
288
>>> f4 = file.File('junk4.las',mode='w',header=h2)
290
>>> f4.header.data_offset
301
>>> f = file.File('junk4.las')
302
>>> f.header.data_offset
308
... print i # doctest: +ELLIPSIS
309
<liblas.point.Point object at ...>
310
<liblas.point.Point object at ...>
311
<liblas.point.Point object at ...>
312
<liblas.point.Point object at ...>
313
<liblas.point.Point object at ...>
314
<liblas.point.Point object at ...>
315
<liblas.point.Point object at ...>
316
<liblas.point.Point object at ...>
319
... print round(g.x, 6)
329
>>> comp_header = header.Header()
330
>>> comp_header.minor_version = 2
331
>>> comp_header.compressed = True
332
>>> comp_header.scale = [0.01, 0.01, 0.01]
333
>>> compressed = file.File('output.laz', mode='w', header=comp_header)
335
>>> comp_header.compressed
339
... compressed.write(i)
341
>>> compressed.close()
344
>>> read_compressed = file.File('output.laz', mode='r')
346
>>> read_compressed.header.compressed
349
>>> for i in read_compressed:
350
... print round(i.x, 6)
361
>>> read_compressed.close()
362
>>> del read_compressed
364
# The following tests writing out point data that are larger in size than
365
# the base point format, allowing you to store extra data.
367
# >>> f6 = file.File('../test/data/TO_core_last_clip.las')
368
# >>> p2 = f6.read(6)
369
# >>> p2.x, p2.y, p2.z
370
# (630320.95999999996, 4834500.0, 55.009999999999998)
378
# >>> h6.data_record_length
382
# f.size - f.base_size will be 16 bytes of space (h6.data_record_length - 34 bytes for point format 3)
386
# >>> d = (ctypes.c_ubyte * (f.size - f.base_size))()
391
# >>> d2 = (ctypes.c_ubyte * 6)()
394
# >>> f7 = file.File('junk5.las',mode='w', header=h6)
396
# >>> for p in points:
406
# >>> f8 = file.File('junk5.las')
407
# >>> f8.header.data_record_length
410
# >>> p = f8[0].data[0]
413
# >>> p = f8[0].data[15]
417
# >>> p = f8[1].data[0]
422
>>> os.remove('junk.las')
423
>>> os.remove('junk2.las')
424
>>> os.remove('junk3.las')
425
>>> os.remove('junk4.las')
427
# >>> os.remove('junk5.las')
429
>>> f = file.File('junk.las', mode="w", header=h)
430
>>> import liblas.core
431
>>> liblas.core.las.LASWriter_Destroy(f.handle)
432
>>> print 'destroyed once'
435
>>> liblas.core.las.LASWriter_Destroy(f.handle)
436
Traceback (most recent call last):
438
LASException: LASError in "LASWriter_Destroy": Pointer 'hWriter' is NULL in 'LASWriter_Destroy'.
441
>>> os.remove('junk.las')