test.temporal.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. import os
  2. from grass.script.tgis_core import *
  3. from grass.script.tgis_base import *
  4. from grass.script.tgis_temporal_extent import *
  5. from grass.script.tgis_spatial_extent import *
  6. from grass.script.tgis_metadata import *
  7. from grass.script.tgis_abstract_datasets import *
  8. from grass.script.tgis_space_time_datasets import *
  9. import grass.script as grass
  10. ###############################################################################
  11. def test_dict_sql_serializer():
  12. t = dict_sql_serializer()
  13. t.test()
  14. def test_dataset_identifer():
  15. for i in range(2):
  16. base = raster_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", creator="soeren", temporal_type="absolute", revision=1)
  17. base.insert()
  18. base.select()
  19. base.print_self()
  20. base.clear()
  21. base.set_creator("rene")
  22. base.update()
  23. base.select()
  24. base.print_self()
  25. for i in range(2):
  26. base = raster3d_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", creator="soeren")
  27. base.insert()
  28. base.select()
  29. base.print_self()
  30. base.clear()
  31. base.set_creator("rene")
  32. base.update()
  33. base.select()
  34. base.print_self()
  35. for i in range(2):
  36. base = vector_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", creator="soeren")
  37. base.insert()
  38. base.select()
  39. base.print_self()
  40. base.clear()
  41. base.set_creator("rene")
  42. base.update()
  43. base.select()
  44. base.print_self()
  45. for i in range(2):
  46. base = strds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", creator="soeren", semantic_type="event", temporal_type="absolute", revision=1)
  47. base.insert()
  48. base.select()
  49. base.print_self()
  50. base.clear()
  51. base.set_creator("rene")
  52. base.update()
  53. base.select()
  54. base.print_self()
  55. for i in range(2):
  56. base = str3ds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", semantic_type="event", creator="soeren")
  57. base.insert()
  58. base.select()
  59. base.print_self()
  60. base.clear()
  61. base.set_creator("rene")
  62. base.update()
  63. base.select()
  64. base.print_self()
  65. for i in range(2):
  66. base = stvds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", semantic_type="event", creator="soeren")
  67. base.insert()
  68. base.select()
  69. base.print_self()
  70. base.clear()
  71. base.set_creator("rene")
  72. base.update()
  73. base.select()
  74. base.print_self()
  75. def test_absolute_timestamp():
  76. for i in range(2):
  77. base = raster_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), timezone=1)
  78. base.insert()
  79. base.select()
  80. base.print_self()
  81. base.clear()
  82. base.set_start_time(datetime(2010,01,01))
  83. base.update()
  84. base.select()
  85. base.print_self()
  86. for i in range(2):
  87. base = raster3d_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), timezone=1)
  88. base.insert()
  89. base.select()
  90. base.print_self()
  91. base.clear()
  92. base.set_start_time(datetime(2010,01,01))
  93. base.update()
  94. base.select()
  95. base.print_self()
  96. for i in range(2):
  97. base = vector_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), timezone=1)
  98. base.insert()
  99. base.select()
  100. base.print_self()
  101. base.clear()
  102. base.set_start_time(datetime(2010,01,01))
  103. base.update()
  104. base.select()
  105. base.print_self()
  106. for i in range(2):
  107. base = strds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
  108. base.insert()
  109. base.select()
  110. base.print_self()
  111. base.clear()
  112. base.set_start_time(datetime(2010,01,01))
  113. base.update()
  114. base.select()
  115. base.print_self()
  116. for i in range(2):
  117. base = str3ds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
  118. base.insert()
  119. base.select()
  120. base.print_self()
  121. base.clear()
  122. base.set_start_time(datetime(2010,01,01))
  123. base.update()
  124. base.select()
  125. base.print_self()
  126. for i in range(2):
  127. base = stvds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
  128. base.insert()
  129. base.select()
  130. base.print_self()
  131. base.clear()
  132. base.set_start_time(datetime(2010,01,01))
  133. base.update()
  134. base.select()
  135. base.print_self()
  136. def test_spatial_extent():
  137. for i in range(2):
  138. base = raster_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  139. base.insert()
  140. base.select()
  141. base.print_self()
  142. base.clear()
  143. base.set_north(120+i)
  144. base.update()
  145. base.select()
  146. base.print_self()
  147. for i in range(2):
  148. base = raster3d_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  149. base.insert()
  150. base.select()
  151. base.print_self()
  152. base.clear()
  153. base.set_north(120+i)
  154. base.update()
  155. base.select()
  156. base.print_self()
  157. for i in range(2):
  158. base = vector_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  159. base.insert()
  160. base.select()
  161. base.print_self()
  162. base.clear()
  163. base.set_north(120+i)
  164. base.update()
  165. base.select()
  166. base.print_self()
  167. for i in range(2):
  168. base = strds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  169. base.insert()
  170. base.select()
  171. base.print_self()
  172. base.clear()
  173. base.set_north(120+i)
  174. base.update()
  175. base.select()
  176. base.print_self()
  177. for i in range(2):
  178. base = str3ds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  179. base.insert()
  180. base.select()
  181. base.print_self()
  182. base.clear()
  183. base.set_north(120+i)
  184. base.update()
  185. base.select()
  186. base.print_self()
  187. for i in range(2):
  188. base = stvds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  189. base.insert()
  190. base.select()
  191. base.print_self()
  192. base.clear()
  193. base.set_north(120+i)
  194. base.update()
  195. base.select()
  196. base.print_self()
  197. def test_relative_timestamp():
  198. for i in range(2):
  199. base = raster_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i)
  200. base.insert()
  201. base.select()
  202. base.print_self()
  203. base.clear()
  204. base.set_interval(i+1)
  205. base.update()
  206. base.select()
  207. base.print_self()
  208. for i in range(2):
  209. base = raster3d_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i)
  210. base.insert()
  211. base.select()
  212. base.print_self()
  213. base.clear()
  214. base.set_interval(i+1)
  215. base.update()
  216. base.select()
  217. base.print_self()
  218. for i in range(2):
  219. base = vector_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i)
  220. base.insert()
  221. base.select()
  222. base.print_self()
  223. base.clear()
  224. base.set_interval(i+1)
  225. base.update()
  226. base.select()
  227. base.print_self()
  228. for i in range(2):
  229. base = strds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
  230. base.insert()
  231. base.select()
  232. base.print_self()
  233. base.clear()
  234. base.set_interval(i+1)
  235. base.update()
  236. base.select()
  237. base.print_self()
  238. for i in range(2):
  239. base = str3ds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
  240. base.insert()
  241. base.select()
  242. base.print_self()
  243. base.clear()
  244. base.set_interval(i+1)
  245. base.update()
  246. base.select()
  247. base.print_self()
  248. for i in range(2):
  249. base = stvds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
  250. base.insert()
  251. base.select()
  252. base.print_self()
  253. base.clear()
  254. base.set_interval(i+1)
  255. base.update()
  256. base.select()
  257. base.print_self()
  258. def test_map_metadata():
  259. for i in range(2):
  260. base = raster_metadata(ident="soil" + str(i) + "@PERMANENT", strds_register="PERMANENT_soil_strds_register", datatype="CELL", \
  261. cols=500, rows=400, number_of_cells=200000,nsres=1, ewres=1, min=0, max=33)
  262. base.insert()
  263. base.select()
  264. base.print_self()
  265. base.clear()
  266. base.set_datatype("FCELL")
  267. base.update()
  268. base.select()
  269. base.print_self()
  270. for i in range(2):
  271. base = raster3d_metadata(ident="soil" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_soil_str3ds_register", datatype="FCELL", \
  272. cols=500, rows=400, depths=20, number_of_cells=200000,nsres=1, ewres=1, tbres=10, min=0, max=33)
  273. base.insert()
  274. base.select()
  275. base.print_self()
  276. base.clear()
  277. base.set_datatype("DCELL")
  278. base.update()
  279. base.select()
  280. base.print_self()
  281. for i in range(2):
  282. base = vector_metadata(ident="soil" + str(i) + "@PERMANENT", stvds_register="PERMANENT_soil_stvds_register")
  283. base.insert()
  284. base.select()
  285. base.print_self()
  286. base.clear()
  287. base.set_stvds_register("PERMANENT_soil_stvds_register")
  288. base.update()
  289. base.select()
  290. base.print_self()
  291. for i in range(2):
  292. base = strds_metadata(ident="soil" + str(i) + "@PERMANENT", raster_register="PERMANENT_soil_raster_register", \
  293. title="Test", description="Test description")
  294. base.insert()
  295. base.select()
  296. base.print_self()
  297. base.clear()
  298. base.set_title("More tests")
  299. base.update()
  300. base.select()
  301. base.print_self()
  302. for i in range(2):
  303. base = str3ds_metadata(ident="soil" + str(i) + "@PERMANENT", raster3d_register="PERMANENT_soil_raster3d_register", \
  304. title="Test", description="Test description")
  305. base.insert()
  306. base.select()
  307. base.print_self()
  308. base.clear()
  309. base.set_title("More tests")
  310. base.update()
  311. base.select()
  312. base.print_self()
  313. for i in range(2):
  314. base = stvds_metadata(ident="soil" + str(i) + "@PERMANENT", vector_register="PERMANENT_soil_vector_register", \
  315. title="Test", description="Test description")
  316. base.insert()
  317. base.select()
  318. base.print_self()
  319. base.clear()
  320. base.set_title("More tests")
  321. base.update()
  322. base.select()
  323. base.print_self()
  324. def test_base_absolute_time_extent_metadata():
  325. for i in range(10):
  326. base = vector_base(ident="water" + str(i) + "@PERMANENT", name="water" + str(i), mapset="PERMANENT", creator="soeren")
  327. base.insert()
  328. base = raster_base(ident="water" + str(i) + "@PERMANENT", name="water" + str(i), mapset="PERMANENT", creator="soeren")
  329. base.insert()
  330. base = raster3d_base(ident="water" + str(i) + "@PERMANENT", name="water" + str(i), mapset="PERMANENT", creator="soeren")
  331. base.insert()
  332. for i in range(10):
  333. base = vector_base(ident="water" + str(i) + "@PERMANENT")
  334. base.set_creator("rene")
  335. base.update()
  336. base = raster_base(ident="water" + str(i) + "@PERMANENT")
  337. base.set_creator("rene")
  338. base.update()
  339. base = raster3d_base(ident="water" + str(i) + "@PERMANENT")
  340. base.set_creator("rene")
  341. base.update()
  342. for i in range(10):
  343. base = vector_absolute_time(ident="water" + str(i) + "@PERMANENT", start_time=datetime.now(), end_time=datetime.now(), timezone=1)
  344. base.insert()
  345. base = raster_absolute_time(ident="water" + str(i) + "@PERMANENT", start_time=datetime.now(), end_time=datetime.now(), timezone=1)
  346. base.insert()
  347. base = raster3d_absolute_time(ident="water" + str(i) + "@PERMANENT", start_time=datetime.now(), end_time=datetime.now(), timezone=1)
  348. base.insert()
  349. for i in range(10):
  350. base = vector_absolute_time(ident="water" + str(i) + "@PERMANENT")
  351. base.set_start_time(datetime(2010, 6, 1))
  352. base.update()
  353. base = raster_absolute_time(ident="water" + str(i) + "@PERMANENT")
  354. base.set_start_time(datetime(2010, 6, 1))
  355. base.update()
  356. base = raster3d_absolute_time(ident="water" + str(i) + "@PERMANENT")
  357. base.set_start_time(datetime(2010, 6, 1))
  358. base.update()
  359. for i in range(10):
  360. base = vector_spatial_extent(ident="water" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  361. base.insert()
  362. base = raster_spatial_extent(ident="water" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=0, bottom=0)
  363. base.insert()
  364. base = raster3d_spatial_extent(ident="water" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
  365. base.insert()
  366. for i in range(10):
  367. base = vector_spatial_extent(ident="water" + str(i) + "@PERMANENT")
  368. base.set_north(120 + i)
  369. base.set_south(20 + i)
  370. base.update()
  371. base = raster_spatial_extent(ident="water" + str(i) + "@PERMANENT")
  372. base.set_north(120 + i)
  373. base.set_south(20 + i)
  374. base.update()
  375. base = raster3d_spatial_extent(ident="water" + str(i) + "@PERMANENT")
  376. base.set_north(120 + i)
  377. base.set_south(20 + i)
  378. base.update()
  379. for i in range(10):
  380. base = vector_metadata(ident="water" + str(i) + "@PERMANENT", stvds_register="PERMANENT_water_stvds_register")
  381. base.insert()
  382. base = raster_metadata(ident="water" + str(i) + "@PERMANENT", strds_register="PERMANENT_water_strds-register", datatype="CELL", \
  383. cols=500, rows=400, number_of_cells=200000,nsres=1, ewres=1, min=0, max=33)
  384. base.insert()
  385. base = raster3d_metadata(ident="water" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_water_str3ds-register", datatype="FCELL", \
  386. cols=500, rows=400, depths=20, number_of_cells=200000,nsres=1, ewres=1, tbres=10, min=0, max=33)
  387. base.insert()
  388. for i in range(10):
  389. base = vector_metadata(ident="water" + str(i) + "@PERMANENT")
  390. base.set_stvds_register("PERMANENT_water_stvds_register")
  391. base.update()
  392. base = raster_metadata(ident="water" + str(i) + "@PERMANENT")
  393. base.set_datatype("DCELL")
  394. base.update()
  395. base = raster3d_metadata(ident="water" + str(i) + "@PERMANENT")
  396. base.set_datatype("DCELL")
  397. base.update()
  398. for i in range(10):
  399. base = vector_base(ident="water" + str(i) + "@PERMANENT")
  400. base.select()
  401. base.print_self()
  402. base = raster_base(ident="water" + str(i) + "@PERMANENT")
  403. base.select()
  404. base.print_self()
  405. base = raster3d_base(ident="water" + str(i) + "@PERMANENT")
  406. base.select()
  407. base.print_self()
  408. print "Create a raster object"
  409. rds = raster_dataset("water0@PERMANENT")
  410. rds.select()
  411. rds.print_self()
  412. print rds.temporal_relation(rds)
  413. def test_absolut_time_temporal_relations():
  414. A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  415. end_time=datetime(year=2001, month=1, day=1), timezone=1)
  416. B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2001, month=1, day=1), \
  417. end_time=datetime(year=2002, month=1, day=1), timezone=1)
  418. print "Precedes: ", A.temporal_relation(B)
  419. print "Follows: ", B.temporal_relation(A)
  420. A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  421. end_time=datetime(year=2001, month=1, day=1), timezone=1)
  422. B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2001, month=1, day=2), \
  423. end_time=datetime(year=2002, month=1, day=1), timezone=1)
  424. print "Before: ", A.temporal_relation(B)
  425. print "After: ", B.temporal_relation(A)
  426. A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  427. end_time=datetime(year=2001, month=1, day=1), timezone=1)
  428. B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  429. end_time=datetime(year=2002, month=1, day=1), timezone=1)
  430. print "Starts: ", A.temporal_relation(B)
  431. print "Started: ", B.temporal_relation(A)
  432. A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  433. end_time=datetime(year=2001, month=1, day=1), timezone=1)
  434. B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=1, day=2), \
  435. end_time=datetime(year=2001, month=1, day=1), timezone=1)
  436. print "Finished: ", A.temporal_relation(B)
  437. print "Finishes: ", B.temporal_relation(A)
  438. A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  439. end_time=datetime(year=2001, month=1, day=1), timezone=1)
  440. B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=3, day=1), \
  441. end_time=datetime(year=2000, month=9, day=1), timezone=1)
  442. print "Contains: ", A.temporal_relation(B)
  443. print "During: ", B.temporal_relation(A)
  444. A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  445. end_time=datetime(year=2000, month=6, day=1), timezone=1)
  446. B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=3, day=1), \
  447. end_time=datetime(year=2000, month=9, day=1), timezone=1)
  448. print "Overlap: ", A.temporal_relation(B)
  449. print "Overlapped:", B.temporal_relation(A)
  450. A = raster_absolute_time(ident="test1@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  451. end_time=datetime(year=2000, month=1, day=1), timezone=1)
  452. B = raster_absolute_time(ident="test2@PERMANENT", start_time=datetime(year=2000, month=1, day=1), \
  453. end_time=datetime(year=2000, month=1, day=1), timezone=1)
  454. print "Equivalent:", A.temporal_relation(B)
  455. print "Equivalent:", B.temporal_relation(A)
  456. def test_raster_dataset():
  457. # Create a test map
  458. grass.raster.mapcalc("test = sin(x()) + cos(y())", overwrite = True)
  459. name = "test"
  460. mapset = grass.gisenv()["MAPSET"]
  461. print "Create a raster object"
  462. # We need to specify the name and the mapset as identifier
  463. rds = raster_dataset(name + "@" + mapset)
  464. # Load data from the raster map in the mapset
  465. rds.load()
  466. print "Is in db: ", rds.is_in_db()
  467. if rds.is_in_db():
  468. # Remove the entry if it is in the db
  469. rds.delete()
  470. # Set the absolute valid time
  471. rds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
  472. end_time= datetime(year=2010, month=1, day=1))
  473. # Insert the map data into the SQL database
  474. rds.insert()
  475. # Print self info
  476. rds.print_self()
  477. # The temporal relation must be equal
  478. print rds.temporal_relation(rds)
  479. def test_raster3d_dataset():
  480. # Create a test map
  481. grass.raster3d.mapcalc3d("test = sin(x()) + cos(y()) + sin(z())", overwrite = True)
  482. name = "test"
  483. mapset = grass.gisenv()["MAPSET"]
  484. print "Create a raster object"
  485. # We need to specify the name and the mapset as identifier
  486. r3ds = raster3d_dataset(name + "@" + mapset)
  487. # Load data from the raster map in the mapset
  488. r3ds.load()
  489. print "Is in db: ", r3ds.is_in_db()
  490. if r3ds.is_in_db():
  491. # Remove the entry if it is in the db
  492. r3ds.delete()
  493. # Set the absolute valid time
  494. r3ds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
  495. end_time= datetime(year=2010, month=1, day=1))
  496. # Insert the map data into the SQL database
  497. r3ds.insert()
  498. # Print self info
  499. r3ds.print_self()
  500. # The temporal relation must be equal
  501. print r3ds.temporal_relation(r3ds)
  502. def test_vector_dataset():
  503. # Create a test map
  504. grass.run_command("v.random", output="test", n=20, column="height", zmin=0, \
  505. zmax=100, flags="z", overwrite = True)
  506. name = "test"
  507. mapset = grass.gisenv()["MAPSET"]
  508. print "Create a vector object"
  509. # We need to specify the name and the mapset as identifier
  510. vds = vector_dataset(name + "@" + mapset)
  511. # Load data from the raster map in the mapset
  512. vds.load()
  513. print "Is in db: ", vds.is_in_db()
  514. if vds.is_in_db():
  515. # Remove the entry if it is in the db
  516. vds.delete()
  517. # Set the absolute valid time
  518. vds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
  519. end_time= datetime(year=2010, month=1, day=1))
  520. # Insert the map data into the SQL database
  521. vds.insert()
  522. # Print self info
  523. vds.print_self()
  524. # The temporal relation must be equal
  525. print vds.temporal_relation(vds)
  526. def test_strds_dataset():
  527. name = "strds_test_1"
  528. mapset = grass.gisenv()["MAPSET"]
  529. print "Create a strds object"
  530. # We need to specify the name and the mapset as identifier
  531. strds = space_time_raster_dataset(ident = name + "@" + mapset)
  532. # Check if in db
  533. print "Is strds in db: ", strds.is_in_db()
  534. # Create a new entry if not in db
  535. if strds.is_in_db() == False:
  536. strds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
  537. semantic_type="event", title="This is a test space time raster dataset", description="A space time raster dataset for testing")
  538. strds.insert()
  539. # Reread the data from the db
  540. strds.select()
  541. # Print self info
  542. #strds.print_self()
  543. # Create a test maps
  544. for i in range(11):
  545. i = i + 1
  546. grass.raster.mapcalc("test" + str(i) + " = sin(x()) + cos(y())", overwrite = True)
  547. name = "test" + str(i)
  548. mapset = grass.gisenv()["MAPSET"]
  549. ident = name + "@" + mapset
  550. print "Create a raster object"
  551. # We need to specify the name and the mapset as identifier
  552. rds = raster_dataset(ident)
  553. # Load data from the raster map in the mapset
  554. rds.load()
  555. print "Is raster in db: ", rds.is_in_db()
  556. if rds.is_in_db():
  557. rds.select()
  558. rds.print_self()
  559. # Remove the entry if it is in the db
  560. rds.delete()
  561. rds.reset(ident)
  562. rds.load()
  563. # Set the absolute valid time
  564. rds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
  565. end_time= datetime(year=2000, month=i + 1, day=1))
  566. # Insert the map data into the SQL database
  567. rds.insert()
  568. # Register the map in the space time raster dataset
  569. strds.register_map(rds)
  570. # Print self info
  571. #rds.print_self()
  572. strds.update_from_registered_maps()
  573. strds.select()
  574. # Print self info
  575. strds.print_self()
  576. # Delete the dataset
  577. strds.delete()
  578. def test_str3ds_dataset():
  579. name = "str3ds_test_1"
  580. mapset = grass.gisenv()["MAPSET"]
  581. print "Create a str3ds object"
  582. # We need to specify the name and the mapset as identifier
  583. str3ds = space_time_raster3d_dataset(ident = name + "@" + mapset)
  584. # Check if in db
  585. print "Is str3ds in db: ", str3ds.is_in_db()
  586. # Create a new entry if not in db
  587. if str3ds.is_in_db() == False:
  588. str3ds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
  589. semantic_type="event", title="This is a test space time raster3d dataset", description="A space time raster3d dataset for testing")
  590. str3ds.insert()
  591. # Reread the data from the db
  592. str3ds.select()
  593. # Print self info
  594. #str3ds.print_self()
  595. # Create a test maps
  596. for i in range(11):
  597. i = i + 1
  598. grass.raster3d.mapcalc3d("test" + str(i) + " = sin(x()) + cos(y()) + z()", overwrite = True)
  599. name = "test" + str(i)
  600. mapset = grass.gisenv()["MAPSET"]
  601. ident = name + "@" + mapset
  602. print "Create a raster3d object"
  603. # We need to specify the name and the mapset as identifier
  604. r3ds = raster3d_dataset(ident)
  605. # Load data from the raster3d map in the mapset
  606. r3ds.load()
  607. print "Is raster3d in db: ", r3ds.is_in_db()
  608. if r3ds.is_in_db():
  609. r3ds.select()
  610. r3ds.print_self()
  611. # Remove the entry if it is in the db
  612. r3ds.delete()
  613. r3ds.reset(ident)
  614. r3ds.load()
  615. # Set the absolute valid time
  616. r3ds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
  617. end_time= datetime(year=2000, month=i + 1, day=1))
  618. # Insert the map data into the SQL database
  619. r3ds.insert()
  620. # Register the map in the space time raster3d dataset
  621. str3ds.register_map(r3ds)
  622. # Print self info
  623. #r3ds.print_self()
  624. str3ds.update_from_registered_maps()
  625. str3ds.select()
  626. # Print self info
  627. str3ds.print_self()
  628. # Delete the dataset
  629. str3ds.delete()
  630. def test_stvds_dataset():
  631. name = "stvds_test_1"
  632. mapset = grass.gisenv()["MAPSET"]
  633. print "Create a stvds object"
  634. # We need to specify the name and the mapset as identifier
  635. stvds = space_time_vector_dataset(ident = name + "@" + mapset)
  636. # Check if in db
  637. print "Is stvds in db: ", stvds.is_in_db()
  638. # Create a new entry if not in db
  639. if stvds.is_in_db() == False:
  640. stvds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
  641. semantic_type="event", title="This is a test space time vector dataset", description="A space time vector dataset for testing")
  642. stvds.insert()
  643. # Reread the data from the db
  644. stvds.select()
  645. # Print self info
  646. #stvds.print_self()
  647. # Create a test maps
  648. for i in range(11):
  649. name = "test" + str(i)
  650. mapset = grass.gisenv()["MAPSET"]
  651. ident = name + "@" + mapset
  652. i = i + 1
  653. grass.run_command("v.random", output=name, n=100, zmin=0, zmax=100, column="height" ,flags="z" , overwrite = True)
  654. print "Create a vector object"
  655. # We need to specify the name and the mapset as identifier
  656. vds = vector_dataset(ident)
  657. # Load data from the raster map in the mapset
  658. vds.load()
  659. print "Is vector in db: ", vds.is_in_db()
  660. if vds.is_in_db():
  661. vds.select()
  662. vds.print_self()
  663. # Remove the entry if it is in the db
  664. vds.delete()
  665. vds.reset(ident)
  666. vds.load()
  667. # Set the absolute valid time
  668. vds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
  669. end_time= datetime(year=2000, month=i + 1, day=1))
  670. # Insert the map data into the SQL database
  671. vds.insert()
  672. # Register the map in the space time raster dataset
  673. stvds.register_map(vds)
  674. # Print self info
  675. #vds.print_self()
  676. stvds.update_from_registered_maps()
  677. stvds.select()
  678. # Print self info
  679. stvds.print_self()
  680. # Delete the dataset
  681. stvds.delete()
  682. test_dict_sql_serializer()
  683. create_temporal_database()
  684. #test_dataset_identifer()
  685. #test_absolute_timestamp()
  686. #test_relative_timestamp()
  687. #test_spatial_extent()
  688. #test_map_metadata()
  689. #test_base_absolute_time_extent_metadata()
  690. #test_absolut_time_temporal_relations()
  691. test_raster_dataset()
  692. test_raster3d_dataset()
  693. test_vector_dataset()
  694. test_strds_dataset()
  695. test_str3ds_dataset()
  696. test_stvds_dataset()
  697. test_increment_datetime_by_string()