Return a list of driver short names that are likely candidates for the * provided output file name. * * @param pszDestDataset Output dataset name (might not exist). * @param nDatasetTypeFlag GDAL_OF_RASTER, GDAL_OF_VECTOR, GDAL_OF_MULTIDIM_RASTER * or a binary-or'ed combination of them * @param bSingleMatch Whether a single match is desired, that is to say the *
| 3208 | * @since 3.9 |
| 3209 | */ |
| 3210 | char **GDALGetOutputDriversForDatasetName(const char *pszDestDataset, |
| 3211 | int nDatasetTypeFlag, |
| 3212 | bool bSingleMatch, bool bEmitWarning) |
| 3213 | { |
| 3214 | CPLStringList aosDriverNames; |
| 3215 | CPLStringList aosMissingDriverNames; |
| 3216 | |
| 3217 | std::string osExt = CPLGetExtensionSafe(pszDestDataset); |
| 3218 | if (EQUAL(osExt.c_str(), "zip")) |
| 3219 | { |
| 3220 | const CPLString osLower(CPLString(pszDestDataset).tolower()); |
| 3221 | if (osLower.endsWith(".shp.zip")) |
| 3222 | { |
| 3223 | osExt = "shp.zip"; |
| 3224 | } |
| 3225 | else if (osLower.endsWith(".gpkg.zip")) |
| 3226 | { |
| 3227 | osExt = "gpkg.zip"; |
| 3228 | } |
| 3229 | } |
| 3230 | else if (EQUAL(osExt.c_str(), "json")) |
| 3231 | { |
| 3232 | const CPLString osLower(CPLString(pszDestDataset).tolower()); |
| 3233 | if (osLower.endsWith(".gdalg.json")) |
| 3234 | return nullptr; |
| 3235 | } |
| 3236 | |
| 3237 | auto poDM = GetGDALDriverManager(); |
| 3238 | const int nDriverCount = poDM->GetDriverCount(true); |
| 3239 | GDALDriver *poMissingPluginDriver = nullptr; |
| 3240 | std::string osMatchingPrefix; |
| 3241 | for (int i = 0; i < nDriverCount; i++) |
| 3242 | { |
| 3243 | GDALDriver *poDriver = poDM->GetDriver(i, true); |
| 3244 | bool bOk = false; |
| 3245 | if ((poDriver->GetMetadataItem(GDAL_DCAP_CREATE) != nullptr || |
| 3246 | poDriver->GetMetadataItem(GDAL_DCAP_CREATECOPY) != nullptr || |
| 3247 | poDriver->GetMetadataItem(GDAL_DCAP_UPDATE) != nullptr) && |
| 3248 | (((nDatasetTypeFlag & GDAL_OF_RASTER) && |
| 3249 | poDriver->GetMetadataItem(GDAL_DCAP_RASTER) != nullptr) || |
| 3250 | ((nDatasetTypeFlag & GDAL_OF_VECTOR) && |
| 3251 | poDriver->GetMetadataItem(GDAL_DCAP_VECTOR) != nullptr) || |
| 3252 | ((nDatasetTypeFlag & GDAL_OF_MULTIDIM_RASTER) && |
| 3253 | poDriver->GetMetadataItem(GDAL_DCAP_MULTIDIM_RASTER) != nullptr))) |
| 3254 | { |
| 3255 | bOk = true; |
| 3256 | } |
| 3257 | else if (poDriver->GetMetadataItem(GDAL_DCAP_VECTOR_TRANSLATE_FROM) && |
| 3258 | (nDatasetTypeFlag & GDAL_OF_VECTOR) != 0) |
| 3259 | { |
| 3260 | bOk = true; |
| 3261 | } |
| 3262 | if (bOk) |
| 3263 | { |
| 3264 | if (!osExt.empty() && |
| 3265 | DoesDriverHandleExtension(GDALDriver::ToHandle(poDriver), |
| 3266 | osExt.c_str())) |
| 3267 | { |
no test coverage detected