t.vect.algebra.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <h2>DESCRIPTION</h2>
  2. <em>t.vect.algebra</em> performs temporal and spatial overlay and
  3. buffer functions on space time vector datasets (STVDS) by using the
  4. temporal vector algebra. New STVDS can be created, which are
  5. expressions of existing STVDS.
  6. <h3>PROGRAM USE</h3>
  7. The module expects an <b>expression</b> as input parameter in the following form:
  8. <p>
  9. <div class="code"><pre>
  10. "result = expression"
  11. </pre></div>
  12. The statement structure is similar to r.mapcalc, see <a href="r.mapcalc.html">r.mapcalc</a>.
  13. Where <b>result</b> represents the name of a space time dataset (STVDS) that will
  14. contain the result of the calculation that is given as <b>expression</b>
  15. on the right side of the equality sign.
  16. These expression can be any valid or nested combination of temporal
  17. operations and functions that are provided by the temporal vector
  18. algebra.<br>
  19. The algebra provides methods for map selection from STDS based on their
  20. temporal relations. It is also possible to temporally shift maps, to
  21. create temporal buffer and to snap time instances to create a valid
  22. temporal topology. Furthermore expressions can be nested and evaluated
  23. in conditional statements (if, else statements). Within if-statements
  24. the algebra provides temporal variables like start time, end time, day
  25. of year, time differences or number of maps per time interval to build
  26. up conditions. These operations can be assigned to space time datasets
  27. or to the results of operations between space time datasets.
  28. <p>
  29. The type of the input space time datasets must be defined
  30. with the input parameter <b>type</b>. Possible options are STRDS, STVDS
  31. or STR3DS. The default is set to space time raster datasets (STRDS).
  32. <p> As default, topological relationships between space time datasets
  33. will be evaluated only temporal. Use the <b>s</b> flag to activate the
  34. additionally spatial topology evaluation. <p> The expression option
  35. must be passed as <b>quoted</b> expression, for example: <br>
  36. <div class="code"><pre>
  37. t.select expression="C = A : B"
  38. </pre></div>
  39. Where <b>C</b> is the new space time raster dataset that will contain
  40. maps from <b>A</b> that are selected by equal temporal relationships to
  41. the existing dataset <b>B</b> in this case.
  42. <h2>TEMPORAL VECTOR ALGEBRA</h2>
  43. The temporal algebra provides a wide range of temporal operators and
  44. functions that will be presented in the following section. <p>
  45. <h3>TEMPORAL RELATIONS</h3>
  46. Several temporal topology relations between registered maps of space
  47. time datasets are supported: <br>
  48. <div class="code"><pre>
  49. equals A ------
  50. B ------
  51. during A ----
  52. B ------
  53. contains A ------
  54. B ----
  55. starts A ----
  56. B ------
  57. started A ------
  58. B ----
  59. finishs A ----
  60. B ------
  61. finished A ------
  62. B ----
  63. precedes A ----
  64. B ----
  65. follows A ----
  66. B ----
  67. overlapped A ------
  68. B ------
  69. overlaps A ------
  70. B ------
  71. over booth overlaps and overlapped
  72. </pre></div>
  73. The relations must be read as: A is related to B, like - A equals B - A is
  74. during B - A contains B <p>
  75. Topological relations must be specified in {} parentheses. <br>
  76. <h3>TEMPORAL OPERATORS</h3>
  77. The temporal algebra defines temporal operators that can be combined
  78. with other operators to perform spatio-temporal operations. The
  79. temporal operators process the time instances and intervals of two
  80. temporal related maps and calculate the result temporal extent by five
  81. different possibilities.
  82. <div class="code"><pre>
  83. LEFT REFERENCE l Use the time stamp of the left space time dataset
  84. INTERSECTION i Intersection
  85. DISJOINT UNION d Disjoint union
  86. UNION u Union
  87. RIGHT REFERENCE r Use the time stamp of the right space time dataset
  88. </pre></div>
  89. <h3>TEMPORAL SELECTION</h3>
  90. The temporal selection simply selects parts of a space time dataset without
  91. processing raster or vector data.
  92. The algebra provides a selection operator <b>:</b> that selects parts
  93. of a space time dataset that are temporally equal to parts of a second one
  94. by default. The following expression
  95. <div class="code"><pre>
  96. C = A : B
  97. </pre></div>
  98. means: Select all parts of space time dataset A that are equal to B and
  99. store it in space time dataset C. The parts are time stamped maps.
  100. <p>
  101. In addition the inverse selection operator <b>!:</b> is defined as
  102. the complement of the selection operator, hence the following
  103. expression
  104. <div class="code"><pre>
  105. C = A !: B
  106. </pre></div>
  107. means: select all parts of space time time dataset A that are not equal to B
  108. and store it in space time dataset (STDS) C.<p>
  109. To select parts of a STDS by different topological relations to other
  110. STDS, the temporal topology selection operator can be used. The
  111. operator consists of the temporal selection operator, the topological
  112. relations, that must be separated by the logical OR operator <b>|</b>
  113. and the temporal extent operator. All three parts are separated by
  114. comma and surrounded by curly braces:
  115. <div class="code"><pre>
  116. {"temporal selection operator", "topological relations", "temporal operator"}
  117. </pre></div>
  118. <p>
  119. Examples:
  120. <div class="code"><pre>
  121. C = A {:, equals} B
  122. C = A {!:, equals} B
  123. </pre></div>
  124. We can now define arbitrary topological relations using the OR operator "|"
  125. to connect them:
  126. <div class="code"><pre>
  127. C = A {:,equals|during|overlaps} B
  128. </pre></div>
  129. Select all parts of A that are equal to B, during B or overlaps B. <br>
  130. In addition we can define the temporal extent of the result STDS by adding the
  131. temporal operator.
  132. <div class="code"><pre>
  133. C = A {:, during,r} B
  134. </pre></div>
  135. Select all parts of A that are during B and use the temporal extents
  136. from B for C.
  137. <p>
  138. The selection operator is implicitly contained in the temporal topology
  139. selection operator, so that the following statements are exactly the same:
  140. <div class="code"><pre>
  141. C = A : B
  142. C = A {:} B
  143. C = A {:,equal} B
  144. C = A {:,equal,l} B
  145. </pre></div>
  146. Same for the complementary selection:
  147. <div class="code"><pre>
  148. C = A !: B
  149. C = A {!:} B
  150. C = A {!:,equal} B
  151. C = A {!:,equal,l} B
  152. </pre></div>
  153. <h3>CONDITIONAL STATEMENTS</h3>
  154. Selection operations can be evaluated within conditional statements.
  155. <br>
  156. Note A and B can either be space time datasets or expressions. The temporal
  157. relationship between the conditions and the conclusions can be defined at the
  158. beginning of the if statement. The relationship between then and else conclusion
  159. must be always equal.
  160. <div class="code"><pre>
  161. if statement decision option temporal relations
  162. if(if, then, else)
  163. if(conditions, A) A if conditions are True; temporal topological relation between if and then is equal.
  164. if(conditions, A, B) A if conditions are True, B otherwise; temporal topological relation between if, then and else is equal.
  165. if(topologies, conditions, A) A if conditions are True; temporal topological relation between if and then is explicit specified by topologies.
  166. if(topologies, conditions, A, B) A if conditions are True, B otherwise; temporal topological relation between if, then and else is explicit specified by topologies.
  167. </pre></div>
  168. <h4>Logical operators</h4>
  169. <div class="code"><pre>
  170. Symbol description
  171. == equal
  172. != not equal
  173. > greater than
  174. >= greater than or equal
  175. < less than
  176. <= less than or equal
  177. && and
  178. || or
  179. </pre></div>
  180. <h4>Temporal functions</h4>
  181. The following temporal function are evaluated only for the STDS that
  182. must be given in parenthesis.
  183. <div class="code"><pre>
  184. td(A) Returns a list of time intervals of STDS A
  185. start_time(A) Start time as HH::MM:SS
  186. start_date(A) Start date as yyyy-mm-DD
  187. start_datetime(A) Start datetime as yyyy-mm-DD HH:MM:SS
  188. end_time(A) End time as HH:MM:SS
  189. end_date(A) End date as yyyy-mm-DD
  190. end_datetime(A) End datetime as yyyy-mm-DD HH:MM
  191. start_doy(A) Day of year (doy) from the start time [1 - 366]
  192. start_dow(A) Day of week (dow) from the start time [1 - 7], the start of the week is Monday == 1
  193. start_year(A) The year of the start time [0 - 9999]
  194. start_month(A) The month of the start time [1 - 12]
  195. start_week(A) Week of year of the start time [1 - 54]
  196. start_day(A) Day of month from the start time [1 - 31]
  197. start_hour(A) The hour of the start time [0 - 23]
  198. start_minute(A) The minute of the start time [0 - 59]
  199. start_second(A) The second of the start time [0 - 59]
  200. end_doy(A) Day of year (doy) from the end time [1 - 366]
  201. end_dow(A) Day of week (dow) from the end time [1 - 7], the start of the week is Monday == 1
  202. end_year(A) The year of the end time [0 - 9999]
  203. end_month(A) The month of the end time [1 - 12]
  204. end_week(A) Week of year of the end time [1 - 54]
  205. end_day(A) Day of month from the start time [1 - 31]
  206. end_hour(A) The hour of the end time [0 - 23]
  207. end_minute(A) The minute of the end time [0 - 59]
  208. end_second(A) The second of the end time [0 - 59]
  209. </pre></div>
  210. <h4>Comparison operator</h4>
  211. The conditions are comparison expressions that are used to evaluate
  212. space time datasets. Specific values of temporal variables are
  213. compared by logical operators and evaluated for each map of the STDS and
  214. the related maps.
  215. For complex relations the comparison operator can be used to combine conditions:
  216. <br>
  217. The structure is similar to the select operator with the extension of an aggregation operator:
  218. <div class="code"><pre>
  219. {"comparison operator", "topological relations", aggregation operator, "temporal operator"}
  220. </pre></div>
  221. <br>
  222. This aggregation operator (| or &) define the behaviour if a map is related the more
  223. than one map, e.g for the topological relations 'contains'.
  224. Should all (&) conditions for the related maps be true or is it sufficient to
  225. have any (|) condition that is true. The resulting boolean value is then compared
  226. to the first condition by the comparison operator (|| or &&).
  227. As default the aggregation operator is related to the comparison operator: <br>
  228. Comparison operator -&gt; aggregation operator:
  229. <div class="code"><pre>
  230. || -> | and && -> &
  231. </pre></div>
  232. Examples:
  233. <div class="code"><pre>
  234. Condition 1 {||, equal, r} Condition 2
  235. Condition 1 {&&, equal|during, l} Condition 2
  236. Condition 1 {&&, equal|contains, |, l} Condition 2
  237. Condition 1 {&&, equal|during, l} Condition 2 && Condition 3
  238. Condition 1 {&&, equal|during, l} Condition 2 {&&,contains, |, r} Condition 3
  239. </pre></div>
  240. <h4>Hash operator</h4>
  241. Additionally the number of maps in intervals can be computed and used in
  242. conditional statements with the hash (#) operator. <br>
  243. <div class="code"><pre>
  244. A{#, contains}B
  245. </pre></div>
  246. This expression computes the number of maps from space
  247. time dataset B which are during the time intervals of maps from
  248. space time dataset A.<br>
  249. A list of integers (scalars) corresponding to the maps of A
  250. that contain maps from B will be returned.
  251. <p>
  252. <div class="code"><pre>
  253. C = if({equal}, A {#, contains} B > 2, A {:, contains} B)
  254. </pre></div>
  255. This expression selects all maps from A that temporally contains at least 2
  256. maps from B and stores them in space time dataset C. The leading equal statement
  257. in the if condition specifies the temporal relation between the if and then part
  258. of the if expression. This is very important, so we do not need to specify a
  259. global time reference (a space time dataset) for temporal processing.
  260. <p>
  261. Furthermore the temporal algebra allows temporal buffering, shifting
  262. and snapping with the functions buff_t(), tshift() and tsnap()
  263. respectively.
  264. <div class="code"><pre>
  265. buff_t(A, size) Buffer STDS A with granule ("1 month" or 5)
  266. tshift(A, size) Shift STDS A with granule ("1 month" or 5)
  267. tsnap(A) Snap time instances and intervals of STDS A
  268. </pre></div>
  269. <h4>Single map with temporal extent</h4>
  270. The temporal algebra can also handle single maps with time stamps in
  271. the tmap function.
  272. <div class="code"><pre>
  273. tmap()
  274. </pre></div>
  275. For example:
  276. <div class="code"><pre>
  277. C = A {:,during} tmap(event)
  278. </pre></div>
  279. This statement select all maps from space time data set A that are
  280. during the temporal extent of single map 'event'
  281. <h3>Spatial vector operators</h3>
  282. The module supports the following boolean vector operations:<br>
  283. <div class="code"><pre>
  284. Boolean Name Operator Meaning Precedence Correspondent function
  285. ----------------------------------------------------------------------------------
  286. AND & Intersection 1 (v.overlay operator=and)
  287. OR | Union 1 (v.overlay operator=or)
  288. DISJOINT OR + Disjoint union 1 (v.patch)
  289. XOR ^ Symmetric difference 1 (v.overlay operator=xor)
  290. NOT ~ Complement 1 (v.overlay operator=not)
  291. </pre></div>
  292. And vector functions:
  293. <div class="code"><pre>
  294. buff_p(A, size) Buffer the points of vector map layer A with size
  295. buff_l(A, size) Buffer the lines of vector map layer A with size
  296. buff_a(A, size) Buffer the areas of vector map layer A with size
  297. </pre></div>
  298. <h3>Combinations of temporal, vector and select operators</h3>
  299. We combine the temporal topology relations, the temporal operators and
  300. the spatial/select operators to create spatio-temporal vector
  301. operators:
  302. <pre class="code">
  303. {"spatial or select operator" , "list of temporal relations", "temporal operator" }
  304. </pre><p>
  305. For multiple topological relations or several related maps the spatio-temporal
  306. operators feature implicit aggregation.
  307. The algebra evaluates the stated STDS by their temporal topologies and apply
  308. the given spatio temporal operators in a aggregated form.
  309. If we have two STDS A and B, B has three maps: b1, b2, b3 that are all during
  310. the temporal extent of the single map a1 of A, then the following overlay
  311. calculations would implicitly aggregate all maps of B into one result map for
  312. a1 of A:
  313. <div class="code"><pre>
  314. C = A {&, contains} B --> c1 = a1 & b1 & b2 & b3
  315. </pre></div>
  316. Keep attention that the aggregation behaviour is not symmetric:
  317. <div class="code"><pre>
  318. C = B {&, during} A --> c1 = b1 & a1
  319. c2 = b2 & a1
  320. c3 = b3 & a1
  321. </pre></div>
  322. <h3>Examples: </h3>
  323. Spatio-temporal intersect all maps from space time dataset A with all
  324. maps from space time dataset B which have equal time stamps and are
  325. temporary before Jan. 1. 2005 and store them in space time dataset D.
  326. <div class="code"><pre>
  327. D = if(start_date(A) < "2005-01-01", A & B)
  328. </pre></div>
  329. Buffer all vector points from space time vector dataset A and B with a
  330. distance of one and intersect the results with overlapping, containing,
  331. during and equal temporal relations to store the result in space time
  332. vector dataset D with intersected time stamps.
  333. <div class="code"><pre>
  334. D = buff_p(A, 1) {&,overlaps|overlapped|equal|during|contains,i} buff_p(B, 1)
  335. </pre></div>
  336. Select all maps from space time dataset B which are during the temporal
  337. buffered space time dataset A with a map interval of three days, else
  338. select maps from C and store them in space time dataset D.
  339. <div class="code"><pre>
  340. D = if(contains, td(buff_t(A, "1 days")) == 3, B, C)
  341. </pre></div>
  342. <h2>REFERENCES</h2>
  343. <a href="http://www.dabeaz.com/ply/">PLY(Python-Lex-Yacc)</a>
  344. <h2>SEE ALSO</h2>
  345. <em>
  346. <a href="t.select.html">t.select</a>
  347. </em>
  348. <h2>AUTHORS</h2>
  349. Thomas Leppelt, Soeren Gebbert, Th&uuml;nen Institute of Climate-Smart Agriculture
  350. <p><i>Last changed: $Date$</i>