~ubuntu-branches/ubuntu/utopic/liblas/utopic

« back to all changes in this revision

Viewing changes to python/tests/File.txt

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2013-11-26 16:03:56 UTC
  • mto: (2.1.1 experimental) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20131126160356-r94gc8jmp4lm0yix
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
  >>> from liblas import file
 
2
  >>> file.File('notafile.las') #doctest: +IGNORE_EXCEPTION_DETAIL
 
3
  Traceback (most recent call last):
 
4
  ...
 
5
  OSError: missing file
 
6
  
 
7
  >>> f = file.File('../test/data/TO_core_last_clip.las')
 
8
  
 
9
  >>> f.header # doctest: +ELLIPSIS
 
10
  <liblas.header.Header object at ...>
 
11
  
 
12
  >>> f.header.point_records_count
 
13
  8L
 
14
  
 
15
  >>> h = f.header
 
16
  >>> h.data_offset
 
17
  229L
 
18
  >>> p = f.read(0)
 
19
  >>> p.x, p.y, p.z
 
20
  (630262.30000000005, 4834500.0, 51.530000000000001)
 
21
  
 
22
  >>> p = f.read(6)
 
23
  >>> p.x, p.y, p.z
 
24
  (630320.95999999996, 4834500.0, 55.009999999999998)
 
25
  
 
26
  >>> f.seek(5)
 
27
  True
 
28
 
 
29
  >>> for i in f:
 
30
  ...   p = i
 
31
  ...   break
 
32
 
 
33
  >>> p.x, p.y, p.z
 
34
  (630323.57000000007, 4834500.0, 55.020000000000003)
 
35
  
 
36
  >>> f.seek(4)
 
37
  True
 
38
 
 
39
  >>> for i in f:
 
40
  ...   p = i
 
41
  ...   break
 
42
 
 
43
  >>> p.x, p.y, p.z
 
44
  (630327.58999999997, 4834500.0, 54.730000000000004)
 
45
 
 
46
  >>> f.seek(1)
 
47
  True
 
48
 
 
49
  >>> for i in f:
 
50
  ...   p = i
 
51
  ...   break
 
52
 
 
53
  >>> p.x, p.y, p.z
 
54
  (630282.45000000007, 4834500.0, 51.630000000000003)
 
55
  
 
56
  >>> f.close()
 
57
  >>> f.open()
 
58
 
 
59
 
 
60
Test Reading different locations and proper internal overwriting of the file
 
61
 
 
62
  >>> f2 = file.File('../test/data/TO_core_last_clip.las')
 
63
  >>> f2.header.data_offset
 
64
  229L  
 
65
  >>> p2 = f2.read(6)
 
66
  >>> p2.x, p2.y, p2.z
 
67
  (630320.95999999996, 4834500.0, 55.009999999999998)
 
68
 
 
69
  >>> p2 == f2.read(3)
 
70
  False
 
71
  >>> p2.x == f2.read(6).x
 
72
  True
 
73
 
 
74
 
 
75
  >>> f2.close()
 
76
  >>> del f2
 
77
  
 
78
  >>> points = []
 
79
  >>> for i in f:
 
80
  ...   points.append(i)
 
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 ...>
 
90
 
 
91
  >>> f[0]
 
92
  <liblas.point.Point object at ...>
 
93
 
 
94
  >>> out = f[0:3]
 
95
  >>> out
 
96
  [<liblas.point.Point object at ...>, <liblas.point.Point object at ...>, <liblas.point.Point object at ...>]
 
97
  >>> len(out)
 
98
  3
 
99
 
 
100
  >>> len(points)
 
101
  8
 
102
 
 
103
  >>> for p in points:
 
104
  ...   print p.x, p.y
 
105
  630262.3 4834500.0
 
106
  630282.45 4834500.0
 
107
  630300.08 4834500.0
 
108
  630346.83 4834500.0
 
109
  630327.59 4834500.0
 
110
  630323.57 4834500.0
 
111
  630320.96 4834500.0
 
112
  630280.89 4834500.0
 
113
 
 
114
  >>> points = []
 
115
  >>> f.seek(0)
 
116
  True  
 
117
  >>> for i in f:
 
118
  ...   points.append(i)
 
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 ...>
 
128
 
 
129
 
 
130
  >>> len(points)
 
