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

Allow Expressions to be set for LABEL properties using MapScript #6904

Merged
merged 6 commits into from
Jun 22, 2023

Conversation

geographika
Copy link
Member

This pull request allows the new functionality in #6884 of using an expression in a LABEL PRIORITY in MapScript.
It takes a similar approach to setting attribute bindings for properties, which requires using the appropriate attribute constant such as MS_LABEL_BINDING_PRIORITY:

label = mapscript.labelObj()
label .setExpressionBinding(mapscript.MS_LABEL_BINDING_PRIORITY, "[MY_ATTRIBUTE] * 2")

This is a little clunky but is at least consistent with setting attribute bindings:

label = mapscript.labelObj()
label.setBinding(mapscript.MS_LABEL_BINDING_COLOR, "NEW_BINDING")

While testing this I noticed that the writeLabel function used to write Mapfile objects ignored expressions. This seems an oversight also for the LABEL SIZE expression. If this approach seems appropriate I can use this for other expression bindings.

Something to note is that a property could have an attribute binding and an expression binding set. In this case the attribute binding currently takes precedence when calculating a shape value, so it also takes precedence when writing to a Mapfile.

In theory setting an expression could also set the attribute binding to NULL. This is not currently the case for MapScript or when reading a Mapfile twice.

@jmckenna jmckenna added this to the 8.2.0 Release milestone Jun 6, 2023
mapscript/swiginc/label.i Outdated Show resolved Hide resolved
mapscript/swiginc/label.i Outdated Show resolved Hide resolved
geographika and others added 2 commits June 14, 2023 17:34
Make char a constant

Co-authored-by: Even Rouault <even.rouault@spatialys.com>
Make char a constant

Co-authored-by: Even Rouault <even.rouault@spatialys.com>
@geographika
Copy link
Member Author

@rouault - thanks for the review - changes applied.
I presume it would make sense to use const for all similar functions throughout MapScript?

E.g.

char *getExpressionString() {

int setExpression(char *expression)

char *getTextString() {

@rouault
Copy link
Contributor

rouault commented Jun 14, 2023

I presume it would make sense to use const for all similar functions throughout MapScript?

yes

@rouault rouault merged commit ac60539 into MapServer:main Jun 22, 2023
7 checks passed
jmckenna pushed a commit to jmckenna/MapServer that referenced this pull request Aug 3, 2023
…Server#6904)

This pull request allows the new functionality in MapServer#6884 of using an expression in a LABEL PRIORITY in MapScript. 
It takes a similar approach to setting attribute bindings for properties, which requires using the appropriate attribute constant such as `MS_LABEL_BINDING_PRIORITY`:

```python
label = mapscript.labelObj()
label .setExpressionBinding(mapscript.MS_LABEL_BINDING_PRIORITY, "[MY_ATTRIBUTE] * 2")
```

This is a little clunky but is at least consistent with setting attribute bindings:

```python
label = mapscript.labelObj()
label.setBinding(mapscript.MS_LABEL_BINDING_COLOR, "NEW_BINDING")
```

While testing this I noticed that the `writeLabel` function used to write Mapfile objects ignored expressions. This seems an oversight also for the `LABEL` `SIZE` expression. If this approach seems appropriate I can use this for other expression bindings.

Something to note is that a property could have an attribute binding **and** an expression binding set. In this case the attribute binding currently takes precedence when calculating a shape value, so it also takes precedence when writing to a Mapfile. 

In theory setting an expression could also set the attribute binding to NULL. This is not currently the case for MapScript or when reading a Mapfile twice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants