diff options
| author | Guilhem Moulin <guilhem@fripost.org> | 2026-03-06 09:00:51 +0100 |
|---|---|---|
| committer | Guilhem Moulin <guilhem@fripost.org> | 2026-03-06 09:37:51 +0100 |
| commit | 2fa39019cd4bbe0c221b084a9bd17698f8ffd767 (patch) | |
| tree | d63e1b73434a6a239251907b86680cf30f4f6af8 /common_gdal.py | |
| parent | f2393202a5343dcaeffdbec518aa241573185335 (diff) | |
Add wrapper for gdal.Dataset.ExecuteSQL().
Diffstat (limited to 'common_gdal.py')
| -rw-r--r-- | common_gdal.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/common_gdal.py b/common_gdal.py index 401e0a5..b5570eb 100644 --- a/common_gdal.py +++ b/common_gdal.py @@ -371,3 +371,13 @@ def getEscapedTableName(lyr : ogr.Layer, extract_schema_from_layer_name : bool = if lyr.GetDataset().GetDriver().ShortName == 'PostgreSQL': return getEscapedTableNamePG(layername, extract_schema_from_layer_name) return escape_identifier(layername) + +def executeSQL(ds : gdal.Dataset, statement : str, + spatialFilter : Optional[ogr.Geometry] = None) -> ogr.Layer|None: + """Wrapper for gdal.Dataset.ExecuteSQL(). + https://gdal.org/en/stable/api/python/raster_api.html#osgeo.gdal.Dataset.ExecuteSQL""" + msg = statement + if spatialFilter is not None: + msg += ', spatialFilter=' + spatialFilter.ExportToWkt() + logging.debug('ExecuteSQL(%s)', msg) + return ds.ExecuteSQL(statement, spatialFilter=spatialFilter) |
