| 580 | } |
| 581 | |
| 582 | OGRLayer *GetOutputLayer(bool createValueField) |
| 583 | { |
| 584 | const OGRGeomFieldDefn *poGeomDefn = nullptr; |
| 585 | if (m_options.include_geom) |
| 586 | { |
| 587 | const OGRFeatureDefn *poSrcDefn = |
| 588 | std::get<OGRLayer *>(m_zones)->GetLayerDefn(); |
| 589 | poGeomDefn = poSrcDefn->GetGeomFieldDefn(0); |
| 590 | } |
| 591 | |
| 592 | OGRLayer *poLayer = |
| 593 | m_dst.CreateLayer(m_options.output_layer.c_str(), poGeomDefn, |
| 594 | m_options.layer_creation_options.List()); |
| 595 | if (!poLayer) |
| 596 | return nullptr; |
| 597 | |
| 598 | if (createValueField) |
| 599 | { |
| 600 | OGRFieldDefn oFieldDefn("value", OFTReal); |
| 601 | if (poLayer->CreateField(&oFieldDefn) != OGRERR_NONE) |
| 602 | return nullptr; |
| 603 | } |
| 604 | |
| 605 | if (!m_options.include_fields.empty()) |
| 606 | { |
| 607 | const OGRFeatureDefn *poSrcDefn = |
| 608 | std::get<OGRLayer *>(m_zones)->GetLayerDefn(); |
| 609 | |
| 610 | for (const auto &field : m_options.include_fields) |
| 611 | { |
| 612 | const int iField = poSrcDefn->GetFieldIndex(field.c_str()); |
| 613 | // Already checked field names during Init() |
| 614 | if (poLayer->CreateField(poSrcDefn->GetFieldDefn(iField)) != |
| 615 | OGRERR_NONE) |
| 616 | return nullptr; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | for (int iBand : m_options.bands) |
| 621 | { |
| 622 | auto &aiStatFields = m_statFields[iBand]; |
| 623 | aiStatFields.fill(-1); |
| 624 | |
| 625 | for (const auto &stat : m_options.stats) |
| 626 | { |
| 627 | const Stat eStat = GetStat(stat); |
| 628 | |
| 629 | std::string osFieldName; |
| 630 | if (m_options.bands.size() > 1) |
| 631 | { |
| 632 | osFieldName = CPLSPrintf("%s_band_%d", stat.c_str(), iBand); |
| 633 | } |
| 634 | else |
| 635 | { |
| 636 | osFieldName = stat; |
| 637 | } |
| 638 | |
| 639 | OGRFieldDefn oFieldDefn(osFieldName.c_str(), |
no test coverage detected