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

Support arithmetic functions #981

Open
slafayIGN opened this issue Feb 7, 2025 · 0 comments
Open

Support arithmetic functions #981

slafayIGN opened this issue Feb 7, 2025 · 0 comments
Assignees

Comments

@slafayIGN
Copy link

Feature Request

Someone tried to use an SLD with the following rule in one of our API that relies on GeoServer. The goal is to make a style based on a ratio between two property values. You can imagine there were several similar rules in the SLD file.

<Rule>
	<Name>25 à 36%</Name>
	<ogc:Filter
		xmlns:ogc="http://www.opengis.net/ogc">
		<ogc:And>
			<ogc:PropertyIsGreaterThan>
				<ogc:PropertyName>"men_pauv" / "men" * 100</ogc:PropertyName>
				<ogc:Literal>25</ogc:Literal>
			</ogc:PropertyIsGreaterThan>
			<ogc:PropertyIsLessThanOrEqualTo>
				<ogc:PropertyName>"men_pauv" / "men" * 100</ogc:PropertyName>
				<ogc:Literal>36</ogc:Literal>
			</ogc:PropertyIsLessThanOrEqualTo>
		</ogc:And>
	</ogc:Filter>
	<PolygonSymbolizer>
		<Fill>
			<CssParameter name="fill">#ff5e23</CssParameter>
		</Fill>
	</PolygonSymbolizer>
</Rule>

But GeoServer doesn't accept the arithmetic operations in the PropertyName. So we had to replace it with specific SLD functions ogc:Mul and ogc:Div (reference is here: https://docs.geoserver.org/main/en/user/styling/sld/reference/filters.html#filter-expressions):

<Rule>
	<Name>25 à 36%</Name>
	<ogc:Filter
		xmlns:ogc="http://www.opengis.net/ogc">
		<ogc:And>
			<ogc:PropertyIsGreaterThan>
				<ogc:Mul>
					<ogc:Div>
						<ogc:PropertyName>men_pauv</ogc:PropertyName>
						<ogc:PropertyName>men</ogc:PropertyName>
					</ogc:Div>
					<ogc:Literal>100</ogc:Literal>
				</ogc:Mul>
				<ogc:Literal>25</ogc:Literal>
			</ogc:PropertyIsGreaterThan>
			<ogc:PropertyIsLessThanOrEqualTo>
				<ogc:Mul>
					<ogc:Div>
						<ogc:PropertyName>men_pauv</ogc:PropertyName>
						<ogc:PropertyName>men</ogc:PropertyName>
					</ogc:Div>
					<ogc:Literal>100</ogc:Literal>
				</ogc:Mul>
				<ogc:Literal>36</ogc:Literal>
			</ogc:PropertyIsLessThanOrEqualTo>
		</ogc:And>
	</ogc:Filter>
	<PolygonSymbolizer>
		<Fill>
			<CssParameter name="fill">#ff5e23</CssParameter>
		</Fill>
	</PolygonSymbolizer>
</Rule>

GeoStyler SLD parser doesn't recognize those functions. A quick try empties the filter.

That would be a useful addition.

I'm not sure this is a GeoServer vendor option. In that case it can be referenced as a child request of #969 .

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

No branches or pull requests

3 participants