Skip to content

Commit

Permalink
Merge pull request #11656 from rouault/ExpressionDialects
Browse files Browse the repository at this point in the history
VRT: advertize expression dialects in 'ExpressionDialects' driver metadata item
  • Loading branch information
rouault authored Jan 16, 2025
2 parents 5d2f918 + b9dfa11 commit a16d29c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 1 addition & 17 deletions autotest/pymod/gdaltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<VRTDataset rasterXSize="20" rasterYSize="20">
<VRTRasterBand dataType="Float64" band="1" subClass="VRTDerivedRasterBand">
<PixelFunctionType>expression</PixelFunctionType>
<PixelFunctionArguments expression="B1 + 5" dialect="{dialect}"/>
<ArraySource>
<Array name="test">
<DataType>Float64</DataType>
<Dimension name="Y" size="20"/>
<Dimension name="X" size="20"/>
<ConstantValue>10</ConstantValue>
</Array>
</ArraySource>
</VRTRasterBand>
</VRTDataset>"""
ds = gdal.Open(vrt)
return ds.ReadRaster() is not None
return dialect in gdal.GetDriverByName("VRT").GetMetadataItem("ExpressionDialects")
11 changes: 11 additions & 0 deletions frmts/vrt/vrtdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a16d29c

Please sign in to comment.