Skip to content

Commit

Permalink
Work started on polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
milovanderlinden committed May 26, 2011
1 parent 5ecb341 commit 4b069a4
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 2 deletions.
19 changes: 19 additions & 0 deletions landuse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sld

# nieuwe sld
s = sld.Sld('Landuse','OSM landuse','Landuse polygons for OpenStreetMap data')

# outline fts
fts = sld.Fts()

#forest
f = sld.OgcFilter('landuse','=','forest')
fts.addRule(sld.Rule('forest', 0,120000,f, sld.Polygon('#6b942e','#6b942e',1)))

s.addFts(fts)

# export
s.saveToFile('landuse.sld')
s.DOMToFile('landuse_dom.sld')
s.saveToClipboard()
#s.DOMToClipboard()
29 changes: 29 additions & 0 deletions landuse.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
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">
<!-- a Named Layer is the basic building block of an SLD document -->
<NamedLayer>
<Name>Landuse</Name>
<UserStyle>
<Title>OSM landuse</Title>
<Abstract>Landuse polygons for OpenStreetMap data</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>forest</Name>
<MaxScaleDenominator>120000</MaxScaleDenominator>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>landuse</ogc:PropertyName>
<ogc:Literal>forest</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>

</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
32 changes: 32 additions & 0 deletions landuse_dom.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" 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" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd">
<!--a Named Layer is the basic building block of an SLD document-->
<NamedLayer>
<Name>Landuse</Name>
<UserStyle>
<Title>OSM landuse</Title>
<Abstract>Landuse polygons for OpenStreetMap data</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>forest</Name>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>landuse</ogc:PropertyName>
<ogc:Literal>forest</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<MaxScaleDenominator>120000</MaxScaleDenominator>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#6b942e</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#6b942e</CssParameter>
<CssParameter name="stroke-width">1</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
35 changes: 35 additions & 0 deletions sld.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,41 @@ def getSldDOM(self):
_linesymbolizer.appendChild(_stroke)
return _linesymbolizer

# polygon
class Polygon():
def __init__(self, fillcolor='#0000ff',strokecolor='#0000ff', strokewidth=1):
self.fillcolor = fillcolor
self.strokecolor = strokecolor
self.strokewidth = strokewidth

def __str__(self):
result = 'polygon(fill:' + self.fillcolor + ', stroke:' + self.strokecolor + ', width:' + str(self.width) + ')'
return result

def getSldString(self,indent=0,nls=True):
return ''

def getSldDOM(self):
doc = xml.dom.minidom.Document()
_polysymbolizer = doc.createElement("PolygonSymbolizer")
_fill = doc.createElement("Fill")
_cssfill = doc.createElement("CssParameter")
_cssfill.setAttribute("name", "fill")
_cssfill.appendChild(doc.createTextNode(str(self.fillcolor)))
_fill.appendChild(_cssfill)
_polysymbolizer.appendChild(_fill)
_stroke = doc.createElement("Stroke")
_cssstroke = doc.createElement("CssParameter")
_cssstroke.setAttribute("name", "stroke")
_cssstroke.appendChild(doc.createTextNode(str(self.strokecolor)))
_cssstrokew = doc.createElement("CssParameter")
_cssstrokew.setAttribute("name", "stroke-width")
_cssstrokew.appendChild(doc.createTextNode(str(self.strokewidth)))
_stroke.appendChild(_cssstroke)
_stroke.appendChild(_cssstrokew)
_polysymbolizer.appendChild(_stroke)
return _polysymbolizer

#font
class Font():
def __init__(self, family=None, size=None, style=None, weight=None):
Expand Down
Binary file modified sld.pyc
Binary file not shown.
9 changes: 7 additions & 2 deletions test.sld
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" ?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/sld" xmlns:xlink="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"/>
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
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">
<!-- a Named Layer is the basic building block of an SLD document -->
<NamedLayer>
<Name>Highway</Name>
Expand Down

0 comments on commit 4b069a4

Please sign in to comment.