| 435 | |
| 436 | |
| 437 | void TIndexKernel::mergeFile() |
| 438 | { |
| 439 | using namespace gdal; |
| 440 | |
| 441 | std::ostringstream out; |
| 442 | |
| 443 | if (!openDataset(m_idxFilename)) |
| 444 | { |
| 445 | std::ostringstream out; |
| 446 | out << "Couldn't open index dataset file '" << m_idxFilename << "'."; |
| 447 | throw pdal_error(out.str()); |
| 448 | } |
| 449 | if (!openLayer(m_layerName)) |
| 450 | { |
| 451 | std::ostringstream out; |
| 452 | out << "Couldn't open layer '" << m_layerName << |
| 453 | "' in output file '" << m_idxFilename << "'."; |
| 454 | throw pdal_error(out.str()); |
| 455 | } |
| 456 | |
| 457 | FieldIndexes indexes = getFields(); |
| 458 | |
| 459 | if (!m_wkt.empty()) |
| 460 | { |
| 461 | pdal::Polygon g(m_wkt, m_tgtSrsString); |
| 462 | OGR_L_SetSpatialFilter(m_layer, g.getOGRHandle()); |
| 463 | } |
| 464 | |
| 465 | std::vector<FileInfo> files; |
| 466 | |
| 467 | // Docs are bad here. You need this call even if you haven't read anything |
| 468 | // or nothing happens. |
| 469 | OGR_L_ResetReading(m_layer); |
| 470 | while (true) |
| 471 | { |
| 472 | OGRFeatureH feature = OGR_L_GetNextFeature(m_layer); |
| 473 | if (!feature) |
| 474 | break; |
| 475 | |
| 476 | FileInfo fileInfo; |
| 477 | fileInfo.m_filename = |
| 478 | OGR_F_GetFieldAsString(feature, indexes.m_filename); |
| 479 | fileInfo.m_srs = |
| 480 | OGR_F_GetFieldAsString(feature, indexes.m_srs); |
| 481 | files.push_back(fileInfo); |
| 482 | |
| 483 | OGR_F_Destroy(feature); |
| 484 | } |
| 485 | |
| 486 | OGR_DS_Destroy(m_dataset); |
| 487 | m_dataset = nullptr; |
| 488 | m_layer = nullptr; |
| 489 | |
| 490 | m_log->get(LogLevel::Info) << "Merge filecount: " << |
| 491 | files.size() << std::endl; |
| 492 | |
| 493 | Options cropOptions; |
| 494 | if (!m_bounds.empty()) |