20 |
from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException |
from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException |
21 |
|
|
22 |
from Thuban import _ |
from Thuban import _ |
|
from Thuban.common import * |
|
23 |
|
|
24 |
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
25 |
FIELDTYPE_STRING |
FIELDTYPE_STRING |
75 |
|
|
76 |
def __init__(self): |
def __init__(self): |
77 |
self.chars = '' |
self.chars = '' |
|
self.__parser = None |
|
78 |
self.__directory = "" |
self.__directory = "" |
79 |
self.__dispatchers = {} |
self.__dispatchers = {} |
80 |
|
|
89 |
self.__directory = os.path.dirname(filename) |
self.__directory = os.path.dirname(filename) |
90 |
self.__file = open(filename) |
self.__file = open(filename) |
91 |
|
|
92 |
if self.__parser is None: |
parser = make_parser() |
93 |
self.__parser = make_parser() |
parser.setContentHandler(self) |
94 |
self.__parser.setContentHandler(self) |
parser.setErrorHandler(ErrorHandler()) |
95 |
self.__parser.setErrorHandler(ErrorHandler()) |
parser.setFeature(xml.sax.handler.feature_namespaces, 1) |
96 |
self.__parser.setFeature(xml.sax.handler.feature_namespaces, 1) |
|
97 |
|
# |
98 |
# |
# Well, this isn't pretty, but it appears that if you |
99 |
# Well, this isn't pretty, but it appears that if you |
# use Python 2.2 without the site-package _xmlplus then |
100 |
# use Python 2.2 without the site-package _xmlplus then |
# the following will fail, and without them it will work. |
101 |
# the following will fail, and without them it will work. |
# However, if you do have the site-package and you don't |
102 |
# However, if you do have the site-package and you don't |
# call these functions, the reader raises an exception |
103 |
# call these functions, the reader raises an exception |
# |
104 |
# |
# The reason we set these to 0 in the first place is |
105 |
# The reason we set these to 0 in the first place is |
# because there is an unresolved issue with external |
106 |
# because there is an unresolved issue with external |
# entities causing an exception in the reader |
107 |
# entities causing an exception in the reader |
# |
108 |
# |
try: |
109 |
try: |
parser.setFeature(xml.sax.handler.feature_validation,0) |
110 |
self.__parser.setFeature(xml.sax.handler.feature_validation,0) |
parser.setFeature(xml.sax.handler.feature_external_ges,0) |
111 |
self.__parser.setFeature(xml.sax.handler.feature_external_ges,0) |
parser.setFeature(xml.sax.handler.feature_external_pes,0) |
112 |
self.__parser.setFeature(xml.sax.handler.feature_external_pes,0) |
except SAXNotRecognizedException: |
113 |
except SAXNotRecognizedException: |
pass |
|
pass |
|
114 |
|
|
115 |
self.__parser.parse(self.__file) |
parser.parse(self.__file) |
116 |
|
|
117 |
self.close() |
self.close() |
118 |
|
|
205 |
self.__projReceiver = None |
self.__projReceiver = None |
206 |
|
|
207 |
def start_projection(self, name, qname, attrs): |
def start_projection(self, name, qname, attrs): |
208 |
|
self.ProjectionName = attrs.get((None, 'name'), None) |
209 |
self.ProjectionParams = [ ] |
self.ProjectionParams = [ ] |
210 |
|
|
211 |
def end_projection(self, name, qname): |
def end_projection(self, name, qname): |
212 |
self.__projReceiver.SetProjection(Projection(self.ProjectionParams)) |
self.__projReceiver.SetProjection( |
213 |
|
Projection(self.ProjectionParams, self.ProjectionName)) |
214 |
|
|
215 |
def start_parameter(self, name, qname, attrs): |
def start_parameter(self, name, qname, attrs): |
216 |
s = attrs.get((None, 'value')) |
s = attrs.get((None, 'value')) |
227 |
title = attrs.get((None, 'title'), "") |
title = attrs.get((None, 'title'), "") |
228 |
filename = attrs.get((None, 'filename'), "") |
filename = attrs.get((None, 'filename'), "") |
229 |
filename = os.path.join(self.GetDirectory(), filename) |
filename = os.path.join(self.GetDirectory(), filename) |
230 |
|
visible = attrs.get((None, 'visible'), "true") |
231 |
fill = parse_color(attrs.get((None, 'fill'), "None")) |
fill = parse_color(attrs.get((None, 'fill'), "None")) |
232 |
stroke = parse_color(attrs.get((None, 'stroke'), "#000000")) |
stroke = parse_color(attrs.get((None, 'stroke'), "#000000")) |
233 |
stroke_width = int(attrs.get((None, 'stroke_width'), "1")) |
stroke_width = int(attrs.get((None, 'stroke_width'), "1")) |
234 |
self.aLayer = layer_class(title, |
self.aLayer = layer_class(title, |
235 |
self.theSession.OpenShapefile(filename), |
self.theSession.OpenShapefile(filename), |
236 |
fill = fill, stroke = stroke, |
fill = fill, stroke = stroke, |
237 |
lineWidth = stroke_width) |
lineWidth = stroke_width, |
238 |
|
visible = visible != "false") |
239 |
|
|
240 |
self.__projReceiver = self.aLayer |
self.__projReceiver = self.aLayer |
241 |
|
|
280 |
def start_clpoint(self, name, qname, attrs): |
def start_clpoint(self, name, qname, attrs): |
281 |
attrib_value = attrs.get((None, 'value'), "0") |
attrib_value = attrs.get((None, 'value'), "0") |
282 |
|
|
|
#try: |
|
|
#value = Str2Num(attrib_value) |
|
|
#except: |
|
|
#value = attrib_value |
|
|
|
|
283 |
value = self.conv(attrib_value) |
value = self.conv(attrib_value) |
284 |
|
|
285 |
self.cl_group = ClassGroupSingleton(value) |
self.cl_group = ClassGroupSingleton(value) |
297 |
try: |
try: |
298 |
min = self.conv(attrs.get((None, 'min'), "0")) |
min = self.conv(attrs.get((None, 'min'), "0")) |
299 |
max = self.conv(attrs.get((None, 'max'), "0")) |
max = self.conv(attrs.get((None, 'max'), "0")) |
|
#min = Str2Num(attrs.get((None, 'min'), "0")) |
|
|
#max = Str2Num(attrs.get((None, 'max'), "0")) |
|
300 |
except ValueError: |
except ValueError: |
301 |
raise ValueError(_("Classification range is not a number!")) |
raise ValueError(_("Classification range is not a number!")) |
302 |
|
|