131
  8  
 
132
 
 
133
  >>> del f
 
134
  
 
135
  >>> f = file.File('junk.las', mode="w", header=h)
 
136
  >>> f.header.data_offset
 
137
  229L    
 
138
  >>> sum(h.offset)
 
139
  0.0
 
140
  >>> h.min
 
141
  [630262.30000000005, 4834500.0, 50.899999999999999]
 
142
 
 
143
  >>> for i in points:
 
144
  ...    f.write(i)
 
145
  
 
146
  >>> pts = file.File('junk.las')
 
147
  Traceback (most recent call last):
 
148
  ...
 
149
  LASException: File junk.las is already open for write.  Close the file or delete the reference to it
 
150
  
 
151
  >>> f.close()
 
152
  >>> f.header
 
153
 
 
154
  >>> del f
 
155
  
 
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
 
158
 
 
159
  >>> f2 = file.File('junk.las')
 
160
  >>> h = f2.header
 
161
  >>> h.data_offset
 
162
  229L    
 
163
  >>> f2.close()
 
164
  
 
165
  >>> f = file.File('junk.las', mode='w+', header=h)
 
166
  
 
167
  >>> for i in points:
 
168
  ...    f.write(i)
 
169
  
 
170
  >>> f.close()
 
171
  
 
172
  >>> f = file.File('junk.las')
 
173
  >>> cnt = 0
 
174
  >>> for i in f:
 
175
  ...     cnt += 1
 
176
  
 
177
  >>> cnt
 
178
  16
 
179
 
 
180
  >>> buffered_header = f.header
 
181
  >>> del f 
 
182
 
 
183
  >>> buffered_header.padding = 1024 - buffered_header.data_offset
 
184
  >>> buffered_header.padding
 
185
  795L
 
186
 
 
187
  >>> buffered_header.data_offset
 
188
  229L
 
189
 
 
190
  >>> f3 = file.File('junk2.las',mode='w',header=buffered_header)
 
191
 
 
192
  >>> for i in points:
 
193
  ...    f3.write(i)
 
194
    
 
195
  >>> f3.close()
 
196
 
 
197
  >>> del f3
 
198
 
 
199
  >>> f4 = file.File('junk2.las')
 
200
 
 
201
  >>> f4.header.data_offset
 
202
  1024L
 
203
  >>> del f4
 
204
 
 
205
  
 
206
  >>> f = file.File('junk2.las')
 
207
  >>> f.header.data_offset
 
208
  1024L
 
209
  
 
210
  >>> points = []
 
211
  >>> for i in f:
 
212
  ...   points.append(i)
 
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 ...>
 
222
 
 
223
  >>> for g in points:
 
224
  ...   print round(g.x, 6)
 
225
  630262.3
 
226
  630282.45
 
227
  630300.08
 
228
  630346.83
 
229
  630327.59
 
230
  630323.57
 
231
  630320.96
 
232
  630280.89
 
233
 
 
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
 
236
 
 
237
  >>> buffered_header.data_offset = 1024
 
238
  >>> buffered_header.minor_version = 2
 
239
  >>> f3 = file.File('junk3.las',mode='w',header=buffered_header)
 
240
 
 
241
  >>> f3.header.data_offset
 
242
  1024L
 
243
 
 
244
  >>> for i in points:
 
245
  ...    f3.write(i)
 
246
    
 
247
  >>> f3.close()
 
248
 
 
249
  >>> del f3
 
250
 
 
251
  >>> f = file.File('junk3.las')
 
252
  >>> f.header.data_offset
 
253
  1024L
 
254
  
 
255
  >>> points = []
 
256
  >>> for i in f:
 
257
  ...   points.append(i)
 
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 ...>
 
267
 
 
268
  >>> for g in points:
 
269
  ...   print round(g.x, 6)
 
270
  630262.3
 
271
  630282.45
 
272
  630300.08
 
273
  630346.83
 
274
  630327.59
 
275
  630323.57
 
276
  630320.96
 
277
  630280.89
 
278
 
 
279
 
 
280
The header's offset will change +=2 if there isn't enough room in the 
 
281
header after you subtract the VLRs
 
282
 
 
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)
 
289
 
 
290
  >>> f4.header.data_offset
 
291
  229L
 
292
 
 
293
  >>> for i in points:
 
