Changeset 1241:2b6bba71a3ab


Ignore:
Timestamp:
07/09/09 10:51:33 (13 months ago)
Author:
Howard Butler <hobu.inc@…>
Branch:
default
Convert:
svn:1766ff46-f334-0410-ab20-d63176f87757/trunk@1308
Message:

fix up our blob writing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/las2oci.cpp

    r1240 r1241  
    177177{ 
    178178    // This function returns an array of bytes describing the  
    179     // x,y,z and optionally time values for the point.  The caller owns  
    180     // the array. 
    181     std::vector<liblas::uint8_t>* data = new std::vector<liblas::uint8_t>; 
    182     point_data.resize(24); 
    183     if (bTime) point_data.resize(data->size()+8); // Add the time bytes too 
     179    // x,y,z and optionally time values for the point.   
     180 
     181    point_data.clear(); 
    184182 
    185183    double x = p.GetX(); 
     
    196194    // doubles are 8 bytes long.  For each double, push back the  
    197195    // byte.  We do this for all four values (x,y,z,t) 
    198     for (int i=0; i<8; i++) { 
     196 
     197    // // little-endian 
     198    // for (int i=0; i<sizeof(double); i++) { 
     199    //     point_data.push_back(y_b[i]); 
     200    // } 
     201    //  
     202 
     203    // big-endian 
     204    for (int i = sizeof(double) - 1; i >= 0; i--) { 
    199205        point_data.push_back(x_b[i]); 
    200206    } 
    201     for (int i=0; i<8; i++) { 
     207 
     208    for (int i = sizeof(double) - 1; i >= 0; i--) { 
    202209        point_data.push_back(y_b[i]); 
    203     } 
    204     for (int i=0; i<8; i++) { 
     210    }    
     211 
     212    for (int i = sizeof(double) - 1; i >= 0; i--) { 
    205213        point_data.push_back(z_b[i]); 
    206214    } 
     215 
    207216     
    208217    if (bTime) 
    209218    { 
    210         for (int i=0; i<8; i++) { 
     219        for (int i = sizeof(double) - 1; i >= 0; i--) { 
    211220            point_data.push_back(t_b[i]); 
    212221        } 
    213     } 
    214     return data; 
     222 
     223    } 
     224 
     225    return true; 
    215226} 
    216227std::vector<liblas::uint8_t>* GetResultData(const LASQueryResult& result, LASReader* reader, int nDimension) 
    217228{ 
    218229    list<SpatialIndex::id_type> const& ids = result.GetIDs(); 
    219      
    220     // calculate the vector size 
    221     // d 8-byte IEEE doubles, where d is the PC_TOT_DIMENSIONS value 
     230 
     231    // d 8-byte IEEE  big-endian doubles, where d is the PC_TOT_DIMENSIONS value 
    222232    // 4-byte big-endian integer for the BLK_ID value 
    223233    // 4-byte big-endian integer for the PT_ID value 
    224234     
    225235    bool bTime = false; 
    226     liblas::uint32_t record_size; 
    227     if (nDimension == 3) 
    228         record_size = ids.size() * (8*3+4+4); 
    229     else if (nDimension == 4) 
    230     { 
    231         record_size = ids.size() * (8*4+4+4); 
     236    if (nDimension == 4) 
     237    { 
    232238        bTime = true; 
    233239    } 
    234     else 
    235         // throw a big error 
    236         throw std::runtime_error("Dimension must be 3 or 4"); 
    237  
     240     
    238241    vector<liblas::uint8_t>* output = new vector<liblas::uint8_t>; 
    239     output->resize(record_size); 
    240242     
    241243    list<SpatialIndex::id_type>::const_iterator i; 
    242244    vector<liblas::uint8_t>::iterator pi; 
    243      
    244245     
    245246    liblas::uint32_t block_id = result.GetID(); 
     
    254255        if (doRead) { 
    255256            LASPoint const& p = reader->GetPoint(); 
     257 
     258            // d 8-byte IEEE  big-endian doubles, where d is the PC_TOT_DIMENSIONS value 
    256259            bool gotdata = GetPointData(p, bTime, point_data); 
    257              
     260 
    258261            std::vector<liblas::uint8_t>::const_iterator d; 
    259262            for (d = point_data.begin(); d!=point_data.end(); d++) { 
    260263                output->push_back(*d); 
    261264            } 
    262             // pi = std::copy(point_data->begin(), point_data->end(), pi); 
     265 
    263266            liblas::uint8_t* id_b = reinterpret_cast<liblas::uint8_t*>(&id); 
    264267            liblas::uint8_t* block_b = reinterpret_cast<liblas::uint8_t*>(&block_id); 
    265268             
    266             // add 4-byte big endian integers 
    267             output->push_back(id_b[3]); 
    268             output->push_back(id_b[2]); 
    269             output->push_back(id_b[1]); 
    270             output->push_back(id_b[0]); 
     269            // 4-byte big-endian integer for the BLK_ID value 
     270            for (int i =  sizeof(liblas::uint32_t) - 1; i >= 0; i--) { 
     271                output->push_back(block_b[i]); 
     272            } 
    271273             
    272             output->push_back(block_b[3]); 
    273             output->push_back(block_b[2]); 
    274             output->push_back(block_b[1]); 
    275             output->push_back(block_b[0]); 
    276  
    277         } 
    278     } 
     274            // 4-byte big-endian integer for the PT_ID value 
     275            for (int i =  sizeof(liblas::uint32_t) - 1; i >= 0; i--) { 
     276                output->push_back(id_b[i]); 
     277            } 
     278             
     279 
     280        } 
     281    } 
     282 
    279283    return output; 
    280284} 
     
    312316    // we only expect one blob to come back 
    313317    OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 ); 
    314      
    315318 
    316319    statement = connection->CreateStatement(oss.str().c_str()); 
     
    333336     
    334337 
    335     liblas::uint32_t num_bytes = 0; 
    336338    std::vector<liblas::uint8_t>* data = GetResultData(result, reader, 3); 
    337     std::cout << "Data size: " << data->size() << std::endl; 
    338     // liblas::uint8_t *bytes = (liblas::uint8_t*) new liblas::uint8_t[data->size()]; 
    339     // memcpy( (void*)&(bytes[0]), (void*)data[0], data->size() ); 
    340     // liblas::uint8_t *bytes; 
    341     int anumber = data->size(); 
    342  
    343     // liblas::uint8_t *bytes2 = (liblas::uint8_t*) new liblas::uint8_t[data.size()]; 
    344     // memset( bytes2, 0, data.size()); 
    345  
    346 //         int nBytesRead = statement->ReadBlob( locator[0], 
    347 //                                             (void*)data, 
    348 //                                             anumber ); 
    349  
    350  
    351 // this could be writing junk 
    352 liblas::uint32_t num_bytes_written = statement->WriteBlob( locator[0], 
    353                                          data, 
    354                                         anumber ); 
     339 
     340    liblas::uint8_t *bytes = (liblas::uint8_t*) new liblas::uint8_t[data->size()]; 
     341 
     342    std::vector<liblas::uint8_t>::const_iterator f; 
     343    int j = 0; 
     344    for (f=data->begin(); f!=data->end(); f++) { 
     345        bytes[j] = *f; 
     346        j++; 
     347    } 
     348 
     349    liblas::uint32_t wroteblob = statement->WriteBlob(  locator[0], 
     350                                                        bytes, 
     351                                                        data->size()); 
     352     
     353    if (! wroteblob) throw std::runtime_error("No blob bytes could be written!"); 
     354//select dbms_lob.getlength(points) from TO_core_last_clip 
     355    OWStatement::Free(locator, 1); 
    355356 
    356357    delete statement; 
    357     // OWStatement::Free(locator, 1); 
    358     // exit(0); 
     358     
     359    delete bytes; 
     360    delete data; 
     361     
    359362    return true; 
    360363 
     
    454457void usage() {} 
    455458 
     459// select sdo_pc_pkg.to_geometry(a.points, a.num_points, 3, 8307) from NACHES_BAREEARTH_BLOCK1 a where a.obj_id= 8907 
    456460int main(int argc, char* argv[]) 
    457461{ 
     
    550554    instance = connection.substr(at_pos+1); 
    551555    std::cout << "Connecting with username: " << username << " password: "<< password<< " instance: " << instance << std::endl;     
     556 
     557    // OCI_SUCCESS_WITH_INFO error, which according to google relates to  
     558    // a warning related to expired or expiring passwords needs to be  
     559    // handled in the oracle wrapper. 
     560     
     561    // Create the index before connecting to Oracle.  That way we don't heartbeat 
     562    // the server while we're cruising through the file(s). 
     563     
     564    // OS X RAMDISK configuration 
     565    // http://www.macosxhints.com/article.php?story=20090222092827145 
     566     
     567    // Obj_id is serial for each row in the block table 
     568    // blk_id is the index leaf node id (this is currently being written incorrectly) 
    552569    OWConnection* con = new OWConnection(username.c_str(),password.c_str(),instance.c_str()); 
    553570    if (con->Succeeded()) { 
     
    571588     
    572589    // change filename foo.las -> foo for an appropriate 
    573     // tablename for oracle 
     590    // block tablename for oracle... must be less than 30 characters 
     591    // and no extraneous characters. 
     592     
     593    // We need an option for the user to specify the blk tablename 
    574594    string::size_type dot_pos = input.find_first_of("."); 
    575595    string table_name = input.substr(0,dot_pos); 
Note: See TracChangeset for help on using the changeset viewer.