-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement RFC 104: Adding a "gdal" front-end command line interface
- Loading branch information
Showing
54 changed files
with
13,908 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/****************************************************************************** | ||
* | ||
* Project: GDAL | ||
* Purpose: CLI front-end | ||
* Author: Even Rouault <even dot rouault at spatialys.com> | ||
* | ||
****************************************************************************** | ||
* Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com> | ||
* | ||
* SPDX-License-Identifier: MIT | ||
****************************************************************************/ | ||
|
||
#include "gdalalgorithm.h" | ||
#include "commonutils.h" | ||
|
||
#include "gdal.h" | ||
|
||
#include <cassert> | ||
|
||
/************************************************************************/ | ||
/* main() */ | ||
/************************************************************************/ | ||
|
||
MAIN_START(argc, argv) | ||
{ | ||
EarlySetConfigOptions(argc, argv); | ||
|
||
/* -------------------------------------------------------------------- */ | ||
/* Register standard GDAL drivers, and process generic GDAL */ | ||
/* command options. */ | ||
/* -------------------------------------------------------------------- */ | ||
|
||
GDALAllRegister(); | ||
argc = GDALGeneralCmdLineProcessor(argc, &argv, 0); | ||
if (argc < 1) | ||
return (-argc); | ||
|
||
auto alg = GDALGlobalAlgorithmRegistry::GetSingleton().Instantiate( | ||
GDALGlobalAlgorithmRegistry::ROOT_ALG_NAME); | ||
assert(alg); | ||
alg->SetCallPath(std::vector<std::string>{argv[0]}); | ||
std::vector<std::string> args; | ||
for (int i = 1; i < argc; ++i) | ||
args.push_back(argv[i]); | ||
|
||
if (!alg->ParseCommandLineArguments(args)) | ||
{ | ||
fprintf(stderr, "%s", alg->GetUsageForCLI(true).c_str()); | ||
CSLDestroy(argv); | ||
return 1; | ||
} | ||
|
||
{ | ||
const auto stdoutArg = alg->GetActualAlgorithm().GetArg("stdout"); | ||
if (stdoutArg && stdoutArg->GetType() == GAAT_BOOLEAN) | ||
stdoutArg->Set(true); | ||
} | ||
|
||
GDALProgressFunc pfnProgress = | ||
alg->IsProgressBarRequested() ? GDALTermProgress : nullptr; | ||
void *pProgressData = nullptr; | ||
|
||
int ret = 0; | ||
if (alg->Run(pfnProgress, pProgressData) && alg->Finalize()) | ||
{ | ||
const auto outputArg = | ||
alg->GetActualAlgorithm().GetArg("output-string"); | ||
if (outputArg && outputArg->GetType() == GAAT_STRING && | ||
outputArg->IsOutput()) | ||
{ | ||
printf("%s", outputArg->Get<std::string>().c_str()); | ||
} | ||
} | ||
else | ||
{ | ||
ret = 1; | ||
} | ||
|
||
CSLDestroy(argv); | ||
|
||
return ret; | ||
} | ||
|
||
MAIN_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/****************************************************************************** | ||
* | ||
* Project: GDAL | ||
* Purpose: gdal "convert" subcommand | ||
* Author: Even Rouault <even dot rouault at spatialys.com> | ||
* | ||
****************************************************************************** | ||
* Copyright (c) 2024, Even Rouault <even dot rouault at spatialys.com> | ||
* | ||
* SPDX-License-Identifier: MIT | ||
****************************************************************************/ | ||
|
||
#include "cpl_error.h" | ||
#include "gdalalgorithm.h" | ||
#include "gdalalg_raster_convert.h" | ||
#include "gdalalg_vector_convert.h" | ||
#include "gdalalg_dispatcher.h" | ||
#include "gdal_priv.h" | ||
|
||
/************************************************************************/ | ||
/* GDALConvertAlgorithm */ | ||
/************************************************************************/ | ||
|
||
class GDALConvertAlgorithm | ||
: public GDALDispatcherAlgorithm<GDALRasterConvertAlgorithm, | ||
GDALVectorConvertAlgorithm> | ||
{ | ||
public: | ||
static constexpr const char *NAME = "convert"; | ||
static constexpr const char *DESCRIPTION = | ||
"Convert a dataset (shortcut for 'gdal raster convert' or " | ||
"'gdal vector convert')."; | ||
static constexpr const char *HELP_URL = ""; // TODO | ||
|
||
static std::vector<std::string> GetAliases() | ||
{ | ||
return {}; | ||
} | ||
|
||
GDALConvertAlgorithm() | ||
: GDALDispatcherAlgorithm(NAME, DESCRIPTION, HELP_URL) | ||
{ | ||
// only for the help message | ||
AddProgressArg(); | ||
AddOutputFormatArg(&m_format); | ||
AddInputDatasetArg(&m_inputDataset); | ||
AddOutputDatasetArg(&m_outputDataset); | ||
|
||
m_longDescription = "For all options, run 'gdal raster convert --help' " | ||
"or 'gdal vector convert --help'"; | ||
} | ||
|
||
private: | ||
std::string m_format{}; | ||
GDALArgDatasetValue m_inputDataset{}; | ||
GDALArgDatasetValue m_outputDataset{}; | ||
}; | ||
|
||
GDAL_STATIC_REGISTER_ALG(GDALConvertAlgorithm); |
Oops, something went wrong.