Skip to content

Commit

Permalink
Convert qgis raster resampling setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 15, 2024
1 parent 0c75f63 commit c80f18f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
16 changes: 13 additions & 3 deletions felt/core/fsl_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
QGIS to FSL conversion
"""

import math
from enum import (
Enum,
auto
Expand All @@ -11,13 +12,11 @@
List,
Optional
)
import math

from qgis.PyQt.QtCore import (
Qt,
)
from qgis.PyQt.QtGui import QColor

from qgis.core import (
NULL,
QgsVectorLayer,
Expand Down Expand Up @@ -60,7 +59,9 @@
QgsRasterRenderer,
QgsSingleBandPseudoColorRenderer,
QgsPalettedRasterRenderer,
QgsSingleBandGrayRenderer
QgsSingleBandGrayRenderer,
QgsRasterPipe,
QgsRasterDataProvider
)

from .map_utils import MapUtils
Expand Down Expand Up @@ -1531,6 +1532,15 @@ def raster_layer_to_fsl(
if not fsl:
return None

if (layer.resamplingStage() == QgsRasterPipe.ResamplingStage.Provider
and (layer.dataProvider().zoomedInResamplingMethod() !=
QgsRasterDataProvider.ResamplingMethod.Nearest
or layer.dataProvider().zoomedOutResamplingMethod() !=
QgsRasterDataProvider.ResamplingMethod.Nearest)):
fsl['config']['rasterResampling'] = "linear"
else:
fsl['config']['rasterResampling'] = "nearest"

if layer.hasScaleBasedVisibility():
if layer.minimumScale():
fsl['style']['minZoom'] = (
Expand Down
25 changes: 22 additions & 3 deletions felt/core/map_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
QgsTask,
QgsFeedback,
QgsBlockingNetworkRequest,
QgsReferencedRectangle
QgsReferencedRectangle,
QgsRasterLayer
)
from qgis.utils import iface

Expand Down Expand Up @@ -75,7 +76,7 @@ def __init__(self,
project.transformContext()
)
self.layers = [
layer.clone() for layer in layers
MapUploaderTask.clone_layer(layer) for layer in layers
]
self.unsupported_layer_details = {}
else:
Expand All @@ -95,7 +96,8 @@ def __init__(self,
]

self.layers = [
layer.clone() for layer in visible_layers if
MapUploaderTask.clone_layer(layer) for layer in visible_layers
if
LayerExporter.can_export_layer(layer)[
0] == LayerSupport.Supported
]
Expand Down Expand Up @@ -137,6 +139,23 @@ def __init__(self,
self.feedback: Optional[QgsFeedback] = None
self.was_canceled = False

@staticmethod
def clone_layer(layer: QgsMapLayer) -> QgsMapLayer:
"""
Clones a layer
"""
res = layer.clone()
if isinstance(layer, QgsRasterLayer):
res.setResamplingStage(layer.resamplingStage())
res.dataProvider().setZoomedInResamplingMethod(
layer.dataProvider().zoomedInResamplingMethod()
)
res.dataProvider().setZoomedOutResamplingMethod(
layer.dataProvider().zoomedOutResamplingMethod()
)

return res

def set_workspace_id(self, workspace_id: Optional[str]):
"""
Sets the target workspace ID
Expand Down

0 comments on commit c80f18f

Please sign in to comment.