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 Thuban.Model.wellknowntext""" |
9 |
|
10 |
__version__ = "$Revision$" |
11 |
# $Source$ |
12 |
# $Id$ |
13 |
|
14 |
import unittest |
15 |
|
16 |
import support |
17 |
support.initthuban() |
18 |
|
19 |
from Thuban.Model.wellknowntext import parse_wkt_thuban |
20 |
|
21 |
|
22 |
class TestWKT(unittest.TestCase, support.FloatComparisonMixin): |
23 |
|
24 |
def test_point(self): |
25 |
"""Test WKT parsing of POINT geometries""" |
26 |
wkt = "SRID=1;POINT(6554860 967048)" |
27 |
self.assertPointListEquals(parse_wkt_thuban(wkt), |
28 |
[[(6554860, 967048)]]) |
29 |
|
30 |
def test_multilinestring(self): |
31 |
"""Test WKT parsing of MULTILINESTRING geometries""" |
32 |
wkt = ("MULTILINESTRING((" |
33 |
"(6489598.51 867720.64," |
34 |
"6489593.90 867837.42)," |
35 |
"(6489624.12 867714.83," |
36 |
"6489629.83 867621.31," |
37 |
"6489616.35 867552.57," |
38 |
"6489608.31 867507.10)," |
39 |
"(6489902.89 868153.54," |
40 |
"6489880.85 868167.12," |
41 |
"6489837.96 868136.41," |
42 |
"6489788.94 868071.37)))") |
43 |
self.assertPointListEquals(parse_wkt_thuban(wkt), |
44 |
[[(6489598.51, 867720.64), |
45 |
(6489593.90, 867837.42)], |
46 |
[(6489624.12, 867714.83), |
47 |
(6489629.83, 867621.31), |
48 |
(6489616.35, 867552.57), |
49 |
(6489608.31, 867507.10)], |
50 |
[(6489902.89, 868153.54), |
51 |
(6489880.85, 868167.12), |
52 |
(6489837.96, 868136.41), |
53 |
(6489788.94, 868071.37)]]) |
54 |
|
55 |
def test_polygon(self): |
56 |
"""Test WKT parsing of POLYGON geometries""" |
57 |
wkt = ("SRID=1;POLYGON((6545639.323878 961209.599602," |
58 |
"6545630.08526 961213.426864,6545617.99819 961184.249912," |
59 |
"6545627.236809 961180.422651,6545639.323878 961209.599602))") |
60 |
self.assertPointListEquals(parse_wkt_thuban(wkt), |
61 |
[[(6545639.323878, 961209.599602), |
62 |
(6545630.08526, 961213.426864), |
63 |
(6545617.99819, 961184.249912), |
64 |
(6545627.236809, 961180.422651), |
65 |
(6545639.323878, 961209.599602)]]) |
66 |
|
67 |
def test_errors(self): |
68 |
"""Test WKT parsing error detection""" |
69 |
# empty strings cause value errors |
70 |
self.assertRaises(ValueError, parse_wkt_thuban, "") |
71 |
# strings with only an SRID cause value errors |
72 |
self.assertRaises(ValueError, parse_wkt_thuban, "SRID=1") |
73 |
|
74 |
# Missing parentheses cause value errors |
75 |
self.assertRaises(ValueError, parse_wkt_thuban, "POINT(10 20") |
76 |
|
77 |
|
78 |
if __name__ == "__main__": |
79 |
support.run_tests() |