| 27 | /************************************************************************/ |
| 28 | |
| 29 | GDALVectorRenameLayerAlgorithm::GDALVectorRenameLayerAlgorithm( |
| 30 | bool standaloneStep) |
| 31 | : GDALVectorPipelineStepAlgorithm( |
| 32 | NAME, DESCRIPTION, HELP_URL, |
| 33 | ConstructorOptions() |
| 34 | .SetStandaloneStep(standaloneStep) |
| 35 | .SetAddInputLayerNameArgument(false) |
| 36 | .SetOutputLayerNameAvailableInPipelineStep(true)) |
| 37 | { |
| 38 | AddLayerNameArg(&m_inputLayerName); |
| 39 | if (!standaloneStep) |
| 40 | { |
| 41 | AddOutputLayerNameArg(/* hiddenForCLI = */ false, |
| 42 | /* shortNameOutputLayerAllowed = */ false); |
| 43 | } |
| 44 | AddArg("ascii", 0, _("Force names to ASCII character"), &m_ascii); |
| 45 | AddArg("lower-case", 0, |
| 46 | _("Force names to lower case (only on ASCII characters)"), |
| 47 | &m_lowerCase); |
| 48 | AddArg("filename-compatible", 0, _("Force names to be usable as filenames"), |
| 49 | &m_filenameCompatible); |
| 50 | AddArg("reserved-characters", 0, _("Reserved character(s) to be removed"), |
| 51 | &m_reservedChars); |
| 52 | AddArg("replacement-character", 0, |
| 53 | _("Replacement character when ASCII conversion not possible"), |
| 54 | &m_replacementChar) |
| 55 | .SetMaxCharCount(1); |
| 56 | AddArg("max-length", 0, _("Maximum length of layer names"), &m_maxLength) |
| 57 | .SetMinValueIncluded(1); |
| 58 | |
| 59 | AddValidationAction( |
| 60 | [this]() |
| 61 | { |
| 62 | if (!m_inputLayerName.empty() && m_outputLayerName.empty()) |
| 63 | { |
| 64 | ReportError(CE_Failure, CPLE_AppDefined, |
| 65 | "Argument output-layer must be specified when " |
| 66 | "input-layer is specified"); |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | if (!m_inputDataset.empty() && m_inputDataset[0].GetDatasetRef()) |
| 71 | { |
| 72 | auto poSrcDS = m_inputDataset[0].GetDatasetRef(); |
| 73 | if (!m_inputLayerName.empty() && |
| 74 | poSrcDS->GetLayerByName(m_inputLayerName.c_str()) == |
| 75 | nullptr) |
| 76 | { |
| 77 | ReportError(CE_Failure, CPLE_AppDefined, |
| 78 | "Input layer '%s' does not exist", |
| 79 | m_inputLayerName.c_str()); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | if (!m_outputLayerName.empty() && m_inputLayerName.empty() && |
| 84 | poSrcDS->GetLayerCount() >= 2) |
| 85 | { |
| 86 | ReportError(CE_Failure, CPLE_AppDefined, |
nothing calls this directly
no test coverage detected