1 |
# Copyright (c) 2002 by Intevation GmbH |
# Copyright (c) 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
90 |
stroke="#000000"> |
stroke="#000000"> |
91 |
<classification field="AREA" field_type="double"> |
<classification field="AREA" field_type="double"> |
92 |
<clnull> |
<clnull> |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
|
|
</clnull> |
|
|
<clnull> |
|
93 |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
94 |
</clnull> |
</clnull> |
95 |
<clrange min="0" max="1"> |
<clrange min="0" max="1"> |
96 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#111111" stroke_width="1" fill="None"/> |
97 |
</clrange> |
</clrange> |
98 |
<clpoint value=".5"> |
<clpoint value=".5"> |
99 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="#111111"/> |
100 |
</clpoint> |
</clpoint> |
101 |
<clrange min="-1" max="0"> |
<clrange min="-1" max="0"> |
102 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
136 |
</session> |
</session> |
137 |
''' |
''' |
138 |
|
|
139 |
|
contents_test_layer_projection = '''\ |
140 |
|
<?xml version="1.0" encoding="UTF-8"?> |
141 |
|
<!DOCTYPE session SYSTEM "thuban.dtd"> |
142 |
|
<session title="single map&layer"> |
143 |
|
<map title="Test Map"> |
144 |
|
<projection> |
145 |
|
<parameter value="zone=26"/> |
146 |
|
<parameter value="proj=utm"/> |
147 |
|
<parameter value="ellps=clrk66"/> |
148 |
|
</projection> |
149 |
|
<layer title="My Layer" stroke_width="1" fill="None" |
150 |
|
filename="../../Data/iceland/political.shp" |
151 |
|
stroke="#000000"> |
152 |
|
<projection name="hello"> |
153 |
|
<parameter value="zone=13"/> |
154 |
|
<parameter value="proj=tmerc"/> |
155 |
|
<parameter value="ellps=clrk66"/> |
156 |
|
</projection> |
157 |
|
<classification field="POPYREG" field_type="string"> |
158 |
|
<clnull label="hallo"> |
159 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
160 |
|
</clnull> |
161 |
|
<clpoint label="welt" value="1"> |
162 |
|
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
163 |
|
</clpoint> |
164 |
|
</classification> |
165 |
|
</layer> |
166 |
|
<layer title="My Layer" stroke_width="1" fill="None" |
167 |
|
filename="../../Data/iceland/political.shp" |
168 |
|
stroke="#000000"> |
169 |
|
<projection> |
170 |
|
<parameter value="proj=lcc"/> |
171 |
|
<parameter value="ellps=clrk66"/> |
172 |
|
</projection> |
173 |
|
</layer> |
174 |
|
</map> |
175 |
|
</session> |
176 |
|
''' |
177 |
|
|
178 |
|
contents_test_visible = '''\ |
179 |
|
<?xml version="1.0" encoding="UTF-8"?> |
180 |
|
<!DOCTYPE session SYSTEM "thuban.dtd"> |
181 |
|
<session title="single map&layer"> |
182 |
|
<map title="Test Map"> |
183 |
|
<projection> |
184 |
|
<parameter value="zone=26"/> |
185 |
|
<parameter value="proj=utm"/> |
186 |
|
<parameter value="ellps=clrk66"/> |
187 |
|
</projection> |
188 |
|
<layer title="My Layer" stroke_width="1" fill="None" |
189 |
|
filename="../../Data/iceland/political.shp" |
190 |
|
stroke="#000000" visible="false"> |
191 |
|
</layer> |
192 |
|
</map> |
193 |
|
</session> |
194 |
|
''' |
195 |
|
|
196 |
class LoadSessionTest(unittest.TestCase, support.FileTestMixin): |
class LoadSessionTest(unittest.TestCase, support.FileTestMixin): |
197 |
|
|
198 |
def setUp(self): |
def setUp(self): |
208 |
file = open(self.temp_file_name("load_labels.thuban"), "w") |
file = open(self.temp_file_name("load_labels.thuban"), "w") |
209 |
file.write(contents_test_labels) |
file.write(contents_test_labels) |
210 |
file.close() |
file.close() |
211 |
|
|
212 |
|
file = open(self.temp_file_name("load_layerproj.thuban"), "w") |
213 |
|
file.write(contents_test_layer_projection) |
214 |
|
file.close() |
215 |
|
|
216 |
|
file = open(self.temp_file_name("load_visible.thuban"), "w") |
217 |
|
file.write(contents_test_visible) |
218 |
|
file.close() |
219 |
|
|
220 |
self.session = None |
self.session = None |
221 |
|
|
222 |
def tearDown(self): |
def tearDown(self): |
223 |
if self.session is not None: |
if self.session is not None: |
224 |
self.session.Destroy() |
self.session.Destroy() |
225 |
|
self.session = None |
226 |
|
|
227 |
def testSingleLayer(self): |
def testSingleLayer(self): |
228 |
"""Load a session with a single map with a single layer""" |
"""Load a session with a single map with a single layer""" |
255 |
"political.shp"))) |
"political.shp"))) |
256 |
eq(layer.GetClassification().GetDefaultFill(), Color.Transparent) |
eq(layer.GetClassification().GetDefaultFill(), Color.Transparent) |
257 |
eq(layer.GetClassification().GetDefaultLineColor().hex(), "#000000") |
eq(layer.GetClassification().GetDefaultLineColor().hex(), "#000000") |
258 |
|
eq(layer.Visible(), True) |
259 |
|
|
260 |
self.session.Destroy() |
self.session.Destroy() |
261 |
self.session = None |
self.session = None |
262 |
|
|
263 |
|
def testLayerVisibility(self): |
264 |
|
"""Test that the visible flag is correctly loaded for a layer.""" |
265 |
|
|
266 |
|
eq = self.assertEquals |
267 |
|
session = load_session(self.temp_file_name("load_visible.thuban")) |
268 |
|
self.session = session |
269 |
|
maps = session.Maps() |
270 |
|
eq(len(maps), 1) |
271 |
|
map = maps[0] |
272 |
|
layers = map.Layers() |
273 |
|
eq(len(layers), 1) |
274 |
|
layer = layers[0] |
275 |
|
|
276 |
|
eq(layer.Visible(), False) |
277 |
|
|
278 |
def testClassification(self): |
def testClassification(self): |
279 |
"""Load a session with a map and classified layers.""" |
"""Load a session with a map and classified layers.""" |
280 |
|
|
294 |
[("default", (), "", |
[("default", (), "", |
295 |
("#000000", 2, "None")), |
("#000000", 2, "None")), |
296 |
("range", (0, 1), "", |
("range", (0, 1), "", |
297 |
("#000000", 1, "None")), |
("#111111", 1, "None")), |
298 |
("single", .5, "", |
("single", .5, "", |
299 |
("#000000", 1, "None")), |
("#000000", 1, "#111111")), |
300 |
("range", (-1, 0), "", |
("range", (-1, 0), "", |
301 |
("#000000", 1, "None")), |
("#000000", 1, "None")), |
302 |
("single", -.5, "", |
("single", -.5, "", |
366 |
|
|
367 |
self.TestLayers(map.Layers(), expected) |
self.TestLayers(map.Layers(), expected) |
368 |
|
|
369 |
|
def testLayerProjection(self): |
370 |
|
eq = self.assertEquals |
371 |
|
neq = self.assertNotEqual |
372 |
|
|
373 |
|
session = load_session(self.temp_file_name("load_layerproj.thuban")) |
374 |
|
self.session = session |
375 |
|
|
376 |
|
map = self.session.Maps()[0] # only one map in the sample |
377 |
|
|
378 |
|
layers = map.Layers() # two layers in the sample |
379 |
|
|
380 |
|
# test layer with a named projection |
381 |
|
proj = layers[0].GetProjection() |
382 |
|
neq(proj, None) |
383 |
|
eq(proj.GetName(), "hello") |
384 |
|
eq(proj.GetParameter("proj"), "tmerc") |
385 |
|
eq(proj.GetParameter("zone"), "13") |
386 |
|
eq(proj.GetParameter("ellps"), "clrk66") |
387 |
|
|
388 |
|
# test layer with an unnamed projection |
389 |
|
proj = layers[1].GetProjection() |
390 |
|
neq(proj, None) |
391 |
|
eq(proj.GetName(), "Unknown") |
392 |
|
eq(proj.GetParameter("proj"), "lcc") |
393 |
|
eq(proj.GetParameter("ellps"), "clrk66") |
394 |
|
|
395 |
if __name__ == "__main__": |
if __name__ == "__main__": |
396 |
unittest.main() |
unittest.main() |
397 |
|
|