在SLD中添加新过滤器

时间:2023-02-01 10:15:59

i want to update my sld. In my sld, there is not a filter but i want to apply a filter using the python,dynamically not by manually putting the values in sld. This is my sld.

我想更新我的sld。在我的sld中,没有过滤器,但我想使用python应用过滤器,动态不是通过手动将值放在sld中。这是我的事。

<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" `xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd">`
<NamedLayer>
<Name>Simple polygon with stroke</Name>
<UserStyle>
<Title>SLD Cook Book: Simple polygon with stroke</Title>
<FeatureTypeStyle>
<Rule>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#000080</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#FFFFFF</CssParameter>
<CssParameter name="stroke-width">2</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

Now i want to add a filter on my table attribute name_1 is there any way to do this in python. New filter will be in a Rule tag and will be under the FeatureTypeStyle.

现在我想在我的表属性name_1上添加一个过滤器是否有任何方法可以在python中执行此操作。新过滤器将位于Rule标记中,并位于FeatureTypeStyle下。

1 个解决方案

#1


1  

Python SLD

Well, I used the python-sld package to create the SLD structure dinamically.

好吧,我使用python-sld包来创建SLD结构。

You can find here http://azavea.github.io/python-sld/ the project. I must say the documentation is not exhaustive, so many times you have to try-error to do what you want. For me was neccesary overwrite the existing SLD with the new one created, I couldn't modify the existing one.

你可以在这里找到http://azavea.github.io/python-sld/这个项目。我必须说文档并不详尽,所以很多时候你必须尝试错误来做你想做的事情。对于我来说,必须用新创建的SLD覆盖现有的SLD,我无法修改现有的SLD。

Said this, once you have the package installed:

这样说,一旦你安装了包:

Create the SLD structure

from sld import StyledLayerDescriptor, PolygonSymbolizer, Filter

mysld = StyledLayerDescriptor()
nl = mysld.create_namedlayer('Simple polygon with stroke')
ustyle = nl.create_userstyle()
fts = ustyle.create_featuretypestyle()

First rule

fts.create_rule('First Rule', PolygonSymbolizer)

mysld.NamedLayer.UserStyle.FeatureTypeStyle.Rules[0].PolygonSymbolizer.Fill.CssParameters[0].Value = '#000080'
mysld.NamedLayer.UserStyle.FeatureTypeStyle.Rules[0].PolygonSymbolizer.Stroke.CssParameters[0].Value = '#FFFFFF'
mysld.NamedLayer.UserStyle.FeatureTypeStyle.Rules[0].PolygonSymbolizer.Stroke.CssParameters[1].Value = '2'

Second rule and filter

fts.create_rule('Second Rule', PolygonSymbolizer)

fts.Rules[1].create_filter('name_1', comparator, value)

A rule example:

一个规则示例:

fts.Rules[1].create_filter('name_1', '>=', '0')

You can do a lot of things in the creation of the rules and filters adding variables, for example I code this:

您可以在创建规则和过滤器中添加变量时执行很多操作,例如我对此进行编码:

fts.create_rule(str(int(round(e))) + '-' + str(int(round(v[i + 1]))), PolygonSymbolizer)

fts.Rules[i].create_filter(field, '>=', str(e))

Hope this help, blessings.

希望这有帮助,祝福。

#1


1  

Python SLD

Well, I used the python-sld package to create the SLD structure dinamically.

好吧,我使用python-sld包来创建SLD结构。

You can find here http://azavea.github.io/python-sld/ the project. I must say the documentation is not exhaustive, so many times you have to try-error to do what you want. For me was neccesary overwrite the existing SLD with the new one created, I couldn't modify the existing one.

你可以在这里找到http://azavea.github.io/python-sld/这个项目。我必须说文档并不详尽,所以很多时候你必须尝试错误来做你想做的事情。对于我来说,必须用新创建的SLD覆盖现有的SLD,我无法修改现有的SLD。

Said this, once you have the package installed:

这样说,一旦你安装了包:

Create the SLD structure

from sld import StyledLayerDescriptor, PolygonSymbolizer, Filter

mysld = StyledLayerDescriptor()
nl = mysld.create_namedlayer('Simple polygon with stroke')
ustyle = nl.create_userstyle()
fts = ustyle.create_featuretypestyle()

First rule

fts.create_rule('First Rule', PolygonSymbolizer)

mysld.NamedLayer.UserStyle.FeatureTypeStyle.Rules[0].PolygonSymbolizer.Fill.CssParameters[0].Value = '#000080'
mysld.NamedLayer.UserStyle.FeatureTypeStyle.Rules[0].PolygonSymbolizer.Stroke.CssParameters[0].Value = '#FFFFFF'
mysld.NamedLayer.UserStyle.FeatureTypeStyle.Rules[0].PolygonSymbolizer.Stroke.CssParameters[1].Value = '2'

Second rule and filter

fts.create_rule('Second Rule', PolygonSymbolizer)

fts.Rules[1].create_filter('name_1', comparator, value)

A rule example:

一个规则示例:

fts.Rules[1].create_filter('name_1', '>=', '0')

You can do a lot of things in the creation of the rules and filters adding variables, for example I code this:

您可以在创建规则和过滤器中添加变量时执行很多操作,例如我对此进行编码:

fts.create_rule(str(int(round(e))) + '-' + str(int(round(v[i + 1]))), PolygonSymbolizer)

fts.Rules[i].create_filter(field, '>=', str(e))

Hope this help, blessings.

希望这有帮助,祝福。