From b9dfa1133da52b693a4a2c73d2b2080fbb6b1043 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 15 Jan 2025 02:23:33 +0100 Subject: [PATCH] VRT: advertize expression dialects in 'ExpressionDialects' driver metadata item --- autotest/pymod/gdaltest.py | 18 +----------------- frmts/vrt/vrtdriver.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/autotest/pymod/gdaltest.py b/autotest/pymod/gdaltest.py index 185e43d20872..5e7cbedb3180 100755 --- a/autotest/pymod/gdaltest.py +++ b/autotest/pymod/gdaltest.py @@ -2140,20 +2140,4 @@ def handler(lvl, no, msg): @functools.lru_cache() def gdal_has_vrt_expression_dialect(dialect): - with disable_exceptions(), gdal.quiet_errors(): - vrt = f""" - - expression - - - - Float64 - - - 10 - - - - """ - ds = gdal.Open(vrt) - return ds.ReadRaster() is not None + return dialect in gdal.GetDriverByName("VRT").GetMetadataItem("ExpressionDialects") diff --git a/frmts/vrt/vrtdriver.cpp b/frmts/vrt/vrtdriver.cpp index 14db8591e6fe..6a4eb013f690 100644 --- a/frmts/vrt/vrtdriver.cpp +++ b/frmts/vrt/vrtdriver.cpp @@ -552,6 +552,17 @@ void GDALRegister_VRT() poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); poDriver->SetMetadataItem(GDAL_DCAP_COORDINATE_EPOCH, "YES"); + const char *pszExpressionDialects = "ExpressionDialects"; +#if defined(GDAL_VRT_ENABLE_MUPARSER) && defined(GDAL_VRT_ENABLE_EXPRTK) + poDriver->SetMetadataItem(pszExpressionDialects, "muparser,exprtk"); +#elif defined(GDAL_VRT_ENABLE_MUPARSER) + poDriver->SetMetadataItem(pszExpressionDialects, "muparser"); +#elif defined(GDAL_VRT_ENABLE_EXPRTK) + poDriver->SetMetadataItem(pszExpressionDialects, "exprtk"); +#else + poDriver->SetMetadataItem(pszExpressionDialects, "none"); +#endif + poDriver->AddSourceParser("SimpleSource", VRTParseCoreSources); poDriver->AddSourceParser("ComplexSource", VRTParseCoreSources); poDriver->AddSourceParser("AveragedSource", VRTParseCoreSources);