18 |
import xml.sax.handler |
import xml.sax.handler |
19 |
from xml.sax import make_parser, ErrorHandler |
from xml.sax import make_parser, ErrorHandler |
20 |
|
|
21 |
|
from Thuban import _ |
22 |
from Thuban.Model.session import Session |
from Thuban.Model.session import Session |
23 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
24 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
25 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
26 |
from Thuban.Model.proj import Projection |
from Thuban.Model.proj import Projection |
27 |
from Thuban.Model.classification import Classification |
from Thuban.Model.classification import Classification, ClassData |
28 |
|
|
29 |
|
|
30 |
def parse_color(color): |
def parse_color(color): |
43 |
b = string.atoi(color[5:7], 16) / 255.0 |
b = string.atoi(color[5:7], 16) / 255.0 |
44 |
result = Color(r, g, b) |
result = Color(r, g, b) |
45 |
else: |
else: |
46 |
raise ValueError("Invalid hexadecimal color specification %s" |
raise ValueError(_("Invalid hexadecimal color specification %s") |
47 |
% color) |
% color) |
48 |
else: |
else: |
49 |
raise ValueError("Invalid color specification %s" % color) |
raise ValueError(_("Invalid color specification %s") % color) |
50 |
return result |
return result |
51 |
|
|
52 |
|
|
154 |
end_dispatcher['layer'] = "end_layer" |
end_dispatcher['layer'] = "end_layer" |
155 |
|
|
156 |
def start_classification(self, name, qname, attrs): |
def start_classification(self, name, qname, attrs): |
157 |
self.aLayer.classification.setField(attrs.get((None, 'field'), None)) |
self.aLayer.classification.SetField(attrs.get((None, 'field'), None)) |
158 |
start_dispatcher['classification'] = "start_classification" |
start_dispatcher['classification'] = "start_classification" |
159 |
|
|
160 |
def end_classification(self, name, qname): |
def end_classification(self, name, qname): |
162 |
end_dispatcher['classification'] = "end_classification" |
end_dispatcher['classification'] = "end_classification" |
163 |
|
|
164 |
def start_clnull(self, name, qname, attrs): |
def start_clnull(self, name, qname, attrs): |
165 |
self.cl_data = {} |
self.cl_data = ClassData() |
166 |
start_dispatcher['clnull'] = "start_clnull" |
start_dispatcher['clnull'] = "start_clnull" |
167 |
|
|
168 |
def end_clnull(self, name, qname): |
def end_clnull(self, name, qname): |
169 |
self.aLayer.classification.setNull(self.cl_data) |
self.aLayer.classification.SetDefaultData(self.cl_data) |
170 |
del self.cl_data |
del self.cl_data |
171 |
end_dispatcher['clnull'] = "end_clnull" |
end_dispatcher['clnull'] = "end_clnull" |
172 |
|
|
178 |
except: |
except: |
179 |
self.cl_value = attrib_value |
self.cl_value = attrib_value |
180 |
|
|
181 |
self.cl_data = {} |
self.cl_data = ClassData() |
182 |
start_dispatcher['clpoint'] = "start_clpoint" |
start_dispatcher['clpoint'] = "start_clpoint" |
183 |
|
|
184 |
def end_clpoint(self, name, qname): |
def end_clpoint(self, name, qname): |
185 |
self.aLayer.classification.addPoint(self.cl_value, self.cl_data) |
self.aLayer.classification.AddPoint(self.cl_value, self.cl_data) |
186 |
del self.cl_value, self.cl_data |
del self.cl_value, self.cl_data |
187 |
end_dispatcher['clpoint'] = "end_clpoint" |
end_dispatcher['clpoint'] = "end_clpoint" |
188 |
|
|
192 |
self.cl_low = int(attrs.get((None, 'low'), "0")) |
self.cl_low = int(attrs.get((None, 'low'), "0")) |
193 |
self.cl_high = int(attrs.get((None, 'high'), "0")) |
self.cl_high = int(attrs.get((None, 'high'), "0")) |
194 |
except ValueError: |
except ValueError: |
195 |
raise ValueError("Classification range is not a number!") |
raise ValueError(_("Classification range is not a number!")) |
196 |
|
|
197 |
self.cl_data = {} |
self.cl_data = ClassData() |
198 |
start_dispatcher['clrange'] = "start_clrange" |
start_dispatcher['clrange'] = "start_clrange" |
199 |
|
|
200 |
def end_clrange(self, name, qname): |
def end_clrange(self, name, qname): |
201 |
self.aLayer.classification.addRange( |
self.aLayer.classification.AddRange( |
202 |
self.cl_low, self.cl_high, self.cl_data) |
self.cl_low, self.cl_high, self.cl_data) |
203 |
del self.cl_low, self.cl_high, self.cl_data |
del self.cl_low, self.cl_high, self.cl_data |
204 |
end_dispatcher['clrange'] = "end_clrange" |
end_dispatcher['clrange'] = "end_clrange" |
205 |
|
|
206 |
def start_cldata(self, name, qname, attrs): |
def start_cldata(self, name, qname, attrs): |
207 |
self.cl_data['stroke'] = parse_color( |
self.cl_data.SetStroke(parse_color(attrs.get((None, 'stroke'), "None"))) |
208 |
attrs.get((None, 'stroke'), "None")) |
self.cl_data.SetStrokeWidth( |
209 |
self.cl_data['stroke_width'] = int( |
int(attrs.get((None, 'stroke_width'), "0"))) |
210 |
attrs.get((None, 'stroke_width'), "0")) |
self.cl_data.SetFill(parse_color(attrs.get((None, 'fill'), "None"))) |
|
self.cl_data['fill'] = parse_color( |
|
|
attrs.get((None, 'fill'), "None")) |
|
211 |
start_dispatcher['cldata'] = "start_cldata" |
start_dispatcher['cldata'] = "start_cldata" |
212 |
|
|
213 |
def end_cldata(self, name, qname): |
def end_cldata(self, name, qname): |