Changeset 888

Show
Ignore:
Timestamp:
09/27/08 19:12:14 (3 months ago)
Author:
hobu
Message:

VLR data setting for C/Python APIs #78

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/include/liblas/capi/liblas.h

    r875 r888  
    970970LAS_DLL LASError LASVLR_SetReserved(LASVLRH hVLR, uint16_t value); 
    971971 
    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 
    976977 *  @return LASErrorEnum 
    977978*/ 
    978 LAS_DLL LASError LASVLR_GetData(const LASVLRH hVLR, uint8_t** data, int* length); 
     979LAS_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*/ 
     988LAS_DLL LASError LASVLR_SetData(const LASVLRH hVLR, uint8_t* data, uint16_t length); 
    979989 
    980990LAS_C_END 
  • trunk/python/liblas/core.py

    r874 r888  
    516516las.LASVLR_SetReserved.restype = ctypes.c_int 
    517517 
     518las.LASVLR_GetData.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_ubyte)] 
     519las.LASVLR_GetData.errcheck = check_value 
     520las.LASVLR_GetData.restype = ctypes.c_int 
     521 
     522las.LASVLR_SetData.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_ubyte)] 
     523las.LASVLR_SetData.errcheck = check_value 
     524las.LASVLR_SetData.restype = ctypes.c_int 
  • trunk/python/liblas/vlr.py

    r813 r888  
    8787     
    8888    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 
    9493 
    95         t = (ctypes.c_byte*i.contents.value)() 
    96         print '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) 
    9998 
    100         o = ''.join([chr(b[i]) for i in range(i.contents.value)]) 
    101         print 'o: ', o 
    102         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).value 
    106 #        return ctypes.create_string_buffer(parray, i.contents.value)[:] 
    107     data = property(get_data) 
    108  
  • trunk/python/tests/VLR.txt

    r784 r888  
    2020  'libLAS' 
    2121   
     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     
    2257  >>> from liblas import file 
    2358  >>> f = file.File('../test/data/srs.las') 
     
    3368  'LASF_Projection' 
    3469   
    35 #  >>> data = v.data 
    36 #  >>> len(data) 
     70  >>> data = v.data 
     71  >>> len(data) 
     72  72 
     73  >>> data[6] 
     74  8 
    3775 
    3876  # Ensure the offset is updated when a VLR is deleted 
     
    4280  >>> h.data_offset 
    4381  633L 
     82   
     83   
  • trunk/src/las_c_api.cpp

    r875 r888  
    14691469} 
    14701470 
    1471 LAS_DLL LASErrorEnum LASVLR_GetData(const LASVLRH hVLR, liblas::uint8_t** data, int* length) { 
     1471LAS_DLL LASErrorEnum LASVLR_GetData(const LASVLRH hVLR, liblas::uint8_t* data) { 
    14721472     
    14731473    VALIDATE_POINTER1(hVLR, "LASVLR_GetData", LE_Failure); 
    14741474 
    14751475    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        } 
    14811482    } 
    14821483    catch (std::exception const& e) { 
     
    14891490} 
    14901491 
     1492LAS_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} 
    14911513 
    14921514LAS_DLL LASGuidH LASGuid_Create() {