aboutsummaryrefslogtreecommitdiffstats
path: root/import_source.py
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2025-08-14 13:46:48 +0200
committerGuilhem Moulin <guilhem@fripost.org>2025-08-14 16:02:20 +0200
commit27fc0d1bfdefbc69450781c16bb43198b857f95d (patch)
treee3c3505bc5cec12b845e7213d6458db00dc315ca /import_source.py
parent878d693d3cda9dc667508889732614bdd9e31abd (diff)
Use .GetDataSet() from gdal ≥3.9 instead of passing the ds around.
Diffstat (limited to 'import_source.py')
-rw-r--r--import_source.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/import_source.py b/import_source.py
index 8a8ff1a..f103ce8 100644
--- a/import_source.py
+++ b/import_source.py
@@ -363,7 +363,7 @@ def validateOutputLayer(lyr : ogr.Layer,
return ok
-def clearLayer(ds : gdal.Dataset, lyr : ogr.Layer) -> None:
+def clearLayer(lyr : ogr.Layer) -> None:
"""Clear the given layer (wipe all its features)"""
n = -1
if lyr.TestCapability(ogr.OLCFastFeatureCount):
@@ -373,7 +373,7 @@ def clearLayer(ds : gdal.Dataset, lyr : ogr.Layer) -> None:
return
layername_esc = escape_identifier(lyr.GetName())
- # XXX GDAL <3.9 doesn't have lyr.GetDataset() so we pass the DS along with the layer
+ ds = lyr.GetDataset()
drv = ds.GetDriver()
if drv.ShortName == 'PostgreSQL':
# https://www.postgresql.org/docs/15/sql-truncate.html
@@ -454,7 +454,7 @@ class ImportStatus(Enum):
return self.name.removeprefix('IMPORT_')
# pylint: disable-next=dangerous-default-value
-def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
+def importSources(lyr : ogr.Layer,
sources : dict[str,Any] = {},
cachedir : Path|None = None,
extent : ogr.Geometry|None = None,
@@ -463,6 +463,7 @@ def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
force : bool = False) -> ImportStatus:
"""Clear lyr and import source layers to it."""
+ dso = lyr.GetDataset()
layername = lyr.GetName()
if dsoTransaction:
# declare a SAVEPOINT (nested transaction) within the DS-level transaction
@@ -483,7 +484,7 @@ def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
rv = ImportStatus.IMPORT_NOCHANGE
now = datetime.now().astimezone()
try:
- clearLayer(dso, lyr) # TODO conditional (only if not new)?
+ clearLayer(lyr) # TODO conditional (only if not new)?
for source in sources:
importSource0(lyr, **source['source'],
@@ -499,7 +500,7 @@ def importSources(dso : gdal.Dataset, lyr : ogr.Layer,
if lyrcache is None:
rv = ImportStatus.IMPORT_SUCCESS
elif updateLayerCache(cache=lyrcache,
- ds=dso, lyr=lyr,
+ lyr=lyr,
force=force,
lyrTransaction=lyrTransaction,
last_updated=now):
@@ -912,7 +913,7 @@ def listFieldsOrderBy(defn : ogr.FeatureDefn,
yield c
# pylint: disable-next=too-many-branches, too-many-statements
-def updateLayerCache(ds : gdal.Dataset, lyr : ogr.Layer, cache : ogr.Layer,
+def updateLayerCache(lyr : ogr.Layer, cache : ogr.Layer,
last_updated : datetime,
lyrTransaction : str|bool|None = None,
force : bool = False) -> bool:
@@ -960,6 +961,7 @@ def updateLayerCache(ds : gdal.Dataset, lyr : ogr.Layer, cache : ogr.Layer,
struct_dgst : Final = struct.Struct('@qq').pack
logging.debug('%s', query)
+ ds = lyr.GetDataset()
lyr2 = ds.ExecuteSQL(query)
try:
assert lyr2.GetLayerDefn().GetFieldDefn(0).GetName() == 'hash_properties'