|
5 | 5 | from pathlib import Path |
6 | 6 | from typing import Dict, List, NamedTuple, NewType, Optional |
7 | 7 |
|
| 8 | +import qgis.core |
8 | 9 | from osgeo import gdal, ogr, osr |
9 | 10 | from qgis.core import ( |
10 | 11 | Qgis, |
@@ -136,8 +137,14 @@ def convert_to_offline( |
136 | 137 | layer.removeSelection() |
137 | 138 | else: |
138 | 139 | tr = QgsCoordinateTransform(project.crs(), layer.crs(), project) |
139 | | - layer_bbox = tr.transform(bbox) |
140 | | - layer.selectByRect(layer_bbox) |
| 140 | + |
| 141 | + try: |
| 142 | + layer_bbox = tr.transform(bbox) |
| 143 | + layer.selectByRect(layer_bbox) |
| 144 | + except qgis.core.QgsCsException as err: |
| 145 | + logger.warning( |
| 146 | + 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." |
| 147 | + ) |
141 | 148 |
|
142 | 149 | # If the selection by BBOX did not select anything, make sure we fool `QgsOfflineEditing` something is selected. |
143 | 150 | # Otherwise when `layer.selectedFeatureIds().isEmpty()`, `QgsOfflineEditing` dumps all features. |
@@ -442,8 +449,14 @@ def _convert_to_offline_project( |
442 | 449 | tr = QgsCoordinateTransform( |
443 | 450 | project.crs(), layer_to_offline.crs(), project |
444 | 451 | ) |
445 | | - layer_bbox = tr.transform(bbox) |
446 | | - request.setFilterRect(layer_bbox) |
| 452 | + |
| 453 | + try: |
| 454 | + layer_bbox = tr.transform(bbox) |
| 455 | + request.setFilterRect(layer_bbox) |
| 456 | + except qgis.core.QgsCsException as err: |
| 457 | + logger.warning( |
| 458 | + 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." |
| 459 | + ) |
447 | 460 |
|
448 | 461 | if filters_mapping[datasource_hash]: |
449 | 462 | request.setFilterExpression(filters_mapping[datasource_hash]) |
|
0 commit comments