18 |
import support |
import support |
19 |
support.initthuban() |
support.initthuban() |
20 |
|
|
21 |
from Thuban.Model.proj import Projection |
from Thuban.Model.proj import Projection, ProjFile |
22 |
|
|
23 |
|
import Thuban.Model.resource as resource |
24 |
|
|
25 |
|
from test_save import sax_eventlist |
26 |
|
|
27 |
|
|
28 |
class TestProjection(unittest.TestCase, support.FloatComparisonMixin): |
class TestProjection(unittest.TestCase, support.FloatComparisonMixin): |
48 |
3875381.8535437919, 252962.10480170773), |
3875381.8535437919, 252962.10480170773), |
49 |
epsilon = 1e-5) |
epsilon = 1e-5) |
50 |
|
|
51 |
|
self.assertEquals(proj.GetParameter("zone"), "26") |
52 |
|
self.assertEquals(proj.GetParameter("proj"), "utm") |
53 |
|
self.assertEquals(proj.GetParameter("ellps"), "clrk66") |
54 |
|
self.assertEquals(proj.GetParameter("hallo"), "") |
55 |
|
|
56 |
|
|
57 |
|
sample_projfile = '''\ |
58 |
|
<?xml version="1.0" encoding="UTF-8"?> |
59 |
|
<!DOCTYPE projfile SYSTEM "thuban.dtd"> |
60 |
|
<projectionlist> |
61 |
|
<projection name="Transverse Mercartor"> |
62 |
|
<parameter value="proj=tmerc"/> |
63 |
|
<parameter value="ellps=clrk66"/> |
64 |
|
<parameter value="lat_0=90w"/> |
65 |
|
<parameter value="lon_0=90w"/> |
66 |
|
<parameter value="k=1"/> |
67 |
|
</projection> |
68 |
|
<projection name="Transverse Mercartor"> |
69 |
|
<parameter value="proj=tmerc"/> |
70 |
|
<parameter value="ellps=clrk66"/> |
71 |
|
<parameter value="lat_0=30w"/> |
72 |
|
<parameter value="lon_0=30w"/> |
73 |
|
<parameter value="k=1"/> |
74 |
|
</projection> |
75 |
|
<projection name="Universal Transverse Mercartor"> |
76 |
|
<parameter value="proj=utm"/> |
77 |
|
<parameter value="ellps=clrk66"/> |
78 |
|
<parameter value="zone=1"/> |
79 |
|
</projection> |
80 |
|
</projectionlist> |
81 |
|
''' |
82 |
|
|
83 |
|
sample_projfile_data = [("Transverse Mercartor", ["proj=tmerc", |
84 |
|
"ellps=clrk66", |
85 |
|
"lat_0=90w", |
86 |
|
"lon_0=90w", |
87 |
|
"k=1"]), |
88 |
|
("Transverse Mercartor", ["proj=tmerc", |
89 |
|
"ellps=clrk66", |
90 |
|
"lat_0=30w", |
91 |
|
"lon_0=30w", |
92 |
|
"k=1"]), |
93 |
|
("Universal Transverse Mercartor", ["proj=utm", |
94 |
|
"ellps=clrk66", |
95 |
|
"zone=1"])] |
96 |
|
|
97 |
|
sample_projfile2 = '''\ |
98 |
|
<?xml version="1.0" encoding="UTF-8"?> |
99 |
|
<!DOCTYPE projfile SYSTEM "thuban.dtd"> |
100 |
|
<projectionlist> |
101 |
|
</projectionlist> |
102 |
|
''' |
103 |
|
|
104 |
|
sample_projfile_data2 = [] |
105 |
|
|
106 |
|
class TestProjFile(unittest.TestCase, support.FileTestMixin): |
107 |
|
|
108 |
|
"""Test cases for reading and writing projection files. |
109 |
|
""" |
110 |
|
|
111 |
|
def compare_xml(self, xml1, xml2): |
112 |
|
self.assertEquals(sax_eventlist(xml1), sax_eventlist(xml2)) |
113 |
|
|
114 |
|
def testRead(self): |
115 |
|
"""Test ReadProjFile""" |
116 |
|
|
117 |
|
self.doTestRead(sample_projfile_data, sample_projfile) |
118 |
|
self.doTestRead(sample_projfile_data2, sample_projfile2) |
119 |
|
|
120 |
|
def testWrite(self): |
121 |
|
"""Test WriteProjFile""" |
122 |
|
|
123 |
|
self.doTestWrite(sample_projfile_data, sample_projfile) |
124 |
|
self.doTestWrite(sample_projfile_data2, sample_projfile2) |
125 |
|
|
126 |
|
def doTestWrite(self, data, expected): |
127 |
|
|
128 |
|
filename = self.temp_file_name("projfile.proj") |
129 |
|
|
130 |
|
pf = ProjFile(filename) |
131 |
|
for proj in data: |
132 |
|
pf.Add(Projection(proj[1], proj[0])) |
133 |
|
|
134 |
|
resource.WriteProjFile(pf) |
135 |
|
|
136 |
|
file = open(filename) |
137 |
|
written_contents = file.read() |
138 |
|
file.close() |
139 |
|
self.compare_xml(written_contents, expected) |
140 |
|
|
141 |
|
def doTestRead(self, data, input): |
142 |
|
|
143 |
|
filename = self.temp_file_name("projfile.proj") |
144 |
|
file = open(filename, "w") |
145 |
|
file.write(input) |
146 |
|
file.close() |
147 |
|
|
148 |
|
pf = resource.ReadProjFile(filename) |
149 |
|
|
150 |
|
eq = self.assertEquals |
151 |
|
|
152 |
|
eq(pf.GetFileName(), filename) |
153 |
|
|
154 |
|
for proj, d in zip(pf.GetProjections(), data): |
155 |
|
eq(proj.GetName(), d[0]) |
156 |
|
for param in proj.GetAllParameters(): |
157 |
|
self.assert_(param in d[1]) |
158 |
|
|
159 |
|
|
160 |
if __name__ == "__main__": |
if __name__ == "__main__": |