1 |
# Copyright (C) 2003 by Intevation GmbH |
2 |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
4 |
# |
5 |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with the software for details. |
7 |
|
8 |
"""Test cases for wxproj""" |
9 |
|
10 |
__version__ = "$Revision$" |
11 |
# $Source$ |
12 |
# $Id$ |
13 |
|
14 |
import os |
15 |
import unittest |
16 |
|
17 |
import support |
18 |
support.initthuban() |
19 |
|
20 |
import shapelib |
21 |
from wxproj import shape_centroid |
22 |
from Thuban.Model.proj import Projection |
23 |
|
24 |
|
25 |
class TestShapeCentroid(unittest.TestCase, support.FloatComparisonMixin): |
26 |
|
27 |
"""Test cases for wxproj.shape_centroid()""" |
28 |
|
29 |
def setUp(self): |
30 |
filename = os.path.join("..", "Data", "iceland", "political.shp") |
31 |
self.shapefile = shapelib.ShapeFile(filename) |
32 |
self.map_proj = Projection(["proj=utm", "zone=26", "ellps=clrk66"]) |
33 |
self.layer_proj = Projection(["proj=latlong", |
34 |
"to_meter=0.017453292519943295", |
35 |
"ellps=clrk66"]) |
36 |
|
37 |
def test_no_proj(self): |
38 |
"""Test shape_centroid without any projections""" |
39 |
self.assertFloatSeqEqual(shape_centroid(self.shapefile.cobject(), 0, |
40 |
None, None, |
41 |
1, 1, 0, 0), |
42 |
(-22.5514848648, 64.7794567309)) |
43 |
|
44 |
def test_map_proj(self): |
45 |
"""Test shape_centroid with map projection""" |
46 |
self.assertFloatSeqEqual(shape_centroid(self.shapefile.cobject(), 0, |
47 |
self.map_proj, None, |
48 |
1, 1, 0, 0), |
49 |
(711378, 7191110), |
50 |
epsilon = 1) |
51 |
|
52 |
def test_layer_proj(self): |
53 |
"""Test shape_centroid with layer projection""" |
54 |
self.assertFloatSeqEqual(shape_centroid(self.shapefile.cobject(), 0, |
55 |
None, self.layer_proj, |
56 |
1, 1, 0, 0), |
57 |
(-22.5514848648, 64.7794567309)) |
58 |
|
59 |
def test_both_proj(self): |
60 |
"""Test shape_centroid with map and layer projection""" |
61 |
self.assertFloatSeqEqual(shape_centroid(self.shapefile.cobject(), 0, |
62 |
self.map_proj, self.layer_proj, |
63 |
1, 1, 0, 0), |
64 |
(711378, 7191110), |
65 |
epsilon=1) |
66 |
|
67 |
def test_invalid_shape_id(self): |
68 |
"""Test shape_centroid without an invalid shape id""" |
69 |
self.assertRaises(ValueError, shape_centroid, |
70 |
self.shapefile.cobject(), -1, None, None, |
71 |
1, 1, 0, 0) |
72 |
self.assertRaises(ValueError, shape_centroid, |
73 |
self.shapefile.cobject(), 1000000, None, None, |
74 |
1, 1, 0, 0) |
75 |
|
76 |
if __name__ == "__main__": |
77 |
support.run_tests() |