Created
January 19, 2016 14:30
-
-
Save SzieberthAdam/078c5a4d34ba8c8a5511 to your computer and use it in GitHub Desktop.
QGIS: Label to centroid when position is not explicitely set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It is assumed that the layer has both "labelX" and a "labelY" attributes set as real number fields. | |
# Labels / Placement / Data Defined / Coordinate / X: | |
CASE WHEN "labelX" IS NULL THEN toreal(regexp_substr(geom_to_wkt(centroid($geometry)), '(-?\\d+\\.?\\d*) -?\\d+\\.?\\d*')) ELSE "labelX" END | |
# Labels / Placement / Data Defined / Coordinate / Y: | |
CASE WHEN "labelY" IS NULL THEN toreal(regexp_substr(geom_to_wkt(centroid($geometry)), '-?\\d+\\.?\\d* (-?\\d+\\.?\\d*)')) ELSE "labelY" END | |
# Labels / Placement / Data Defined / Alignment / horizontal: | |
'Center' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment