-
Notifications
You must be signed in to change notification settings - Fork 2
/
patch_temporal.diff
258 lines (227 loc) · 10.6 KB
/
patch_temporal.diff
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
Index: lib/python/temporal/c_libraries_interface.py
===================================================================
--- lib/python/temporal/c_libraries_interface.py (revision 73073)
+++ lib/python/temporal/c_libraries_interface.py (working copy)
@@ -27,6 +27,7 @@
from grass.pygrass.rpc.base import RPCServerBase
from grass.pygrass.raster import RasterRow
from grass.pygrass.vector import VectorTopo
+from grass.script.utils import encode, decode
###############################################################################
@@ -238,7 +239,7 @@
mapset = libgis.G_mapset()
drstring = libtgis.tgis_get_mapset_driver_name(mapset)
- conn.send(drstring)
+ conn.send(drstring.data)
###############################################################################
@@ -258,13 +259,14 @@
if not mapset:
mapset = libgis.G_mapset()
dbstring = libtgis.tgis_get_mapset_database_name(mapset)
+ dbstring = dbstring.data
if dbstring:
# We substitute GRASS variables if they are located in the database string
# This behavior is in conjunction with db.connect
- dbstring = dbstring.replace("$GISDBASE", libgis.G_gisdbase())
- dbstring = dbstring.replace("$LOCATION_NAME", libgis.G_location())
- dbstring = dbstring.replace("$MAPSET", mapset)
+ dbstring = dbstring.replace(encode("$GISDBASE"), libgis.G_gisdbase())
+ dbstring = dbstring.replace(encode("$LOCATION_NAME"), libgis.G_location())
+ dbstring = dbstring.replace(encode("$MAPSET"), encode(mapset))
except:
raise
finally:
@@ -297,8 +299,9 @@
in_search_path = libgis.G_is_mapset_in_search_path(mapset)
c = 0
- while mapset[c] != "\x00":
- char_list += mapset[c]
+ while mapset[c] != b"\x00":
+ val = decode(mapset[c])
+ char_list += val
c += 1
if permission >= 0 and in_search_path == 1:
@@ -311,7 +314,7 @@
# We need to sort the mapset list, but the first one should be
# the current mapset
- current_mapset = libgis.G_mapset()
+ current_mapset = decode(libgis.G_mapset())
if current_mapset in mapset_list:
mapset_list.remove(current_mapset)
mapset_list.sort()
@@ -566,7 +569,7 @@
return None
# Read the region information
- region = libgis.Cell_head()
+ region = libraster.struct_Cell_head()
libraster.Rast_get_cellhd(name, mapset, byref(region))
kvp["north"] = region.north
Index: lib/python/temporal/core.py
===================================================================
--- lib/python/temporal/core.py (revision 73073)
+++ lib/python/temporal/core.py (working copy)
@@ -41,6 +41,7 @@
from .c_libraries_interface import *
from grass.pygrass import messages
+from grass.script.utils import decode, encode
# Import all supported database backends
# Ignore import errors since they are checked later
try:
@@ -453,6 +454,7 @@
tgis_mapsets = {}
for mapset in mapsets:
+ mapset = decode(mapset)
driver = c_library_interface.get_driver_name(mapset)
database = c_library_interface.get_database_name(mapset)
@@ -464,12 +466,12 @@
# Check if the temporal sqlite database exists
# We need to set non-existing databases in case the mapset is the current mapset
# to create it
- if (driver == "sqlite" and os.path.exists(database)) or mapset == get_current_mapset() :
+ if (encode(driver) == "sqlite" and os.path.exists(database)) or encode(mapset) == get_current_mapset() :
tgis_mapsets[mapset] = (driver, database)
# We need to warn if the connection is defined but the database does not
# exists
- if driver == "sqlite" and not os.path.exists(database):
+ if encode(driver) == "sqlite" and not os.path.exists(database):
message_interface.warning("Temporal database connection defined as:\n" + \
database + "\nBut database file does not exist.")
@@ -583,6 +585,7 @@
msgr.warning("TGIS_DISABLE_TIMESTAMP_WRITE is True")
if driver_string is not None and driver_string is not "":
+ driver_string = decode(driver_string)
if driver_string == "sqlite":
tgis_backend = driver_string
try:
@@ -892,6 +895,8 @@
def get_dbmi(self, mapset=None):
if mapset is None:
mapset = self.current_mapset
+
+ mapset = decode(mapset)
return self.connections[mapset].dbmi
def rollback(self, mapset=None):
@@ -945,6 +950,7 @@
if mapset is None:
mapset = self.current_mapset
+ mapset = decode(mapset)
if mapset not in self.tgis_mapsets.keys():
self.msgr.fatal(_("Unable to mogrify sql statement. " +
self._create_mapset_error_message(mapset)))
@@ -967,6 +973,7 @@
if mapset is None:
mapset = self.current_mapset
+ mapset = decode(mapset)
if mapset not in self.tgis_mapsets.keys():
self.msgr.fatal(_("Unable to check table. " +
self._create_mapset_error_message(mapset)))
@@ -983,6 +990,7 @@
if mapset is None:
mapset = self.current_mapset
+ mapset = decode(mapset)
if mapset not in self.tgis_mapsets.keys():
self.msgr.fatal(_("Unable to execute sql statement. " +
self._create_mapset_error_message(mapset)))
@@ -993,6 +1001,7 @@
if mapset is None:
mapset = self.current_mapset
+ mapset = decode(mapset)
if mapset not in self.tgis_mapsets.keys():
self.msgr.fatal(_("Unable to fetch one. " +
self._create_mapset_error_message(mapset)))
@@ -1003,6 +1012,7 @@
if mapset is None:
mapset = self.current_mapset
+ mapset = decode(mapset)
if mapset not in self.tgis_mapsets.keys():
self.msgr.fatal(_("Unable to fetch all. " +
self._create_mapset_error_message(mapset)))
@@ -1020,6 +1030,7 @@
if mapset is None:
mapset = self.current_mapset
+ mapset = decode(mapset)
if mapset not in self.tgis_mapsets.keys():
self.msgr.fatal(_("Unable to execute transaction. " +
self._create_mapset_error_message(mapset)))
@@ -1032,7 +1043,7 @@
"access mapset <%(mapset)s>, or "
"mapset <%(mapset)s> has no temporal database. "
"Accessible mapsets are: <%(mapsets)s>" % \
- {"mapset": mapset,
+ {"mapset": decode(mapset),
"mapsets":','.join(self.tgis_mapsets.keys())})
###############################################################################
@@ -1057,12 +1068,12 @@
self.connected = False
if backend is None:
global tgis_backend
- if tgis_backend == "sqlite":
+ if decode(tgis_backend) == "sqlite":
self.dbmi = sqlite3
else:
self.dbmi = psycopg2
else:
- if backend == "sqlite":
+ if decode(backend) == "sqlite":
self.dbmi = sqlite3
else:
self.dbmi = psycopg2
@@ -1108,6 +1119,9 @@
# Connection in the current mapset
if dbstring is None:
dbstring = self.dbstring
+
+ dbstring = decode(dbstring)
+
try:
if self.dbmi.__name__ == "sqlite3":
self.connection = self.dbmi.connect(dbstring,
Index: lib/python/temporal/temporal_algebra.py
===================================================================
--- lib/python/temporal/temporal_algebra.py (revision 73073)
+++ lib/python/temporal/temporal_algebra.py (working copy)
@@ -462,9 +462,9 @@
from .factory import dataset_factory
from .open_stds import open_new_stds, open_old_stds
from .temporal_operator import TemporalOperatorParser
-from spatio_temporal_relationships import SpatioTemporalTopologyBuilder
+from .spatio_temporal_relationships import SpatioTemporalTopologyBuilder
from .datetime_math import time_delta_to_relative_time, string_to_datetime
-from abstract_space_time_dataset import AbstractSpaceTimeDataset
+from .abstract_space_time_dataset import AbstractSpaceTimeDataset
from .temporal_granularity import compute_absolute_time_granularity
from .datetime_math import create_suffix_from_datetime
Index: lib/python/temporal/temporal_raster_base_algebra.py
===================================================================
--- lib/python/temporal/temporal_raster_base_algebra.py (revision 73073)
+++ lib/python/temporal/temporal_raster_base_algebra.py (working copy)
@@ -56,7 +56,7 @@
from .abstract_dataset import AbstractDatasetComparisonKeyStartTime
from .factory import dataset_factory
from .open_stds import open_new_stds
-from spatio_temporal_relationships import SpatioTemporalTopologyBuilder
+from .spatio_temporal_relationships import SpatioTemporalTopologyBuilder
from .space_time_datasets import Raster3DDataset, RasterDataset
from .temporal_granularity import compute_absolute_time_granularity
Index: lib/python/temporal/temporal_vector_algebra.py
===================================================================
--- lib/python/temporal/temporal_vector_algebra.py (revision 73073)
+++ lib/python/temporal/temporal_vector_algebra.py (working copy)
@@ -56,7 +56,7 @@
from .core import init_dbif, get_current_mapset
from .abstract_dataset import AbstractDatasetComparisonKeyStartTime
from .open_stds import open_new_stds
-from spatio_temporal_relationships import SpatioTemporalTopologyBuilder
+from .spatio_temporal_relationships import SpatioTemporalTopologyBuilder
from .space_time_datasets import VectorDataset
Index: lib/python/temporal/testsuite/test_register_function.py
===================================================================
--- lib/python/temporal/testsuite/test_register_function.py (revision 73073)
+++ lib/python/temporal/testsuite/test_register_function.py (working copy)
@@ -222,7 +222,7 @@
map_3 = tgis.RasterDataset("register_map_null@" + tgis.get_current_mapset())
map_3.select()
start, end = map_3.get_absolute_time()
- self.assertEqual(start, datetime.datetime(2001, 1, 2, 02, 30, 1))
+ self.assertEqual(start, datetime.datetime(2001, 1, 2, 2, 30, 1))
map_list = [map_1, map_2, map_3]