azavea / python-sld Goto Github PK
View Code? Open in Web Editor NEWA simple python library that enables dynamic SLD creation and manipulation.
Home Page: http://azavea.github.com/python-sld/
License: Apache License 2.0
A simple python library that enables dynamic SLD creation and manipulation.
Home Page: http://azavea.github.com/python-sld/
License: Apache License 2.0
I would like create and sld style with multiple NamedLayer
This my code
doc = sld.StyledLayerDescriptor()
llista = MapStyle.objects.filter(map=id).order_by('order')
for mapstyle in llista:
nl = doc.create_namedlayer(mapstyle.style.name)
I created a namelayer for each element in llista but the result only includes the last NamedLayer.
I possible do this?
I try to do removing the namedlayer node and inserting after the namedlayer nodes but without success
doc = sld.StyledLayerDescriptor()
llista = MapStyle.objects.filter(map=2).order_by('order')
namedlayers=[]
for mapstyle in llista:
namedlayers.append( doc.create_namedlayer(mapstyle.style.name)._node )
nl_node = doc._node.xpath('sld:NamedLayer', namespaces=sld.SLDNode._nsmap)[0]
doc._node.remove(nl_node)
i=0
for n in namedlayers:
doc._node.insert(i, namedlayers[i])
i=i+1
print etree.tostring(doc._node, with_tail=False, pretty_print=True)
I am running this script:
from sld import *
sld_doc = StyledLayerDescriptor()
# Create Layer
nl = sld_doc.create_namedlayer('Drivetime Polygon Style ')
us = nl.create_userstyle()
us.Title = 'Drivetime'
# Create Rule
fts = us.create_featuretypestyle()
r1 = fts.create_rule('Interval 1', PolygonSymbolizer)
# Create Filter
f1 = Filter(r1)
f1.PropertyIsEqualTo = PropertyCriterion(f1, 'PropertyIsEqualTo')
f1.PropertyIsEqualTo.PropertyName = 'drivetime'
f1.PropertyIsEqualTo.Literal = 'v1'
r1.Filter = f1
content = sld_doc.as_sld(pretty_print=True)
print content
And it creates this sld file:
<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
<sld:NamedLayer>
<sld:Name>Drivetime Polygon Style </sld:Name>
<sld:UserStyle>
<sld:Title>Drivetime</sld:Title>
<sld:FeatureTypeStyle>
<sld:Rule>
<sld:Title>Interval 1</sld:Title>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">#AAAAAA</sld:CssParameter>
</sld:Fill>
<sld:Stroke>
<sld:CssParameter name="stroke">#000000</sld:CssParameter>
<sld:CssParameter name="stroke-width">1</sld:CssParameter>
</sld:Stroke>
</sld:PolygonSymbolizer>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>drivetime</ogc:PropertyName>
<ogc:Literal>v1</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>
The file is not valid, because the PolygonSymbolizer is before the filter. Is this a bug or am I doing something wrong?
The Rule.create_filter
is looking for ==
when doing a PropertyIsEqualTo comparitor. However, the documentation states that =
is acceptable.
This had me looking around for a while. :(
Hi, appreciate the work very much.
My Python skills are a bit rusty but I can't seem to find a way to add multiple “AND” and “OR” filters dynamically!
My objective is to translate a parsed query string (SQL) to the corresponding SLD syntax. For example: "a > 1 and b < 2".
As far as I can tell, I must first create two separate filters for the rule:
import sld
r = fs.create_rule('r1')
f1 = sld.Filter(r)
f1.a = sld.PropertyCriterion(f1, 'PropertyIsGreaterThan')
f1.a.PropertyName = 'a'
f1.a.Literal = '1'
f2 = sld.Filter(r)
f2.b = sld.PropertyCriterion(f2, 'PropertyIsLessThan')
f2.b.PropertyName = 'b'
f2.b.Literal = '2'
and finally combine them like so:
r.Filter = f1 + f2
Now, how can I accomplish this when the number of criterion and operands are unknown? Essentially, I need to execute the Filter assignment dynamically but the filter references (f1 and f2) must already be defined!
Consider the following example: "(a > 1 and b < 2 and c = 3 ) or (d = 4 and e >= 5)"
Roland Hansson
Consider using Sphinx (http://sphinx-doc.org/) for Documetnation purposes?
I have a project where I need to load multiple layers. To speed up this process, I'm launching multiple processes to retrieve the layer images. If there are multiple layers that have SLD's associated with them, they can break sometimes when there is contention over the schema document created within the init method of StyledLayerDescriptor. Is there a known workaround for this situation?
I'm looking at modifying the code locally to just keep the schema file around at all times to prevent this contention, but wanted to see if there were other ways of dealing with it.
Thanks much.
Hi David,
I would like use your library, but I don't see how add ExternalGraphic node instead as mark.
The best way to do this is creating a custom PointSymbolizer class that uses a custom graphic class, not?
When I go to print my sld out my filter ends up below my symbolizer. Is there any way to avoid since this violates sld styling policies? Here is my code.
mysld = sld.StyledLayerDescriptor()
nl = mysld.create_namedlayer('test')
ustyle = nl.create_userstyle()
fts = ustyle.create_featuretypestyle()
firstRule = fts.create_rule('test',sld.PolygonSymbolizer)
firstRule.create_filter('value', '>', 'T')
print mysld.as_sld(pretty_print=True)
Is it possible to create more than one rule in an Layer or FutureTypeStyle, by using a list or similar?
I'm running sld in a loop to create an sld file similar to the one generated by QGIS, but the final result only includes the last data from the loop. Thanks
any plan to support RasterSymbolizer?
David, finally got around to trying python-sld and I can't get past this. I'm sure I'm doing something stupid.
from python shell:
import sld
mysld = StyledLayerDescriptor()
this returns error above.
did sudo easy_install --upgrade python-sld beforehand
thanks,
Michael
Are there any workaround available for accessing this rule property with "UpperBoundary" and "LowerBoundary" Value?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.