From e930cd95f3392b44152ae05b4189c65e833adaa3 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 20 Jun 2024 15:40:13 +0200 Subject: Conditionally use GetTZFlag()/SetTZFlag() depending on the GDAL version. OGRFieldDefn: add GetComment() / SetComment() methods were added in OGR 3.8.0, cf. https://github.com/OSGeo/gdal/blob/master/NEWS.md#core-3 . Don't comment out TZ on field definitions. Instead we check the GDAL/OGR version and ignore TZ on field definitions if the OGR version is too old. --- config.yml | 4 ++-- webmap-import | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/config.yml b/config.yml index d95e663..72a735e 100644 --- a/config.yml +++ b/config.yml @@ -264,7 +264,7 @@ layers: comment: Globalt unik identitet för generaliserat objekt - name: skapad type: DateTime - #tz: local + tz: local comment: Tidpunkt när objektet ändrades - name: lanskod type: Integer @@ -302,7 +302,7 @@ layers: comment: Globalt unik identitet för generaliserat objekt - name: skapad type: DateTime - #tz: local + tz: local comment: Tidpunkt när objektet ändrades - name: kommunkod type: Integer diff --git a/webmap-import b/webmap-import index ffc24a2..6502c8f 100755 --- a/webmap-import +++ b/webmap-import @@ -342,6 +342,7 @@ def validateSchema(layers, drvo=None, lco_defaults=None): # Cf. https://github.com/OSGeo/gdal/blob/master/NEWS.md hasCommentSupport = common.gdal_version_min(maj=3, min=7) # GetComment()/SetComment() added in 3.7.0 + hasTZFlagSupport = common.gdal_version_min(maj=3, min=8) # GetTZFlag()/SetTZFlag() and OGR_TZFLAG_* constants added in 3.8.0 for layername, layerdef in layers.items(): create = layerdef.get('create', None) @@ -395,8 +396,11 @@ def validateSchema(layers, drvo=None, lco_defaults=None): elif k2 == 'subtype': fld_def2['SubType'] = parseSubFieldType(v) elif k2 == 'tz': - # (WARN support added in GDAL 3.8) - fld_def2['TZFlag'] = parseTimeZone(v) + if hasTZFlagSupport: + fld_def2['TZFlag'] = parseTimeZone(v) + else: + logging.debug('Ignoring TZ="%s" on field "%s" (OGR v%s is too old)', + v, fld_name, gdal.__version__) elif k2 == 'width' and v is not None and isinstance(v, int): fld_def2['Width'] = v elif k2 == 'precision' and v is not None and isinstance(v, int): -- cgit v1.2.3