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 |
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 |
|
|
201 |
<parameter value="units=m"/> |
<parameter value="units=m"/> |
202 |
<parameter value="zone=27"/> |
<parameter value="zone=27"/> |
203 |
</projection> |
</projection> |
204 |
<layer shapestore="D1" visible="true" |
<layer shapestore="D1" visible="true" title="K\xc3\xbcste"> |
205 |
stroke="#000000" title="K\xc3\xbcste" stroke_width="1" |
<classification> |
206 |
fill="None"/> |
<clnull label=""> |
207 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
208 |
|
</clnull> |
209 |
|
</classification> |
210 |
|
</layer> |
211 |
</map> |
</map> |
212 |
</session> |
</session> |
213 |
''' |
''' |
219 |
self.session = session |
self.session = session |
220 |
|
|
221 |
# Check the title |
# Check the title |
222 |
eq(session.Title(), "Stra\xdfen & Landmarken") |
eq(session.Title(), internal_from_unicode(u"Stra\xdfen & Landmarken")) |
223 |
|
|
224 |
# the session has one map. |
# the session has one map. |
225 |
maps = session.Maps() |
maps = session.Maps() |
227 |
|
|
228 |
# Check the map's attributes |
# Check the map's attributes |
229 |
map = maps[0] |
map = maps[0] |
230 |
eq(map.Title(), "\xdcbersicht") |
eq(map.Title(), internal_from_unicode(u"\xdcbersicht")) |
231 |
proj = map.GetProjection() |
proj = map.GetProjection() |
232 |
eq(proj.GetName(), "WGS 84 / UTM zone 27N") |
eq(proj.GetName(), "WGS 84 / UTM zone 27N") |
233 |
eq(proj.EPSGCode(), "32627") |
eq(proj.EPSGCode(), "32627") |
242 |
|
|
243 |
# Check the layer attributes |
# Check the layer attributes |
244 |
layer = layers[0] |
layer = layers[0] |
245 |
eq(layer.Title(), "K\xfcste") |
eq(layer.Title(), internal_from_unicode(u"K\xfcste")) |
246 |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
247 |
os.path.join(self.temp_dir(), |
os.path.join(self.temp_dir(), |
248 |
os.pardir, os.pardir, |
os.pardir, os.pardir, |
297 |
<parameter value="units=m"/> |
<parameter value="units=m"/> |
298 |
<parameter value="zone=27"/> |
<parameter value="zone=27"/> |
299 |
</projection> |
</projection> |
300 |
<layer shapestore="D1" visible="true" |
<layer shapestore="D1" visible="true" title="layer"> |
|
stroke="#000000" title="layer" stroke_width="1" |
|
|
fill="None"> |
|
301 |
<classification field="Fl\xc3\xa4che" field_type="double"> |
<classification field="Fl\xc3\xa4che" field_type="double"> |
302 |
<clnull label=""> |
<clnull label=""> |
303 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
370 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
371 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
372 |
</projection> |
</projection> |
373 |
<layer shapestore="D1" visible="false" stroke="#000000" |
<layer shapestore="D1" visible="false" title="My Layer"> |
374 |
title="My Layer" stroke_width="1" fill="None"/> |
<classification> |
375 |
|
<clnull label=""> |
376 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
377 |
|
</clnull> |
378 |
|
</classification> |
379 |
|
</layer> |
380 |
</map> |
</map> |
381 |
</session> |
</session> |
382 |
''' |
''' |
406 |
<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"> |
407 |
<fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/> |
<fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/> |
408 |
<map title="Iceland map"> |
<map title="Iceland map"> |
409 |
<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"> |
410 |
<classification field="CLPTLABEL" field_type="string"> |
<classification field="CLPTLABEL" field_type="string"> |
411 |
<clnull label=""> |
<clnull label=""> |
412 |
<cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/> |
<cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/> |
462 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
463 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
464 |
</projection> |
</projection> |
465 |
<layer shapestore="D138389860" visible="true" stroke="#000000" |
<layer shapestore="D138389860" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
466 |
<classification field="POPYREG" field_type="string"> |
<classification field="POPYREG" field_type="string"> |
467 |
<clnull label=""> |
<clnull label=""> |
468 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
479 |
</clpoint> |
</clpoint> |
480 |
</classification> |
</classification> |
481 |
</layer> |
</layer> |
482 |
<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"> |
|
483 |
<classification field="AREA" field_type="double"> |
<classification field="AREA" field_type="double"> |
484 |
<clnull label=""> |
<clnull label=""> |
485 |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
516 |
("#000000", 2, "None")), |
("#000000", 2, "None")), |
517 |
("single", "1", "", |
("single", "1", "", |
518 |
("#000000", 10, "None")), |
("#000000", 10, "None")), |
519 |
("single", "\xe4\xf6\xfc", "\xdcml\xe4uts", |
("single", internal_from_unicode(u"\xe4\xf6\xfc"), |
520 |
|
internal_from_unicode(u"\xdcml\xe4uts"), |
521 |
("#000000", 1, "None"))]), |
("#000000", 1, "None"))]), |
522 |
("My Layer 2", 4, |
("My Layer 2", 4, |
523 |
[("default", (), "", |
[("default", (), "", |
551 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
552 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
553 |
</projection> |
</projection> |
554 |
<layer shapestore="D1" visible="true" stroke="#000000" |
<layer shapestore="D1" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
555 |
<classification field="POPYREG" field_type="string"> |
<classification field="POPYREG" field_type="string"> |
556 |
<clnull label="hallo"> |
<clnull label="hallo"> |
557 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
600 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
601 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
602 |
</projection> |
</projection> |
603 |
<layer shapestore="D4" visible="true" stroke="#000000" |
<layer shapestore="D4" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
604 |
<projection name="hello"> |
<projection name="hello"> |
605 |
<parameter value="zone=13"/> |
<parameter value="zone=13"/> |
606 |
<parameter value="proj=tmerc"/> |
<parameter value="proj=tmerc"/> |
615 |
</clpoint> |
</clpoint> |
616 |
</classification> |
</classification> |
617 |
</layer> |
</layer> |
618 |
<layer shapestore="D2" visible="true" stroke="#000000" |
<layer shapestore="D2" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
619 |
<projection name="Unknown"> |
<projection name="Unknown"> |
620 |
<parameter value="proj=lcc"/> |
<parameter value="proj=lcc"/> |
621 |
<parameter value="lat_1=10"/> |
<parameter value="lat_1=10"/> |
622 |
<parameter value="lat_2=20"/> |
<parameter value="lat_2=20"/> |
623 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
624 |
</projection> |
</projection> |
625 |
|
<classification> |
626 |
|
<clnull label=""> |
627 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
628 |
|
</clnull> |
629 |
|
</classification> |
630 |
</layer> |
</layer> |
631 |
</map> |
</map> |
632 |
</session> |
</session> |
673 |
title="single map&layer"> |
title="single map&layer"> |
674 |
<map title="Test Map"> |
<map title="Test Map"> |
675 |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
676 |
title="My RasterLayer"/> |
title="My RasterLayer" opacity="0.4" masktype="alpha"/> |
677 |
</map> |
</map> |
678 |
</session> |
</session> |
679 |
''' |
''' |
690 |
layer = map.Layers()[0] # one layer in the sample |
layer = map.Layers()[0] # one layer in the sample |
691 |
|
|
692 |
eq(layer.Title(), "My RasterLayer") |
eq(layer.Title(), "My RasterLayer") |
693 |
|
eq(layer.Opacity(), 0.4) |
694 |
|
eq(layer.MaskType(), layer.MASK_ALPHA) |
695 |
|
|
696 |
self.failIf(layer.Visible()) |
self.failIf(layer.Visible()) |
697 |
self.failUnless(filenames_equal(layer.GetImageFilename(), |
self.failUnless(filenames_equal(layer.GetImageFilename(), |
698 |
os.path.join(self.temp_dir(), |
os.path.join(self.temp_dir(), |
718 |
<derivedshapesource table="D136169900" shapesource="D137227612" |
<derivedshapesource table="D136169900" shapesource="D137227612" |
719 |
id="D136170932"/> |
id="D136170932"/> |
720 |
<map title="Test Map"> |
<map title="Test Map"> |
721 |
<layer shapestore="D136170932" visible="true" stroke="#000000" |
<layer shapestore="D136170932" visible="true" title="My Layer"> |
722 |
title="My Layer" stroke_width="1" fill="None"/> |
<classification> |
723 |
|
<clnull label=""> |
724 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
725 |
|
</clnull> |
726 |
|
</classification> |
727 |
|
</layer> |
728 |
</map> |
</map> |
729 |
</session> |
</session> |
730 |
''' |
''' |
773 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
774 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
775 |
</projection> |
</projection> |
776 |
<layer shapestore="D145265052" visible="true" stroke="#000000" |
<layer shapestore="D145265052" visible="true" title="political"> |
|
title="political" stroke_width="1" fill="#c0c0c0"> |
|
777 |
<projection name="Geographic"> |
<projection name="Geographic"> |
778 |
<parameter value="proj=latlong"/> |
<parameter value="proj=latlong"/> |
779 |
<parameter value="to_meter=0.017453"/> |
<parameter value="to_meter=0.017453"/> |
780 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
781 |
</projection> |
</projection> |
782 |
|
<classification> |
783 |
|
<clnull label=""> |
784 |
|
<cldata stroke="#000000" stroke_width="1" fill="#c0c0c0"/> |
785 |
|
</clnull> |
786 |
|
</classification> |
787 |
</layer> |
</layer> |
788 |
<layer shapestore="D145412868" visible="true" stroke="#000000" |
<layer shapestore="D145412868" visible="true" title="landmarks"> |
|
title="landmarks" stroke_width="1" fill="#ffff00"> |
|
789 |
<projection name="Geographic"> |
<projection name="Geographic"> |
790 |
<parameter value="proj=latlong"/> |
<parameter value="proj=latlong"/> |
791 |
<parameter value="to_meter=0.017453"/> |
<parameter value="to_meter=0.017453"/> |
792 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
793 |
</projection> |
</projection> |
794 |
|
<classification> |
795 |
|
<clnull label=""> |
796 |
|
<cldata size="5" stroke="#000000" stroke_width="1" fill="#ffff00"/> |
797 |
|
</clnull> |
798 |
|
</classification> |
799 |
</layer> |
</layer> |
800 |
<labellayer> |
<labellayer> |
801 |
<label x="-21.5" y="64.25" text="RUINS" |
<label x="-21.5" y="64.25" text="RUINS" |
814 |
|
|
815 |
label_layer = self.session.Maps()[0].LabelLayer() |
label_layer = self.session.Maps()[0].LabelLayer() |
816 |
expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER), |
expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER), |
817 |
(-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP), |
(-15.125, 64.75, internal_from_unicode(u"H\xfctte"), |
818 |
|
ALIGN_RIGHT, ALIGN_TOP), |
819 |
] |
] |
820 |
for label, values in zip(label_layer.Labels(), expected_labels): |
for label, values in zip(label_layer.Labels(), expected_labels): |
821 |
self.assertEquals((label.x, label.y, label.text, label.halign, |
self.assertEquals((label.x, label.y, label.text, label.halign, |