-
-
Notifications
You must be signed in to change notification settings - Fork 302
/
test_vector_algebra.py
193 lines (153 loc) · 9.16 KB
/
test_vector_algebra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
"""
(C) 2014 by the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
for details.
:authors: Soeren Gebbert and Thomas Leppelt
"""
import datetime
import os
import grass.temporal as tgis
from grass.gunittest.case import TestCase
from grass.gunittest.main import test
class TestTemporalVectorAlgebra(TestCase):
@classmethod
def setUpClass(cls):
"""Initiate the temporal GIS and set the region
"""
os.putenv("GRASS_OVERWRITE", "1")
tgis.init(True) # Raise on error instead of exit(1)
cls.use_temp_region()
cls.runModule("g.region", n=80.0, s=0.0, e=120.0,
w=0.0, t=1.0, b=0.0, res=10.0)
cls.runModule("v.random", quiet=True, npoints=20, seed=1, output='a1')
cls.runModule("v.random", quiet=True, npoints=20, seed=1, output='a2')
cls.runModule("v.random", quiet=True, npoints=20, seed=1, output='a3')
cls.runModule("v.random", quiet=True, npoints=20, seed=1, output='a4')
cls.runModule("v.random", quiet=True, npoints=20, seed=2, output='b1')
cls.runModule("v.random", quiet=True, npoints=20, seed=2, output='b2')
cls.runModule("v.random", quiet=True, npoints=20, seed=3, output='c1')
cls.runModule("v.random", quiet=True, npoints=20, seed=4, output='d1')
cls.runModule("v.random", quiet=True, npoints=20, seed=4, output='d2')
cls.runModule("v.random", quiet=True, npoints=20, seed=4, output='d3')
cls.runModule("v.random", quiet=True, npoints=20, seed=5, output='singletmap')
cls.runModule("v.random", quiet=True, npoints=20, seed=6, output='singlemap')
tgis.open_new_stds(name="A", type="stvds", temporaltype="absolute",
title="A", descr="A", semantic="field")
tgis.open_new_stds(name="B", type="stvds", temporaltype="absolute",
title="B", descr="B", semantic="field")
tgis.open_new_stds(name="C", type="stvds", temporaltype="absolute",
title="B", descr="C", semantic="field")
tgis.open_new_stds(name="D", type="stvds", temporaltype="absolute",
title="D", descr="D", semantic="field")
tgis.register_maps_in_space_time_dataset(type="vector", name="A", maps="a1,a2,a3,a4",
start="2001-01-01", increment="1 day", interval=True)
tgis.register_maps_in_space_time_dataset(type="vector", name="B", maps="b1,b2",
start="2001-01-01", increment="2 day", interval=True)
tgis.register_maps_in_space_time_dataset(type="vector", name="C", maps="c1",
start="2001-01-02", increment="2 day", interval=True)
tgis.register_maps_in_space_time_dataset(type="vector", name="D", maps="d1,d2,d3",
start="2001-01-03", increment="1 day", interval=True)
tgis.register_maps_in_space_time_dataset(type="vector", name=None, maps="singletmap",
start="2001-01-03", end="2001-01-04")
def tearDown(self):
self.runModule("t.remove", type="stvds", inputs="R", quiet=True)
@classmethod
def tearDownClass(cls):
"""Remove the temporary region
"""
cls.runModule("t.remove", flags="rf", inputs="A,B,C,D", type='stvds', quiet=True)
cls.del_temp_region()
def test_temporal_select(self):
"""Testing the temporal select operator. """
self.assertModule("t.vect.algebra", expression="R = A : A", basename="r")
D = tgis.open_old_stds("R", type="stvds")
self.assertEqual(D.metadata.get_number_of_maps(), 4)
self.assertEqual(D.metadata.get_number_of_points(), 80)
self.assertEqual(D.metadata.get_number_of_areas(), 0)
self.assertEqual(D.metadata.get_number_of_centroids(), 0)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_select_operators(self):
"""Testing the temporal select operator. Including temporal relations. """
self.assertModule("t.vect.algebra", expression="R = A {:,during} C", basename="r")
D = tgis.open_old_stds("R", type="stvds")
self.assertEqual(D.metadata.get_number_of_maps(), 2)
self.assertEqual(D.metadata.get_number_of_points(), 40)
self.assertEqual(D.metadata.get_number_of_areas(), 0)
self.assertEqual(D.metadata.get_number_of_centroids(), 0)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_buff_operators_1(self):
"""Testing the bufferoperator."""
self.assertModule("t.vect.algebra", expression="R = buff_p(A,0.5)", basename="r")
D = tgis.open_old_stds("R", type="stvds")
self.assertEqual(D.metadata.get_number_of_maps(), 4)
self.assertEqual(D.metadata.get_number_of_points(), 0)
self.assertEqual(D.metadata.get_number_of_areas(), 80)
self.assertEqual(D.metadata.get_number_of_centroids(), 80)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_buff_operators_2(self):
"""Testing the bufferoperator."""
self.assertModule("t.vect.algebra", expression="R = buff_a(buff_p(A,1),10)", basename="r")
D = tgis.open_old_stds("R", type="stvds")
self.assertEqual(D.metadata.get_number_of_maps(), 4)
self.assertEqual(D.metadata.get_number_of_points(), 0)
self.assertEqual(D.metadata.get_number_of_areas(), 20)
self.assertEqual(D.metadata.get_number_of_centroids(), 20)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_overlay_operators_1(self):
"""Testing the spatial overlay operator."""
self.assertModule("t.vect.algebra", expression="R = buff_p(A,2) & buff_p(D,2)", basename="r")
D = tgis.open_old_stds("R", type="stvds")
self.assertEqual(D.metadata.get_number_of_maps(), 2)
self.assertEqual(D.metadata.get_number_of_points(), 0)
self.assertEqual(D.metadata.get_number_of_areas(), 6)
self.assertEqual(D.metadata.get_number_of_centroids(), 6)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_overlay_operators_2(self):
"""Testing the spatial overlay operator."""
self.assertModule("t.vect.algebra", expression="R = buff_p(A,1.5) {&,during,r} buff_p(B,1.5)", basename="r")
D = tgis.open_old_stds("R", type="stvds")
self.assertEqual(D.metadata.get_number_of_maps(), 4)
self.assertEqual(D.metadata.get_number_of_points(), 0)
self.assertEqual(D.metadata.get_number_of_areas(), 8)
self.assertEqual(D.metadata.get_number_of_centroids(), 8)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), False)
self.assertEqual(D.get_granularity(), u'2 days')
def test_temporal_overlay_operators_3(self):
"""Testing the spatial overlay operator."""
self.assertModule("t.vect.algebra", expression="R = buff_p(A,2.5) {&,during,l} buff_p(C,2.5)", basename="r")
D = tgis.open_old_stds("R", type="stvds")
self.assertEqual(D.metadata.get_number_of_maps(), 2)
self.assertEqual(D.metadata.get_number_of_points(), 0)
self.assertEqual(D.metadata.get_number_of_areas(), 8)
self.assertEqual(D.metadata.get_number_of_centroids(), 8)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
if __name__ == '__main__':
test()