GeoCat / bridge-style

Cartography library making style format conversions as easy as using Python.
MIT License
44 stars 14 forks source link

QGIS Scale Depenent Visiblity of labels is ignored #82

Closed geraldo closed 5 months ago

geraldo commented 5 months ago

Right now QGIS Scale Depenent Visiblity for labels is ignored when exported to GeoStyler. qgis/togeostyler.py has the following code to have in mind scale-based visibility of labels, but doesn't work:

    if hasattr(labeling, 'dependsOnScale') and labeling.dependsOnScale():
        scale = processRuleScale(labeling)
        result["scaleDenominator"] = scale

I think the code instead should be the following:

    if (layer.hasScaleBasedVisibility()):
        scale = processRuleScale(layer)
        result["scaleDenominator"] = scale

Additionally labels renderer also can have a scale-based visibility, which should be used with the following code:

    if labeling is not None:
        settings = layer.labeling().settings()
        sv = settings.scaleVisibility
        if sv:
            scale = {"max": settings.minimumScale, "min": settings.maximumScale}
            result["scaleDenominator"] = scale
geraldo commented 5 months ago

I'm going to reopen this as there is a bug for Scale Depenent Visiblity as a labels option. (It does work fine so for Scale Depenent Visiblity as set in Layer Rendering.)

What happens is that in opposite to minimumScale and maximumScale in Layers, it is a Property and not a Method in QgsPalLayerSettings.

Now I also do remember why my test cases sometimes fail: It's when I do forget to restart QGIS after applying changes to bridgestyle library and just do use the Plugin Reloader. As documented here, actually Plugin Reloader doesn't reload loaded libraries. Sorry for that!

GeoSander commented 5 months ago

You are very consistent writing "Scale Dependent Visibility" as "Scale Depenent Visiblity" I have to say 😄

Yes, the QGIS API is very consistent (not 🙄)... Good that you discovered it. Will check and merge. Unfortunately this did not make the QGIS Bridge release, but it will be in a next one.