source: subversion/applications/rendering/mapnik/legend.py @ 34619

Last change on this file since 34619 was 29676, checked in by bnesbitt, 6 years ago

Tweak so it at least runs and produces output, just to see what it does.

File size: 2.7 KB
Line 
1#!/usr/bin/python
2
3"""A simple script to help visualize the Mapnik stylesheet. This file puts
4   out poly/line symbols into an HTML file, with their associated filters.
5   Not particularly complex at the moment, but a useful visualization tool if
6   you're hacking on the osm.xml file. Works against the osm.xml
7   at the moment."""
8
9__author__ = "Christopher Schmidt"
10__license__ = "Public Domain"
11
12
13import xml.dom.minidom as m
14
15def run():
16    """Parses the osm.xml file, and write an HTML table.""" 
17    #doc = m.parse("osm-template.xml")
18    doc = m.parse("osm.xml")
19    styles = doc.getElementsByTagName("Style")
20    for style in styles:
21        table_started = False
22        for r in style.getElementsByTagName("Rule"):
23
24            filters = r.getElementsByTagName("Filter")
25            text = ""
26            if len(filters):
27                text = filters[0].firstChild.nodeValue
28
29            polys = r.getElementsByTagName("PolygonSymbolizer")     
30            poly_text = [] 
31            poly_style = {}
32            if len(polys):
33                css = polys[0].getElementsByTagName("CssParameter")
34                for c in css:
35                    poly_style[ c.getAttribute("name") ] = c.firstChild.nodeValue
36
37            pfill = r.getElementsByTagName("PolygonPatternSymbolizer")
38            if len(pfill):
39                pfill = pfill[0]
40                poly_style['fill'] = '<img src="symbols/%s" title="%s"/>' % (pfill.getAttribute("file"), pfill.getAttribute("file"))
41            for key, value in poly_style.items():
42                poly_text.append("%s: %s" % (key, value))
43            poly_text = "<br />".join(poly_text)
44
45            lines = r.getElementsByTagName("LineSymbolizer")     
46            line_text = [] 
47            line_style = {}
48            if len(lines):
49                css = lines[0].getElementsByTagName("CssParameter")
50                for c in css:
51                    line_style[ c.getAttribute("name") ] = c.firstChild.nodeValue
52                for key, value in line_style.items():
53                    line_text.append("%s: %s" % (key, value))
54            line_text = "<br />".join(line_text)
55
56            if text and (poly_text or line_text):
57                if not table_started:
58                    print "<h2>%s</h2>" % style.getAttribute("name").title()
59                    print "<table><tr><td>filter</td><td>poly</td><td>stroke</td></tr>"
60                    table_started = True
61                print "<tr><td>%s</td>" % text
62                print "<td style='background-color: %s'>%s</td>" % (poly_style.get('fill', ''),  poly_text)   
63                print "<td style='background-color: %s'>%s</td></tr>" % (line_style.get('stroke', ''),  line_text)   
64   
65        if table_started:
66            print "</table>"
67if __name__ == "__main__":
68    run()
Note: See TracBrowser for help on using the repository browser.