| 29 | /************************************************************************/ |
| 30 | |
| 31 | GDALRasterSelectAlgorithm::GDALRasterSelectAlgorithm(bool standaloneStep) |
| 32 | : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL, |
| 33 | standaloneStep) |
| 34 | { |
| 35 | { |
| 36 | auto &arg = AddArg("band", 'b', |
| 37 | _("Band(s) (1-based index, 'mask', 'mask:<band>' or " |
| 38 | "color interpretation such as 'red')"), |
| 39 | &m_bands) |
| 40 | .SetPositional() |
| 41 | .SetRequired() |
| 42 | .SetMinCount(1); |
| 43 | arg.SetAutoCompleteFunction( |
| 44 | [this](const std::string &) |
| 45 | { |
| 46 | std::vector<std::string> ret; |
| 47 | std::unique_ptr<GDALDataset> poSrcDSTmp; |
| 48 | GDALDataset *poSrcDS = m_inputDataset.empty() |
| 49 | ? nullptr |
| 50 | : m_inputDataset[0].GetDatasetRef(); |
| 51 | if (!poSrcDS && !m_inputDataset.empty()) |
| 52 | { |
| 53 | CPLErrorStateBackuper oBackuper(CPLQuietErrorHandler); |
| 54 | poSrcDSTmp.reset(GDALDataset::Open( |
| 55 | m_inputDataset[0].GetName().c_str(), GDAL_OF_RASTER)); |
| 56 | poSrcDS = poSrcDSTmp.get(); |
| 57 | } |
| 58 | if (poSrcDS) |
| 59 | { |
| 60 | std::set<GDALColorInterp> oSetColorInterp; |
| 61 | for (int i = 1; i <= poSrcDS->GetRasterCount(); ++i) |
| 62 | { |
| 63 | ret.push_back(std::to_string(i)); |
| 64 | oSetColorInterp.insert(poSrcDS->GetRasterBand(i) |
| 65 | ->GetColorInterpretation()); |
| 66 | } |
| 67 | ret.push_back("mask"); |
| 68 | for (const auto eColorInterp : oSetColorInterp) |
| 69 | { |
| 70 | ret.push_back(CPLString(GDALGetColorInterpretationName( |
| 71 | eColorInterp)) |
| 72 | .tolower()); |
| 73 | } |
| 74 | } |
| 75 | return ret; |
| 76 | }); |
| 77 | arg.AddValidationAction( |
| 78 | [&arg]() |
| 79 | { |
| 80 | int nColorInterpretations = 0; |
| 81 | const auto paeColorInterp = |
| 82 | GDALGetColorInterpretationList(&nColorInterpretations); |
| 83 | std::set<std::string> oSetValidColorInterp; |
| 84 | for (int i = 0; i < nColorInterpretations; ++i) |
| 85 | oSetValidColorInterp.insert( |
| 86 | CPLString( |
| 87 | GDALGetColorInterpretationName(paeColorInterp[i])) |
| 88 | .tolower()); |
nothing calls this directly
no test coverage detected