Changeset 888
- Timestamp:
- 09/27/08 19:12:14 (3 months ago)
- Location:
- trunk
- Files:
-
- 5 modified
-
include/liblas/capi/liblas.h (modified) (1 diff)
-
python/liblas/core.py (modified) (1 diff)
-
python/liblas/vlr.py (modified) (1 diff)
-
python/tests/VLR.txt (modified) (3 diffs)
-
src/las_c_api.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/liblas/capi/liblas.h
r875 r888 970 970 LAS_DLL LASError LASVLR_SetReserved(LASVLRH hVLR, uint16_t value); 971 971 972 /** Gets the data stream for the VLR as an array of bytes 973 * @param hVLR the LASVLRH instance 974 * @param data a pointer to where place the array 975 * @param length a pointer to where to place the length of the array 972 /** Gets the data stream for the VLR as an array of bytes. The length of this 973 * array should be the same as LASVLR_GetRecordLength. You must allocate it on 974 * the heap and you are responsible for its destruction. 975 * @param hVLR the LASVLRH instance 976 * @param data a pointer to your array where you want the data copied 976 977 * @return LASErrorEnum 977 978 */ 978 LAS_DLL LASError LASVLR_GetData(const LASVLRH hVLR, uint8_t** data, int* length); 979 LAS_DLL LASError LASVLR_GetData(const LASVLRH hVLR, uint8_t* data); 980 981 /** Sets the data stream for the VLR as an array of bytes. The length of this 982 * array should be the same as LASVLR_GetRecordLength. The data are copied into 983 * the VLR structure. 984 * @param hVLR the LASVLRH instance 985 * @param data a pointer to your array. It must be LASVLR_GetRecordLength in size 986 * @return LASErrorEnum 987 */ 988 LAS_DLL LASError LASVLR_SetData(const LASVLRH hVLR, uint8_t* data, uint16_t length); 979 989 980 990 LAS_C_END -
trunk/python/liblas/core.py
r874 r888 516 516 las.LASVLR_SetReserved.restype = ctypes.c_int 517 517 518 las.LASVLR_GetData.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_ubyte)] 519 las.LASVLR_GetData.errcheck = check_value 520 las.LASVLR_GetData.restype = ctypes.c_int 521 522 las.LASVLR_SetData.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_ubyte)] 523 las.LASVLR_SetData.errcheck = check_value 524 las.LASVLR_SetData.restype = ctypes.c_int -
trunk/python/liblas/vlr.py
r813 r888 87 87 88 88 def get_data(self): 89 b = ctypes.pointer(ctypes.c_ubyte()) 90 i = ctypes.pointer(ctypes.c_int()) 91 core.las.LASVLR_GetData(self.handle, ctypes.byref(b), i) 92 print 'i length: %s' % i.contents.value 93 print 'bvalue : %s' % b.contents 89 length = self.recordlength 90 data = (ctypes.c_ubyte * length)() 91 core.las.LASVLR_GetData(self.handle, data) 92 return data 94 93 95 t = (ctypes.c_byte*i.contents.value)()96 p rint 'b[0:71]: ', b[0:i.contents.value]97 parray = ctypes.cast(b, ctypes.c_void_p(i.contents.value))98 print 'parray value' , parray[0:i.contents.value]94 def set_data(self, data): 95 pdata = ctypes.cast(data, ctypes.POINTER(ctypes.c_ubyte)) 96 core.las.LASVLR_SetData(self.handle, pdata, self.recordlength) 97 data = property(get_data, set_data) 99 98 100 o = ''.join([chr(b[i]) for i in range(i.contents.value)])101 print 'o: ', o102 print 'type(parray): ', type(parray)103 # buf = ctypes.create_string_buffer(i.value)104 # print type(buf)105 return ctypes.cast(b, ctypes.c_char_p).value106 # return ctypes.create_string_buffer(parray, i.contents.value)[:]107 data = property(get_data)108 -
trunk/python/tests/VLR.txt
r784 r888 20 20 'libLAS' 21 21 22 >>> v.recordlength = 256 23 >>> v.recordlength 24 256 25 26 >>> import ctypes 27 >>> data = (ctypes.c_ubyte * 256)() 28 >>> data[10] 29 0 30 31 >>> for i in range(256): 32 ... data[i] = 2+i 33 34 >>> data[10] 35 12 36 >>> v.data = data 37 38 # Ensure we can round trip the data 39 >>> [data[i] for i in range(10)] 40 [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] 41 >>> [v.data[i] for i in range(10)] 42 [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] 43 44 # Ensure poking one array doesn't affect the other 45 >>> data[1] = 32 46 >>> v.data = data 47 >>> data[1] = 3 48 >>> v.data[1] 49 32 50 >>> data[1] 51 3 52 53 >>> [v.data[i] for i in range(10)] 54 [2, 32, 4, 5, 6, 7, 8, 9, 10, 11] 55 56 22 57 >>> from liblas import file 23 58 >>> f = file.File('../test/data/srs.las') … … 33 68 'LASF_Projection' 34 69 35 # >>> data = v.data 36 # >>> len(data) 70 >>> data = v.data 71 >>> len(data) 72 72 73 >>> data[6] 74 8 37 75 38 76 # Ensure the offset is updated when a VLR is deleted … … 42 80 >>> h.data_offset 43 81 633L 82 83 -
trunk/src/las_c_api.cpp
r875 r888 1469 1469 } 1470 1470 1471 LAS_DLL LASErrorEnum LASVLR_GetData(const LASVLRH hVLR, liblas::uint8_t* * data, int* length) {1471 LAS_DLL LASErrorEnum LASVLR_GetData(const LASVLRH hVLR, liblas::uint8_t* data) { 1472 1472 1473 1473 VALIDATE_POINTER1(hVLR, "LASVLR_GetData", LE_Failure); 1474 1474 1475 1475 try { 1476 std::vector<liblas::uint8_t> *d = new std::vector<liblas::uint8_t>(((LASVLR*) hVLR)->GetData()); 1477 *data = &(d->front()); 1478 //data = &(d[0]) 1479 *length = static_cast<int>(d->size()); 1480 printf("GetData length %d\n", *length); 1476 LASVLR* vlr = ((LASVLR*) hVLR); 1477 std::vector<liblas::uint8_t> d = vlr->GetData(); 1478 liblas::uint16_t length = vlr->GetRecordLength(); 1479 for (liblas::uint16_t i=0; i < length; i++) { 1480 data[i] = d[i]; 1481 } 1481 1482 } 1482 1483 catch (std::exception const& e) { … … 1489 1490 } 1490 1491 1492 LAS_DLL LASErrorEnum LASVLR_SetData(const LASVLRH hVLR, liblas::uint8_t* data, liblas::uint16_t length) { 1493 1494 VALIDATE_POINTER1(hVLR, "LASVLR_SetData", LE_Failure); 1495 1496 try { 1497 LASVLR* vlr = ((LASVLR*) hVLR); 1498 std::vector<liblas::uint8_t> d; 1499 d.resize(length); 1500 for (liblas::uint16_t i=0; i < length; i++) { 1501 d[i] = data[i]; 1502 } 1503 vlr->SetData(d); 1504 } 1505 catch (std::exception const& e) { 1506 LASError_PushError(LE_Failure, e.what(), "LASVLR_GetData"); 1507 return LE_Failure; 1508 } 1509 1510 1511 return LE_None; 1512 } 1491 1513 1492 1514 LAS_DLL LASGuidH LASGuid_Create() {
