Skip to content

Commit

Permalink
On older QGIS versions, we have to drop the FID and cannot rename
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 5, 2024
1 parent 21b7557 commit 80c7ae7
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions felt/core/layer_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from qgis.PyQt.QtXml import (
QDomDocument
)

from qgis.core import (
Qgis,
QgsDataSourceUri,
QgsFeedback,
QgsMapLayer,
Expand Down Expand Up @@ -54,13 +54,13 @@
LayerSupport
)
from .exceptions import LayerPackagingException
from .layer_style import LayerStyle
from .logger import Logger
from .map import Map
from .fsl_converter import (
FslConverter,
ConversionContext
)
from .layer_style import LayerStyle
from .logger import Logger
from .map import Map


@dataclass
Expand Down Expand Up @@ -370,10 +370,21 @@ def export_vector_layer(
writer_options.attributes = fields.allAttributesList()
if fid_index >= 0:
fid_type = fields.field(fid_index).type()
if force_rewrite_fid or fid_type not in (QVariant.Int,
QVariant.UInt,
QVariant.LongLong,
QVariant.ULongLong):
if (Qgis.QGIS_VERSION_INT < 32400 and
fid_type not in (
QVariant.Int,
QVariant.UInt,
QVariant.LongLong,
QVariant.ULongLong)):
# older QGIS, can't rename attributes during export, so
# drop FID
writer_options.attributes = [a for a in
writer_options.attributes if
a != fid_index]
elif force_rewrite_fid or fid_type not in (QVariant.Int,
QVariant.UInt,
QVariant.LongLong,
QVariant.ULongLong):
writer_options.attributesExportNames = [
f.name() if f.name().lower() != 'fid' else 'old_fid'
for f in fields]
Expand All @@ -388,7 +399,7 @@ def export_vector_layer(
)
# pylint: enable=unused-variable

if (not force_rewrite_fid and
if (Qgis.QGIS_VERSION_INT >= 32400 and not force_rewrite_fid and
res == QgsVectorFileWriter.WriterError.ErrFeatureWriteFailed):
# could not write attributes -- possibly eg due to duplicate
# FIDs. Let's try with renaming FID
Expand Down

0 comments on commit 80c7ae7

Please sign in to comment.