-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Advanced labeling rules #299
Labels
Comments
nyalldawson
added a commit
to nyalldawson/QGIS
that referenced
this issue
Sep 5, 2024
See qgis/QGIS-Enhancement-Proposals#299 Implements the API framework for setting advanced labeling engine rules for a project, and implements 4 initial rule types: - QgsLabelingEngineRuleMinimumDistanceLabelToFeature: prevents labels being placed too *close* to features from a different layer - QgsLabelingEngineRuleMaximumDistanceLabelToFeature: prevents labels being placed too *far* from features from a different layer - QgsLabelingEngineRuleMinimumDistanceLabelToLabel: prevents labels being placed too close to labels from a different layer - QgsLabelingEngineRuleAvoidLabelOverlapWithFeature: prevents labels being placed overlapping features from a different layer (note that the first 3 rules require a build based on GEOS >= 3.10, they are not available for older GEOS builds) Also implements a registry for storing available rule classes, and serialization of rules and configuration in QGIS projects
nyalldawson
added a commit
to nyalldawson/QGIS
that referenced
this issue
Sep 10, 2024
See qgis/QGIS-Enhancement-Proposals#299 Implements the API framework for setting advanced labeling engine rules for a project, and implements 4 initial rule types: - QgsLabelingEngineRuleMinimumDistanceLabelToFeature: prevents labels being placed too *close* to features from a different layer - QgsLabelingEngineRuleMaximumDistanceLabelToFeature: prevents labels being placed too *far* from features from a different layer - QgsLabelingEngineRuleMinimumDistanceLabelToLabel: prevents labels being placed too close to labels from a different layer - QgsLabelingEngineRuleAvoidLabelOverlapWithFeature: prevents labels being placed overlapping features from a different layer (note that the first 3 rules require a build based on GEOS >= 3.10, they are not available for older GEOS builds) Also implements a registry for storing available rule classes, and serialization of rules and configuration in QGIS projects
nyalldawson
added a commit
to qgis/QGIS
that referenced
this issue
Sep 10, 2024
See qgis/QGIS-Enhancement-Proposals#299 Implements the API framework for setting advanced labeling engine rules for a project, and implements 4 initial rule types: - QgsLabelingEngineRuleMinimumDistanceLabelToFeature: prevents labels being placed too *close* to features from a different layer - QgsLabelingEngineRuleMaximumDistanceLabelToFeature: prevents labels being placed too *far* from features from a different layer - QgsLabelingEngineRuleMinimumDistanceLabelToLabel: prevents labels being placed too close to labels from a different layer - QgsLabelingEngineRuleAvoidLabelOverlapWithFeature: prevents labels being placed overlapping features from a different layer (note that the first 3 rules require a build based on GEOS >= 3.10, they are not available for older GEOS builds) Also implements a registry for storing available rule classes, and serialization of rules and configuration in QGIS projects
velle
pushed a commit
to velle/QGIS
that referenced
this issue
Sep 17, 2024
See qgis/QGIS-Enhancement-Proposals#299 Implements the API framework for setting advanced labeling engine rules for a project, and implements 4 initial rule types: - QgsLabelingEngineRuleMinimumDistanceLabelToFeature: prevents labels being placed too *close* to features from a different layer - QgsLabelingEngineRuleMaximumDistanceLabelToFeature: prevents labels being placed too *far* from features from a different layer - QgsLabelingEngineRuleMinimumDistanceLabelToLabel: prevents labels being placed too close to labels from a different layer - QgsLabelingEngineRuleAvoidLabelOverlapWithFeature: prevents labels being placed overlapping features from a different layer (note that the first 3 rules require a build based on GEOS >= 3.10, they are not available for older GEOS builds) Also implements a registry for storing available rule classes, and serialization of rules and configuration in QGIS projects
notguiltyspark
pushed a commit
to notguiltyspark/QGIS
that referenced
this issue
Sep 25, 2024
See qgis/QGIS-Enhancement-Proposals#299 Implements the API framework for setting advanced labeling engine rules for a project, and implements 4 initial rule types: - QgsLabelingEngineRuleMinimumDistanceLabelToFeature: prevents labels being placed too *close* to features from a different layer - QgsLabelingEngineRuleMaximumDistanceLabelToFeature: prevents labels being placed too *far* from features from a different layer - QgsLabelingEngineRuleMinimumDistanceLabelToLabel: prevents labels being placed too close to labels from a different layer - QgsLabelingEngineRuleAvoidLabelOverlapWithFeature: prevents labels being placed overlapping features from a different layer (note that the first 3 rules require a build based on GEOS >= 3.10, they are not available for older GEOS builds) Also implements a registry for storing available rule classes, and serialization of rules and configuration in QGIS projects
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
QGIS Enhancement: Advanced labeling rules
Date 2024/07/09
Author Nyall Dawson (@nyalldawson)
Contact nyall dot dawson at gmail dot com
Version QGIS 3.40
Summary
This proposal covers introduction of advanced rules for map labeling. Advanced rules are project-level settings, which define specific constraints which must be satisfied during rendering of maps for that project.
Examples of advanced rules include:
Users can configure any combination of rules as desired, including multiple copies of the same rule with different properties (eg different target layers or different distances)
This will allow a very flexible means for users to fine-tune the exact label logic for their maps, and provide a framework for more custom advanced labeling rules to be implemented in future.
Proposed Solution
The initial set of rules to be implemented are:
Configuration of Advanced Rules
Given the initial targeted set of rules, the GUI for configuring advanced labeling rules will be similar to that of the existing "Topology Checker" plugin:
Each rule will have an associated penalty "cost", exposed as a value from 1-10, reflecting how "important" the rule is (where 10 = Very important, must not be violated, 1-9 = Nice to have if possible, where higher numbers will try harder to avoid violating the rule).
Distance based settings will also expose control over the distance unit (eg Millimeters, Map Units, etc)
The advanced rule configuration will be exposed as an inline panel accessed from the project label settings panel:
API Changes
QgsAbstractLabelingEngineRule
A new abstract base class will be introduced for labeling engine rules. This class contains standard virtual methods for cloning, serializing and identifying the rule subclasses:
The base class will also have virtual methods which allow the rule to interact with the labeling problem, eg:
where arguments will be various internal members of the pal problem solving code, e.g.
Pal::Problem
. Since these PAL classes are all private, internal API, these methods will NOT be exposed to PyQGIS and accordingly it will NOT be possible for Python plugins to implement custom rule subclasses.Additionally, there will be a virtual method for rule preparation, allowing for pre-preparation of required members in a thread safe manner which must be performed in advance on the main rendering thread. (eg creation of feature sources and iterators)
QgsLabelingEngineRuleRegistry
A registry for QgsAbstractLabelingEngineRule subclasses will be created:
Like our other single-instance registries, this will be accessed via the QgsApplication class (via QgsApplication::labelEngineRuleRegistry() ).
Rule subclasses
The four rules initially included will be created as:
QgsLabelingEngineRuleMinimumDistanceLabelToFeature
QgsLabelingEngineRuleMinimumDistanceLabelToLabel
QgsLabelingEngineRuleMaximumDistanceLabelToFeature
QgsLabelingEngineRuleAvoidLabelOverlapWithFeature
The API for each subclass will be similar, with labeled layer getter/setters and target layer getter/setters, along with associated distance properties. Eg for
QgsLabelingEngineRuleMinimumDistanceLabelToFeature
the API will be:QgsLabelingEngineSettings changes
The
QgsLabelingEngineSettings
class will be modified to add methods for adding rules and retrieving rules, via:Since
QgsLabelingEngineSettings
is attached toQgsProject
, this will form the standard means of adding rules to a project. E.g.:QgsLabelingEngineSettings will be modified to ensure that rules are seralized to xml when saving the project, and rules are restored from XML when reading projects.
QgsLabelingEngineSettings
are passed toQgsMapSettings
from the project settings object via QgsMapSettings::setLabelingEngineSettings -- accordingly rules configured for the project will be made available to the rendering code and internal PAL labeling logic via QgsMapSettings.Performance Implications
None -- while adding rules to a project will impact the project's render speed, there will be no extra expense for rendering projects which do NOT have any rules configured.
Further Considerations/Improvements
Advanced label rules will also be respected when rendering maps via QGIS server.
Backwards Compatibility
Not applicable
The text was updated successfully, but these errors were encountered: