Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exporting of geometry-less vector layers when offlining using area of interest #55

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all 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: 17 additions & 9 deletions offline_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Dict, List, Optional, Union

from qgis.core import (
Qgis,
QgsApplication,
QgsBilinearRasterResampler,
QgsCoordinateReferenceSystem,
Expand Down Expand Up @@ -253,15 +254,22 @@ def _convert(self, project: QgsProject) -> None:

if layer_action == SyncAction.OFFLINE:
if self.project_configuration.offline_copy_only_aoi:
extent = QgsCoordinateTransform(
QgsCoordinateReferenceSystem(self.area_of_interest_crs),
layer.crs(),
QgsProject.instance(),
).transformBoundingBox(self.area_of_interest.boundingBox())
layer.selectByRect(extent)

if not layer.selectedFeatureCount():
layer.selectByIds([FID_NULL])
if (
layer.geometryType() is not Qgis.GeometryType.Null
and layer.geometryType() is not Qgis.GeometryType.Unknown
):
extent = QgsCoordinateTransform(
QgsCoordinateReferenceSystem(self.area_of_interest_crs),
layer.crs(),
QgsProject.instance(),
).transformBoundingBox(self.area_of_interest.boundingBox())
layer.selectByRect(extent)

if not layer.selectedFeatureCount():
layer.selectByIds([FID_NULL])
else:
# insure that geometry-less layers do not have selected features that would interfere with the process
layer.removeSelection()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected a select all, does this work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn , it works, the logic is in QgsOfflineEditing, and it only extracts selected features when 1 or more is selected, see: https://github.com/qgis/QGIS/blob/master/src/core/qgsofflineediting.cpp#L788C5-L793


self.__offline_layers.append(layer)
self.__offline_layer_names.append(layer.name())
Expand Down