21 |
support.initthuban() |
support.initthuban() |
22 |
|
|
23 |
from Thuban import _ |
from Thuban import _ |
24 |
from Thuban.Model.proj import Projection, ProjFile |
from Thuban.Model.proj import Projection, ProjFile, \ |
25 |
|
PROJ_UNITS_METERS, PROJ_UNITS_DEGREES |
26 |
|
|
27 |
import Thuban.Model.resource as resource |
import Thuban.Model.resource as resource |
28 |
|
|
71 |
proj = Projection(params, "MyName") |
proj = Projection(params, "MyName") |
72 |
self.assertEquals(proj.GetName(), "MyName") |
self.assertEquals(proj.GetName(), "MyName") |
73 |
|
|
74 |
|
def test_get_projection_units_geo(self): |
75 |
|
"""Test Projection.GetProjectedUnits() for geographic projection""" |
76 |
|
proj = Projection(["proj=latlong", "to_meter=0.017453292519943295", |
77 |
|
"ellps=clrk66"]) |
78 |
|
self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_DEGREES) |
79 |
|
|
80 |
|
def test_get_projection_units_normal(self): |
81 |
|
"""Test Projection.GetProjectedUnits() for normal projection""" |
82 |
|
proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"]) |
83 |
|
self.assertEquals(proj.GetProjectedUnits(), PROJ_UNITS_METERS) |
84 |
|
|
85 |
|
|
86 |
sample_projfile = '''\ |
sample_projfile = '''\ |
87 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
265 |
file.write(input) |
file.write(input) |
266 |
file.close() |
file.close() |
267 |
|
|
268 |
pf = resource.read_proj_file(filename) |
pf, warnings = resource.read_proj_file(filename) |
269 |
|
self.assertEquals(warnings, []) |
270 |
|
|
271 |
eq = self.assertEquals |
eq = self.assertEquals |
272 |
|
|
277 |
for param in proj.GetAllParameters(): |
for param in proj.GetAllParameters(): |
278 |
self.assert_(param in d[1]) |
self.assert_(param in d[1]) |
279 |
|
|
280 |
|
def test_get_system_proj_file(self): |
281 |
|
"""Test resource.get_system_proj_file() |
282 |
|
|
283 |
|
This is primarily to test whether the system proj file contains |
284 |
|
invalid projection paramers and whether the proj file is not |
285 |
|
empty |
286 |
|
""" |
287 |
|
projfile, warnings = resource.get_system_proj_file() |
288 |
|
self.assertEquals(warnings, []) |
289 |
|
self.assert_(len(projfile.GetProjections()) > 0) |
290 |
|
|
291 |
|
|
292 |
|
class TestProjFileWithInvalidParameters(unittest.TestCase, |
293 |
|
support.FileLoadTestCase): |
294 |
|
|
295 |
|
file_extension = ".proj" |
296 |
|
file_contents = '''\ |
297 |
|
<?xml version="1.0" encoding="UTF-8"?> |
298 |
|
<!DOCTYPE projectionlist SYSTEM "projfile.dtd"> |
299 |
|
<projectionlist> |
300 |
|
<projection name="Universal Transverse Mercator"> |
301 |
|
<parameter value="proj=utm"/> |
302 |
|
<parameter value="ellps=clrk66"/> |
303 |
|
<!-- an invalid zone number to trigger the parameter checking |
304 |
|
in the proj library --> |
305 |
|
<parameter value="zone=1000"/> |
306 |
|
</projection> |
307 |
|
<projection name="Transverse Mercator"> |
308 |
|
<parameter value="proj=tmerc"/> |
309 |
|
<parameter value="ellps=clrk66"/> |
310 |
|
<parameter value="lat_0=90w"/> |
311 |
|
<parameter value="lon_0=90w"/> |
312 |
|
<parameter value="k=1"/> |
313 |
|
</projection> |
314 |
|
</projectionlist> |
315 |
|
''' |
316 |
|
|
317 |
|
def setUp(self): |
318 |
|
support.FileLoadTestCase.setUp(self) |
319 |
|
|
320 |
|
def test(self): |
321 |
|
"""Test reading a proj file with invalid parameters""" |
322 |
|
projfile, warnings = resource.read_proj_file(self.filename()) |
323 |
|
projs = projfile.GetProjections() |
324 |
|
self.assertEquals(len(projs), 1) |
325 |
|
params = projs[0].GetAllParameters()[:] |
326 |
|
params.sort() |
327 |
|
self.assertEquals(params, ['ellps=clrk66', 'k=1', 'lat_0=90w', |
328 |
|
'lon_0=90w', 'proj=tmerc']) |
329 |
|
self.assertEquals(warnings, |
330 |
|
['Error in projection "Universal Transverse Mercator":' |
331 |
|
' invalid UTM zone number']) |
332 |
|
|
333 |
|
|
334 |
|
|
335 |
if __name__ == "__main__": |
if __name__ == "__main__": |
336 |
unittest.main() |
unittest.main() |