294
  ...    f4.write(i)
 
295
    
 
296
  >>> f4.close()
 
297
 
 
298
  >>> del f4
 
299
 
 
300
 
 
301
  >>> f = file.File('junk4.las')
 
302
  >>> f.header.data_offset
 
303
  229L
 
304
  
 
305
  >>> points = []
 
306
  >>> for i in f:
 
307
  ...   points.append(i)
 
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 ...>
 
317
 
 
318
  >>> for g in points:
 
319
  ...   print round(g.x, 6)
 
320
  630262.3
 
321
  630282.45
 
322
  630300.08
 
323
  630346.83
 
324
  630327.59
 
325
  630323.57
 
326
  630320.96
 
327
  630280.89
 
328
 
 
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)
 
334
 
 
335
  >>> comp_header.compressed
 
336
  True
 
337
 
 
338
  >>> for i in points:
 
339
  ...    compressed.write(i)
 
340
  
 
341
  >>> compressed.close()
 
342
  >>> del compressed
 
343
 
 
344
  >>> read_compressed = file.File('output.laz', mode='r')
 
345
 
 
346
  >>> read_compressed.header.compressed
 
347
  True
 
348
 
 
349
  >>> for i in read_compressed:
 
350
  ...   print round(i.x, 6)
 
351
  630262.3
 
352
  630282.45
 
353
  630300.08
 
354
  630346.83
 
355
  630327.59
 
356
  630323.57
 
357
  630320.96
 
358
  630280.89
 
359
 
 
360
  
 
361
  >>> read_compressed.close()
 
362
  >>> del read_compressed    
 
363
 
 
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.  
 
366
 
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)
 
371
 
372
#   >>> h6 = f6.header
 
373
#   >>> f = h6.schema
 
374
#   >>> f.time = True
 
375
#   >>> f.color = True
 
376
#   >>> f.size = 52
 
377
#   >>> h6.schema = f
 
378
#   >>> h6.data_record_length
 
379
#   52
 
380
 
381
#   
 
382
# f.size - f.base_size will be 16 bytes of space (h6.data_record_length - 34 bytes for point format 3)
 
383
 
384
# >>> import ctypes
 
385
#  
 
386
#   >>> d = (ctypes.c_ubyte * (f.size - f.base_size))() 
 
387
#   >>> d[10]
 
388
#   0
 
389
#   >>> d[0] = 13
 
390
 
391
#   >>> d2 = (ctypes.c_ubyte * 6)() 
 
392
#   >>> d2[0] = 11
 
393
#     
 
394
#   >>> f7 = file.File('junk5.las',mode='w', header=h6)
 
395
#   >>> i = 0
 
396
#   >>> for p in points:
 
397
#   ...     if i == 0:
 
398
#   ...         p.data = d
 
399
#   ...     if i == 1:
 
400
#   ...         p.data = d2
 
401
#   ...     i = i + 1
 
402
#   ...     f7.write(p)
 
403
#   >>> f7.close()
 
404
#   >>> del f7
 
405
#   
 
406
#   >>> f8 = file.File('junk5.las')
 
407
#   >>> f8.header.data_record_length
 
408
#   52
 
409
 
410
#   >>> p = f8[0].data[0]
 
411
#   >>> p
 
412
#   13
 
413
#   >>> p = f8[0].data[15]
 
414
#   >>> p
 
415
#   0
 
416
#   
 
417
#   >>> p = f8[1].data[0]
 
418
#   >>> p
 
419
#   11
 
420
  
 
421
  >>> import os
 
422
  >>> os.remove('junk.las')
 
423
  >>> os.remove('junk2.las')
 
424
  >>> os.remove('junk3.las')
 
425
  >>> os.remove('junk4.las')
 
426
 
 
427
#  >>> os.remove('junk5.las')
 
428
       
 
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'
 
433
  destroyed once
 
434
  >>> f.handle = None
 
435
  >>> liblas.core.las.LASWriter_Destroy(f.handle)
 
436
  Traceback (most recent call last):
 
437
  ...
 
438
  LASException: LASError in "LASWriter_Destroy": Pointer 'hWriter' is NULL in 'LASWriter_Destroy'.
 
439
 
 
440
  >>> import os
 
441
  >>> os.remove('junk.las')
 
442
  
 
443
  
 
444
 
 
445