2
# -*- coding: utf-8 -*-
3
############################################################################
6
# AUTHOR(S): Soeren Gebbert
8
# PURPOSE: List temporal topology of a space time dataset
9
# COPYRIGHT: (C) 2011-2014 by the GRASS Development Team
11
# This program is free software under the GNU General Public
12
# License (version 2). Read the file COPYING that comes with GRASS
15
#############################################################################
18
#% description: Lists temporal topology of a space time dataset.
23
#%option G_OPT_STDS_INPUT
26
#%option G_OPT_STDS_TYPE
27
#% guidependency: input
28
#% guisection: Required
31
#%option G_OPT_T_WHERE
36
#% description: Print temporal relationships and exit
41
#% description: Print spatio-temporal relationships and exit
44
import grass.script as grass
45
import grass.temporal as tgis
47
############################################################################
53
name = options["input"]
54
type = options["type"]
55
where = options["where"]
56
temporal_relations = flags['m']
57
spatio_temporal_relations = flags['s']
59
# Make sure the temporal database exists
62
sp = tgis.open_old_stds(name, type)
64
# Get ordered map list
65
maps = sp.get_registered_maps_as_objects(
66
where=where, order="start_time", dbif=None)
70
if spatio_temporal_relations:
71
if sp.get_type() == "strds":
76
if temporal_relations or spatio_temporal_relations:
77
sp.print_spatio_temporal_relationships(maps=maps, spatial=spatial)
82
# 0123456789012345678901234567890
83
print " +-------------------- Temporal topology -------------------------------------+"
85
print " | Is subset of dataset: ...... True"
87
print " | Is subset of dataset: ...... False"
89
check = sp.check_temporal_topology(maps)
91
# 0123456789012345678901234567890
92
print " | Temporal topology is: ...... valid"
94
# 0123456789012345678901234567890
95
print " | Temporal topology is: ...... invalid"
97
dict_ = sp.count_temporal_types(maps)
99
for key in dict_.keys():
100
if key == "interval":
101
# 0123456789012345678901234567890
102
print " | Number of intervals: ....... %s" % (dict_[key])
104
print " | Number of points: .......... %s" % (dict_[key])
106
print " | Invalid time stamps: ....... %s" % (dict_[key])
108
# 0123456789012345678901234567890
109
print " | Number of gaps: ............ %i" % sp.count_gaps(maps)
111
if sp.is_time_absolute():
112
gran = tgis.compute_absolute_time_granularity(maps)
114
gran = tgis.compute_relative_time_granularity(maps)
115
print " | Granularity: ............... %s" % str(gran)
117
print " +-------------------- Topological relations ---------------------------------+"
118
dict_ = sp.count_temporal_relations(maps)
121
for key in dict_.keys():
123
# 0123456789012345678901234567890
124
print " | Equal:...................... %s" % (dict_[key])
126
print " | During: .................... %s" % (dict_[key])
127
if key == "contains":
128
print " | Contains: .................. %s" % (dict_[key])
129
if key == "overlaps":
130
print " | Overlaps: .................. %s" % (dict_[key])
131
if key == "overlapped":
132
print " | Overlapped: ................ %s" % (dict_[key])
134
print " | After: ..................... %s" % (dict_[key])
136
print " | Before: .................... %s" % (dict_[key])
138
print " | Starts: .................... %s" % (dict_[key])
139
if key == "finishes":
140
print " | Finishes: .................. %s" % (dict_[key])
142
print " | Started: ................... %s" % (dict_[key])
143
if key == "finished":
144
print " | Finished: .................. %s" % (dict_[key])
146
print " | Follows: ................... %s" % (dict_[key])
147
if key == "precedes":
148
print " | Precedes: .................. %s" % (dict_[key])
149
print " +----------------------------------------------------------------------------+"
151
if __name__ == "__main__":
152
options, flags = grass.parser()