Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions libqfieldsync/offliners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from typing import Dict, List, NamedTuple, NewType, Optional

import qgis.core
from osgeo import gdal, ogr, osr
from qgis.core import (
Qgis,
Expand Down Expand Up @@ -113,6 +114,11 @@ def convert_to_offline(
if bbox and bbox.isFinite():
only_selected = True
for layer in layers:
if layer.type() != QgsMapLayer.LayerType.VectorLayer:
continue

assert isinstance(layer, QgsVectorLayer)

if Qgis.versionInt() >= 33000: # noqa: PLR2004
no_geometry_types = [
Qgis.GeometryType.Null,
Expand All @@ -131,8 +137,14 @@ def convert_to_offline(
layer.removeSelection()
else:
tr = QgsCoordinateTransform(project.crs(), layer.crs(), project)
layer_bbox = tr.transform(bbox)
layer.selectByRect(layer_bbox)

try:
layer_bbox = tr.transform(bbox)
layer.selectByRect(layer_bbox)
except qgis.core.QgsCsException as err:
logger.warning(
f"Failed to transform project CRS {project.crs().authid()} bbox to layer {layer.name()} CRS {layer.crs().authid()} bbox within `QgisCoreOffliner`: {err}. All features will be offlined for this layer."
)

# If the selection by BBOX did not select anything, make sure we fool `QgsOfflineEditing` something is selected.
# Otherwise when `layer.selectedFeatureIds().isEmpty()`, `QgsOfflineEditing` dumps all features.
Expand Down Expand Up @@ -437,8 +449,14 @@ def _convert_to_offline_project(
tr = QgsCoordinateTransform(
project.crs(), layer_to_offline.crs(), project
)
layer_bbox = tr.transform(bbox)
request.setFilterRect(layer_bbox)

try:
layer_bbox = tr.transform(bbox)
request.setFilterRect(layer_bbox)
except qgis.core.QgsCsException as err:
logger.warning(
f"Failed to transform project CRS {project.crs().authid()} bbox to layer {layer_to_offline.name()} CRS {layer_to_offline.crs().authid()} bbox within `PythonMiniOffliner`: {err}. All features will be offlined for this layer."
)

if filters_mapping[datasource_hash]:
request.setFilterExpression(filters_mapping[datasource_hash])
Expand Down
Loading