1 |
# Copyright (c) 2002, 2003, 2004 by Intevation GmbH |
# Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
40 |
import dbflib |
import dbflib |
41 |
import shapelib |
import shapelib |
42 |
|
|
43 |
|
from Thuban import internal_from_unicode |
44 |
from Thuban.Model.save import save_session |
from Thuban.Model.save import save_session |
45 |
from Thuban.Model.load import load_session, parse_color, LoadError, \ |
from Thuban.Model.load import load_session, parse_color, LoadError, \ |
46 |
LoadCancelled |
LoadCancelled |
47 |
from Thuban.Model.color import Transparent |
from Thuban.Model.color import Transparent |
48 |
from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\ |
from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\ |
49 |
ClassGroupSingleton, ClassGroupDefault |
ClassGroupSingleton, ClassGroupPattern, ClassGroupDefault |
50 |
from Thuban.Model.postgisdb import ConnectionError |
from Thuban.Model.postgisdb import ConnectionError |
51 |
from Thuban.Model.table import DBFTable, MemoryTable, \ |
from Thuban.Model.table import DBFTable, MemoryTable, \ |
52 |
FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \ |
FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \ |
54 |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
55 |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
56 |
|
|
|
|
|
57 |
def filenames_equal(name1, name2): |
def filenames_equal(name1, name2): |
58 |
"""Return true if the filenames name1 and name2 are equal. |
"""Return true if the filenames name1 and name2 are equal. |
59 |
|
|
124 |
print a != b and "***************" or "" |
print a != b and "***************" or "" |
125 |
print a |
print a |
126 |
print b |
print b |
127 |
|
|
128 |
self.assertEquals(el1, el2, |
self.assertEquals(el1, el2, |
129 |
"loaded file not equivalent to the saved file") |
"loaded file not equivalent to the saved file") |
130 |
|
|
175 |
elif data[CLASSES][i][GROUP_TYPE] == "single": |
elif data[CLASSES][i][GROUP_TYPE] == "single": |
176 |
g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA], |
g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA], |
177 |
props, data[CLASSES][i][GROUP_LABEL]) |
props, data[CLASSES][i][GROUP_LABEL]) |
178 |
|
elif data[CLASSES][i][GROUP_TYPE] == "pattern": |
179 |
|
g = ClassGroupPattern(data[CLASSES][i][GROUP_DATA], |
180 |
|
props, data[CLASSES][i][GROUP_LABEL]) |
181 |
|
|
182 |
eq(group, g) |
eq(group, g) |
183 |
|
|
204 |
<parameter value="units=m"/> |
<parameter value="units=m"/> |
205 |
<parameter value="zone=27"/> |
<parameter value="zone=27"/> |
206 |
</projection> |
</projection> |
207 |
<layer shapestore="D1" visible="true" |
<layer shapestore="D1" visible="true" title="K\xc3\xbcste"> |
208 |
stroke="#000000" title="K\xc3\xbcste" stroke_width="1" |
<classification> |
209 |
fill="None"/> |
<clnull label=""> |
210 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
211 |
|
</clnull> |
212 |
|
</classification> |
213 |
|
</layer> |
214 |
</map> |
</map> |
215 |
</session> |
</session> |
216 |
''' |
''' |
222 |
self.session = session |
self.session = session |
223 |
|
|
224 |
# Check the title |
# Check the title |
225 |
eq(session.Title(), "Stra\xdfen & Landmarken") |
eq(session.Title(), internal_from_unicode(u"Stra\xdfen & Landmarken")) |
226 |
|
|
227 |
# the session has one map. |
# the session has one map. |
228 |
maps = session.Maps() |
maps = session.Maps() |
230 |
|
|
231 |
# Check the map's attributes |
# Check the map's attributes |
232 |
map = maps[0] |
map = maps[0] |
233 |
eq(map.Title(), "\xdcbersicht") |
eq(map.Title(), internal_from_unicode(u"\xdcbersicht")) |
234 |
proj = map.GetProjection() |
proj = map.GetProjection() |
235 |
eq(proj.GetName(), "WGS 84 / UTM zone 27N") |
eq(proj.GetName(), "WGS 84 / UTM zone 27N") |
236 |
eq(proj.EPSGCode(), "32627") |
eq(proj.EPSGCode(), "32627") |
245 |
|
|
246 |
# Check the layer attributes |
# Check the layer attributes |
247 |
layer = layers[0] |
layer = layers[0] |
248 |
eq(layer.Title(), "K\xfcste") |
eq(layer.Title(), internal_from_unicode(u"K\xfcste")) |
249 |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
250 |
os.path.join(self.temp_dir(), |
os.path.join(self.temp_dir(), |
251 |
os.pardir, os.pardir, |
os.pardir, os.pardir, |
300 |
<parameter value="units=m"/> |
<parameter value="units=m"/> |
301 |
<parameter value="zone=27"/> |
<parameter value="zone=27"/> |
302 |
</projection> |
</projection> |
303 |
<layer shapestore="D1" visible="true" |
<layer shapestore="D1" visible="true" title="layer"> |
|
stroke="#000000" title="layer" stroke_width="1" |
|
|
fill="None"> |
|
304 |
<classification field="Fl\xc3\xa4che" field_type="double"> |
<classification field="Fl\xc3\xa4che" field_type="double"> |
305 |
<clnull label=""> |
<clnull label=""> |
306 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
373 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
374 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
375 |
</projection> |
</projection> |
376 |
<layer shapestore="D1" visible="false" stroke="#000000" |
<layer shapestore="D1" visible="false" title="My Layer"> |
377 |
title="My Layer" stroke_width="1" fill="None"/> |
<classification> |
378 |
|
<clnull label=""> |
379 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
380 |
|
</clnull> |
381 |
|
</classification> |
382 |
|
</layer> |
383 |
</map> |
</map> |
384 |
</session> |
</session> |
385 |
''' |
''' |
409 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session"> |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session"> |
410 |
<fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/> |
<fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/> |
411 |
<map title="Iceland map"> |
<map title="Iceland map"> |
412 |
<layer title="cultural_landmark-point" stroke_width="1" shapestore="D813968480" visible="true" stroke="#000000" fill="#000000"> |
<layer title="cultural_landmark-point" shapestore="D813968480" visible="true"> |
413 |
<classification field="CLPTLABEL" field_type="string"> |
<classification field="CLPTLABEL" field_type="string"> |
414 |
<clnull label=""> |
<clnull label=""> |
415 |
<cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/> |
<cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/> |
459 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
460 |
<fileshapesource filetype="shapefile" id="D138504492" |
<fileshapesource filetype="shapefile" id="D138504492" |
461 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
462 |
|
<fileshapesource filetype="shapefile" id="D123456789" |
463 |
|
filename="../../Data/iceland/cultural_landmark-point.shp"/> |
464 |
<map title="Test Map"> |
<map title="Test Map"> |
465 |
<projection name=""> |
<projection name=""> |
466 |
<parameter value="zone=26"/> |
<parameter value="zone=26"/> |
467 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
468 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
469 |
</projection> |
</projection> |
470 |
<layer shapestore="D138389860" visible="true" stroke="#000000" |
<layer shapestore="D138389860" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
471 |
<classification field="POPYREG" field_type="string"> |
<classification field="POPYREG" field_type="string"> |
472 |
<clnull label=""> |
<clnull label=""> |
473 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
484 |
</clpoint> |
</clpoint> |
485 |
</classification> |
</classification> |
486 |
</layer> |
</layer> |
487 |
<layer shapestore="D138504492" visible="true" stroke="#000000" |
<layer shapestore="D138504492" visible="true" title="My Layer 2"> |
|
title="My Layer 2" stroke_width="2" fill="None"> |
|
488 |
<classification field="AREA" field_type="double"> |
<classification field="AREA" field_type="double"> |
489 |
<clnull label=""> |
<clnull label=""> |
490 |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
503 |
</clpoint> |
</clpoint> |
504 |
</classification> |
</classification> |
505 |
</layer> |
</layer> |
506 |
|
<layer shapestore="D123456789" visible="true" title="My Layer 3"> |
507 |
|
<classification field="CLPTLABEL" field_type="string"> |
508 |
|
<clnull label=""> |
509 |
|
<cldata stroke="#000000" size="5" stroke_width="2" fill="None"/> |
510 |
|
</clnull> |
511 |
|
<clpoint label="" value="FARM"> |
512 |
|
<cldata stroke="#111111" size="5" stroke_width="1" fill="None"/> |
513 |
|
</clpoint> |
514 |
|
<clpattern label="" pattern="BUI"> |
515 |
|
<cldata stroke="#000000" size="5" stroke_width="1" fill="None"/> |
516 |
|
</clpattern> |
517 |
|
</classification> |
518 |
|
</layer> |
519 |
</map> |
</map> |
520 |
</session> |
</session> |
521 |
''' |
''' |
534 |
("#000000", 2, "None")), |
("#000000", 2, "None")), |
535 |
("single", "1", "", |
("single", "1", "", |
536 |
("#000000", 10, "None")), |
("#000000", 10, "None")), |
537 |
("single", "\xe4\xf6\xfc", "\xdcml\xe4uts", |
("single", internal_from_unicode(u"\xe4\xf6\xfc"), |
538 |
|
internal_from_unicode(u"\xdcml\xe4uts"), |
539 |
("#000000", 1, "None"))]), |
("#000000", 1, "None"))]), |
540 |
("My Layer 2", 4, |
("My Layer 2", 4, |
541 |
[("default", (), "", |
[("default", (), "", |
547 |
("range", (-1, 0), "", |
("range", (-1, 0), "", |
548 |
("#000000", 1, "None")), |
("#000000", 1, "None")), |
549 |
("single", -.5, "", |
("single", -.5, "", |
550 |
("#000000", 1, "None"))])] |
("#000000", 1, "None"))]), |
551 |
|
("My Layer 3", 2, |
552 |
|
[("default", (), "", |
553 |
|
("#000000", 2, "None")), |
554 |
|
("single", "FARM", "", |
555 |
|
("#111111", 1, "None")), |
556 |
|
("pattern", "BUI", "", |
557 |
|
("#000000", 1, "None"))]), |
558 |
|
] |
559 |
|
|
560 |
self.TestLayers(map.Layers(), expected) |
self.TestLayers(map.Layers(), expected) |
561 |
|
|
577 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
578 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
579 |
</projection> |
</projection> |
580 |
<layer shapestore="D1" visible="true" stroke="#000000" |
<layer shapestore="D1" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
581 |
<classification field="POPYREG" field_type="string"> |
<classification field="POPYREG" field_type="string"> |
582 |
<clnull label="hallo"> |
<clnull label="hallo"> |
583 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
626 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
627 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
628 |
</projection> |
</projection> |
629 |
<layer shapestore="D4" visible="true" stroke="#000000" |
<layer shapestore="D4" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
630 |
<projection name="hello"> |
<projection name="hello"> |
631 |
<parameter value="zone=13"/> |
<parameter value="zone=13"/> |
632 |
<parameter value="proj=tmerc"/> |
<parameter value="proj=tmerc"/> |
641 |
</clpoint> |
</clpoint> |
642 |
</classification> |
</classification> |
643 |
</layer> |
</layer> |
644 |
<layer shapestore="D2" visible="true" stroke="#000000" |
<layer shapestore="D2" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
645 |
<projection name="Unknown"> |
<projection name="Unknown"> |
646 |
<parameter value="proj=lcc"/> |
<parameter value="proj=lcc"/> |
647 |
<parameter value="lat_1=10"/> |
<parameter value="lat_1=10"/> |
648 |
<parameter value="lat_2=20"/> |
<parameter value="lat_2=20"/> |
649 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
650 |
</projection> |
</projection> |
651 |
|
<classification> |
652 |
|
<clnull label=""> |
653 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
654 |
|
</clnull> |
655 |
|
</classification> |
656 |
</layer> |
</layer> |
657 |
</map> |
</map> |
658 |
</session> |
</session> |
699 |
title="single map&layer"> |
title="single map&layer"> |
700 |
<map title="Test Map"> |
<map title="Test Map"> |
701 |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
702 |
title="My RasterLayer"/> |
title="My RasterLayer" opacity="0.4" masktype="alpha"/> |
703 |
</map> |
</map> |
704 |
</session> |
</session> |
705 |
''' |
''' |
716 |
layer = map.Layers()[0] # one layer in the sample |
layer = map.Layers()[0] # one layer in the sample |
717 |
|
|
718 |
eq(layer.Title(), "My RasterLayer") |
eq(layer.Title(), "My RasterLayer") |
719 |
|
eq(layer.Opacity(), 0.4) |
720 |
|
eq(layer.MaskType(), layer.MASK_ALPHA) |
721 |
|
|
722 |
self.failIf(layer.Visible()) |
self.failIf(layer.Visible()) |
723 |
self.failUnless(filenames_equal(layer.GetImageFilename(), |
self.failUnless(filenames_equal(layer.GetImageFilename(), |
724 |
os.path.join(self.temp_dir(), |
os.path.join(self.temp_dir(), |
744 |
<derivedshapesource table="D136169900" shapesource="D137227612" |
<derivedshapesource table="D136169900" shapesource="D137227612" |
745 |
id="D136170932"/> |
id="D136170932"/> |
746 |
<map title="Test Map"> |
<map title="Test Map"> |
747 |
<layer shapestore="D136170932" visible="true" stroke="#000000" |
<layer shapestore="D136170932" visible="true" title="My Layer"> |
748 |
title="My Layer" stroke_width="1" fill="None"/> |
<classification> |
749 |
|
<clnull label=""> |
750 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
751 |
|
</clnull> |
752 |
|
</classification> |
753 |
|
</layer> |
754 |
</map> |
</map> |
755 |
</session> |
</session> |
756 |
''' |
''' |
799 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
800 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
801 |
</projection> |
</projection> |
802 |
<layer shapestore="D145265052" visible="true" stroke="#000000" |
<layer shapestore="D145265052" visible="true" title="political"> |
|
title="political" stroke_width="1" fill="#c0c0c0"> |
|
803 |
<projection name="Geographic"> |
<projection name="Geographic"> |
804 |
<parameter value="proj=latlong"/> |
<parameter value="proj=latlong"/> |
805 |
<parameter value="to_meter=0.017453"/> |
<parameter value="to_meter=0.017453"/> |
806 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
807 |
</projection> |
</projection> |
808 |
|
<classification> |
809 |
|
<clnull label=""> |
810 |
|
<cldata stroke="#000000" stroke_width="1" fill="#c0c0c0"/> |
811 |
|
</clnull> |
812 |
|
</classification> |
813 |
</layer> |
</layer> |
814 |
<layer shapestore="D145412868" visible="true" stroke="#000000" |
<layer shapestore="D145412868" visible="true" title="landmarks"> |
|
title="landmarks" stroke_width="1" fill="#ffff00"> |
|
815 |
<projection name="Geographic"> |
<projection name="Geographic"> |
816 |
<parameter value="proj=latlong"/> |
<parameter value="proj=latlong"/> |
817 |
<parameter value="to_meter=0.017453"/> |
<parameter value="to_meter=0.017453"/> |
818 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
819 |
</projection> |
</projection> |
820 |
|
<classification> |
821 |
|
<clnull label=""> |
822 |
|
<cldata size="5" stroke="#000000" stroke_width="1" fill="#ffff00"/> |
823 |
|
</clnull> |
824 |
|
</classification> |
825 |
</layer> |
</layer> |
826 |
<labellayer> |
<labellayer> |
827 |
<label x="-21.5" y="64.25" text="RUINS" |
<label x="-21.5" y="64.25" text="RUINS" |
840 |
|
|
841 |
label_layer = self.session.Maps()[0].LabelLayer() |
label_layer = self.session.Maps()[0].LabelLayer() |
842 |
expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER), |
expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER), |
843 |
(-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP), |
(-15.125, 64.75, internal_from_unicode(u"H\xfctte"), |
844 |
|
ALIGN_RIGHT, ALIGN_TOP), |
845 |
] |
] |
846 |
for label, values in zip(label_layer.Labels(), expected_labels): |
for label, values in zip(label_layer.Labels(), expected_labels): |
847 |
self.assertEquals((label.x, label.y, label.text, label.halign, |
self.assertEquals((label.x, label.y, label.text, label.halign, |
1097 |
|
|
1098 |
def test_01_single_path_error_fix(self): |
def test_01_single_path_error_fix(self): |
1099 |
"""Test single file path error fix.""" |
"""Test single file path error fix.""" |
|
|
|
|
eq = self.assertEquals |
|
|
|
|
1100 |
# The usual initial case |
# The usual initial case |
1101 |
s_cb = Shapefile_CallBack({ |
s_cb = Shapefile_CallBack({ |
1102 |
"search": [("../Data/iceland/roads-line.shp",0)], |
"search": [("../Data/iceland/roads-line.shp",0)], |