Changeset 1241:2b6bba71a3ab
- Timestamp:
- 07/09/09 10:51:33 (13 months ago)
- Branch:
- default
- Convert:
- svn:1766ff46-f334-0410-ab20-d63176f87757/trunk@1308
- File:
-
- 1 edited
-
apps/las2oci.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
apps/las2oci.cpp
r1240 r1241 177 177 { 178 178 // 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(); 184 182 185 183 double x = p.GetX(); … … 196 194 // doubles are 8 bytes long. For each double, push back the 197 195 // 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--) { 199 205 point_data.push_back(x_b[i]); 200 206 } 201 for (int i=0; i<8; i++) { 207 208 for (int i = sizeof(double) - 1; i >= 0; i--) { 202 209 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--) { 205 213 point_data.push_back(z_b[i]); 206 214 } 215 207 216 208 217 if (bTime) 209 218 { 210 for (int i =0; i<8; i++) {219 for (int i = sizeof(double) - 1; i >= 0; i--) { 211 220 point_data.push_back(t_b[i]); 212 221 } 213 } 214 return data; 222 223 } 224 225 return true; 215 226 } 216 227 std::vector<liblas::uint8_t>* GetResultData(const LASQueryResult& result, LASReader* reader, int nDimension) 217 228 { 218 229 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 222 232 // 4-byte big-endian integer for the BLK_ID value 223 233 // 4-byte big-endian integer for the PT_ID value 224 234 225 235 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 { 232 238 bTime = true; 233 239 } 234 else 235 // throw a big error 236 throw std::runtime_error("Dimension must be 3 or 4"); 237 240 238 241 vector<liblas::uint8_t>* output = new vector<liblas::uint8_t>; 239 output->resize(record_size);240 242 241 243 list<SpatialIndex::id_type>::const_iterator i; 242 244 vector<liblas::uint8_t>::iterator pi; 243 244 245 245 246 liblas::uint32_t block_id = result.GetID(); … … 254 255 if (doRead) { 255 256 LASPoint const& p = reader->GetPoint(); 257 258 // d 8-byte IEEE big-endian doubles, where d is the PC_TOT_DIMENSIONS value 256 259 bool gotdata = GetPointData(p, bTime, point_data); 257 260 258 261 std::vector<liblas::uint8_t>::const_iterator d; 259 262 for (d = point_data.begin(); d!=point_data.end(); d++) { 260 263 output->push_back(*d); 261 264 } 262 // pi = std::copy(point_data->begin(), point_data->end(), pi); 265 263 266 liblas::uint8_t* id_b = reinterpret_cast<liblas::uint8_t*>(&id); 264 267 liblas::uint8_t* block_b = reinterpret_cast<liblas::uint8_t*>(&block_id); 265 268 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 } 271 273 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 279 283 return output; 280 284 } … … 312 316 // we only expect one blob to come back 313 317 OCILobLocator** locator =(OCILobLocator**) VSIMalloc( sizeof(OCILobLocator*) * 1 ); 314 315 318 316 319 statement = connection->CreateStatement(oss.str().c_str()); … … 333 336 334 337 335 liblas::uint32_t num_bytes = 0;336 338 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); 355 356 356 357 delete statement; 357 // OWStatement::Free(locator, 1); 358 // exit(0); 358 359 delete bytes; 360 delete data; 361 359 362 return true; 360 363 … … 454 457 void usage() {} 455 458 459 // select sdo_pc_pkg.to_geometry(a.points, a.num_points, 3, 8307) from NACHES_BAREEARTH_BLOCK1 a where a.obj_id= 8907 456 460 int main(int argc, char* argv[]) 457 461 { … … 550 554 instance = connection.substr(at_pos+1); 551 555 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) 552 569 OWConnection* con = new OWConnection(username.c_str(),password.c_str(),instance.c_str()); 553 570 if (con->Succeeded()) { … … 571 588 572 589 // 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 574 594 string::size_type dot_pos = input.find_first_of("."); 575 595 string table_name = input.substr(0,dot_pos);
Note: See TracChangeset
for help on using the changeset viewer.
