You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
-
1I was thinking of something similar too. Especially if using map units and a projection in meters. The new(ish) geometry operators could also help here, assuming the labels are centered on the centroid. This will work better with a fixed-width (monospaced) font than a proportional font (Where a 'W' is much wider than an 'i', for example). You're on to something here, but I suspect proportional fonts and kerning will add complexity.– Steven KayCommented Jan 15, 2017 at 22:54
-
You could use pil's imagefont.getsize(). That would give you an exact width of a string rendered in your chosen font, but I think that would have a major performance hit. The rough math above is far simpler, especially if you have hundreds of labels on screen– user52245Commented Jan 16, 2017 at 0:43
-
The only minor issue is that the function doesn't seem to work as a filter in attribute tables in print composer.– Ian Turton ♦Commented Jan 26, 2017 at 9:36
-
Does your map scale vary from page to page? Try manually putting in the scale instead of the @map_scale variable. my guess would be the attribute table has no way of knowing your map scale. (Because for instance you could have multiple map items in composer at different scales)– user52245Commented Jan 26, 2017 at 9:40
-
1@iant I posted a link to another custom expression that will get the scale of your composer map programmatically.– user52245Commented Jan 31, 2017 at 3:27
|
Show 1 more comment
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_`
- quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>
[example](https://example.com)
<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. arcgis-desktop), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-py