+ check expression needs converting
+ convert PolygonSymbolizer to use attributes
This commit is contained in:
parent
c51bac877e
commit
d51111e6e5
1 changed files with 15 additions and 9 deletions
|
@ -3,12 +3,15 @@ import os
|
||||||
import sys
|
import sys
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from lxml import objectify
|
from lxml import objectify
|
||||||
|
import re
|
||||||
|
|
||||||
def name2expr(sym):
|
def name2expr(sym):
|
||||||
name = sym.attrib['name']
|
name = sym.attrib['name']
|
||||||
expression = '[%s]' % name
|
if re.match('^\[.*\]$',name) is None:
|
||||||
sym.attrib['name'] = expression
|
print>>sys.stderr,"Fixing %s" % name
|
||||||
|
expression = '[%s]' % name
|
||||||
|
sym.attrib['name'] = expression
|
||||||
|
|
||||||
def fixup_pointsym(sym):
|
def fixup_pointsym(sym):
|
||||||
if sym.attrib.get('width'):
|
if sym.attrib.get('width'):
|
||||||
sym.attrib.pop('width')
|
sym.attrib.pop('width')
|
||||||
|
@ -18,18 +21,20 @@ def fixup_pointsym(sym):
|
||||||
# sym.attrib.pop('type')
|
# sym.attrib.pop('type')
|
||||||
|
|
||||||
def fixup_sym_attributes(sym):
|
def fixup_sym_attributes(sym):
|
||||||
|
if not hasattr(sym,'CssParameter'):
|
||||||
|
return
|
||||||
attrib = {}
|
attrib = {}
|
||||||
for css in sym.CssParameter:
|
for css in sym.CssParameter:
|
||||||
key = css.attrib.get('name')
|
key = css.attrib.get('name')
|
||||||
value = css.text
|
value = css.text
|
||||||
attrib[key]=value
|
attrib[key]=value
|
||||||
sym.clear() # remove CssParameter children
|
sym.clear() # remove CssParameter elements
|
||||||
for k,v in attrib.items(): # insert attributes
|
for k,v in attrib.items(): # insert attributes instead
|
||||||
sym.attrib[k] = v
|
sym.attrib[k] = v
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print>>sys.stderr,'Usage: %s <map_xml_file>' % sys.argv[0]
|
print>>sys.stderr,'Usage: %s <map_xml_file>' % sys.argv[0]
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -49,11 +54,12 @@ if __name__ == "__main__":
|
||||||
if hasattr(rule,'PointSymbolizer'):
|
if hasattr(rule,'PointSymbolizer'):
|
||||||
for sym in rule.PointSymbolizer:
|
for sym in rule.PointSymbolizer:
|
||||||
fixup_pointsym(sym)
|
fixup_pointsym(sym)
|
||||||
if hasattr(rule,'LineSymbolizer'):
|
if hasattr(rule,'LineSymbolizer') :
|
||||||
for sym in rule.LineSymbolizer:
|
for sym in rule.LineSymbolizer:
|
||||||
fixup_sym_attributes(sym)
|
fixup_sym_attributes(sym)
|
||||||
|
if hasattr(rule,'PolygonSymbolizer') :
|
||||||
|
for sym in rule.PolygonSymbolizer:
|
||||||
|
fixup_sym_attributes(sym)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print etree.tostring(tree,pretty_print=True,standalone=True)
|
print etree.tostring(tree,pretty_print=True,standalone=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue