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

[Python] Labelling for linestring are rendered after #30046

Closed
lbartoletti opened this issue May 31, 2019 · 4 comments
Closed

[Python] Labelling for linestring are rendered after #30046

lbartoletti opened this issue May 31, 2019 · 4 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers Labeling Related to QGIS map labeling

Comments

@lbartoletti
Copy link
Member

Describe the bug

We use a python script to add labels and it works for all geometries except linestring where labels are not displayed until we modify the labeling properties.

label_python

How to Reproduce

  1. Add a line
  2. Execute this python script:
pal_layer = QgsPalLayerSettings()
pal_layer.fieldName = iface.activeLayer().fields()[0].name()
pal_layer.enabled = True

labeler = QgsVectorLayerSimpleLabeling(pal_layer)

iface.activeLayer().setLabeling(labeler)
iface.activeLayer().setLabelsEnabled(True)
print(iface.activeLayer().labelsEnabled())
# not necessary
iface.activeLayer().triggerRepaint()

QGIS and OS versions

All 3.X versions and OS

Additional context

Initial problem reported from Oslandia/labelconnector#13

@lbartoletti lbartoletti added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label May 31, 2019
@nyalldawson
Copy link
Collaborator

Check the label placement option -- the default is not applicable/usable for line layers.

e.g.

pal_layer.placement = QgsPalLayerSettings.Curved

@lbartoletti
Copy link
Member Author

@nyalldawson Thank you. You're right, the default is not applicable for line layers. Shouldn't we propose a(n alternate) default for linestring too?

@nyalldawson
Copy link
Collaborator

@lbartoletti can you elaborate?

@gioman gioman added the Labeling Related to QGIS map labeling label Jun 11, 2019
@lbartoletti
Copy link
Member Author

@nyalldawson
You said the default is not applicable/usable for line layers (is the default is QgsPalLayerSettings::AroundPoint?)

So, if it's possible - I don't know this part of QGIS code - add a conditional default something like :
mDefaultPlacementMember ( layer->.geometryType() == QgsWkbTypes::LineGeometry ? QgsPalLayerSettings.Curved : QgsPalLayerSettings::AroundPoint )

But really don't know if this will change something for the python api.

Well, for my part, I consider that the problem is solved because it is a problem of using the python api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers Labeling Related to QGIS map labeling
Projects
None yet
Development

No branches or pull requests

3 participants