From 75068e6be25acf39ed9a42ee1ed7f9eaedeeb2f0 Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Fri, 1 May 2009 13:20:26 +0800
Subject: [PATCH] ENH: parsing in progress

---
 osmStyleXMLParser.py | 46 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/osmStyleXMLParser.py b/osmStyleXMLParser.py
index 0fd2ab0084..749a9b983a 100755
--- a/osmStyleXMLParser.py
+++ b/osmStyleXMLParser.py
@@ -1,8 +1,14 @@
 import xml.parsers.expat
 
 fout= open("osm-style-in-c.c", 'w')
-writeNextCharData = 0;
+writeNextCharData = 0
 currentStyleName = ""#continue here...
+isStroke=0
+isStrokeWidth=0
+isStrokeOpacity=0
+strokeWidth=""
+strokeOpacity=""
+strokeColor=""
 
 # 3 handler functions
 def start_element(name, attrs):
@@ -13,12 +19,23 @@ def start_element(name, attrs):
       fout.write("mapnik::feature_type_style style;\n")
       fout.write("mapnik::rule_type rule;\n")
     if (name == 'MaxScaleDenominator'):
-      fout.write("rule.set_max_scale(");
+      fout.write("rule.set_max_scale(")
       writeNextCharData=1
     if (name == 'MinScaleDenominator'):
-      fout.write("rule.set_min_scale(");
+      fout.write("rule.set_min_scale(")
       writeNextCharData=1
-
+    if (name == 'LineSymbolizer'):
+      fout.write("{\ngeom = mapnik::line_symbolizer();\n")
+    if (name == 'CssParameter'):
+      global isStroke
+      global isStrokeWidth
+      global isStrokeOpacity
+      if (attrs['name'] == 'stroke'):
+        isStroke=1
+      if (attrs['name'] == 'stroke-width'):
+        isStroke=1
+      if (attrs['name'] == 'stroke-opacity'):
+        isStroke=1
 
 def end_element(name):
     print 'End element:', name
@@ -31,11 +48,32 @@ def end_element(name):
     if (name == 'MinScaleDenominator'):
       fout.write("LLU);\n");
       writeNextCharData=0
+    if (name == 'LineSymbolizer'):
+      fout.write("mapnik::stroke stroke = mapnik::stroke();\n")
+      fout.write("geom.set_stroke(stroke);\n")
+      fout.write("rule.append(geom);\n}\n")
+      strokeWidth, strokeOpacity,strokeColor ="","",""
+    if (name == 'CssParameter'):
+      global isStroke
+      global isStrokeWidth
+      global isStrokeOpacity
+      if (isStroke):
+        isStroke=0
+      if (isStrokeWidth):
+        isStrokeWidth=0
+      if (isStrokeOpacity):
+        isStrokeOpacity=0
 
 def char_data(data):
     print 'Character data:', repr(data)
     if(writeNextCharData):
       fout.write(data)
+    if (isStroke):
+      strokeColor=data
+    if (isStrokeWidth):
+      strokeWidth=data
+    if (isStrokeOpacity):
+      strokeOpacity=data
 
 p = xml.parsers.expat.ParserCreate()
 
-- 
GitLab