1#!/usr/local/bin/python3.8
2# -*- coding: utf-8 -*-
3############################################################################
4#
5# MODULE:	t.register
6# AUTHOR(S):	Soeren Gebbert
7#
8# PURPOSE:	Registers raster, vector and raster3d maps in a space time dataset
9# COPYRIGHT:	(C) 2011-2017, Soeren Gebbert and the GRASS Development Team
10#
11#  This program is free software; you can redistribute it and/or modify
12#  it under the terms of the GNU General Public License as published by
13#  the Free Software Foundation; either version 2 of the License, or
14#  (at your option) any later version.
15#
16#  This program is distributed in the hope that it will be useful,
17#  but WITHOUT ANY WARRANTY; without even the implied warranty of
18#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19#  GNU General Public License for more details.
20#
21#############################################################################
22
23#%module
24#% description: Assigns timestamps and registers raster, vector and raster3d maps in a space time dataset.
25#% keyword: temporal
26#% keyword: map management
27#% keyword: register
28#% keyword: time
29#% overwrite: yes
30#%end
31
32#%option G_OPT_STDS_INPUT
33#% required: no
34#% guisection: Input
35#%end
36
37#%option G_OPT_MAP_INPUTS
38#% required: no
39#% guisection: Input
40#%end
41
42#%option G_OPT_MAP_TYPE
43#% guidependency: input,maps
44#% guisection: Input
45#%end
46
47#%option G_OPT_F_INPUT
48#% key: file
49#% required: no
50#% label: Input file with map names, one per line
51#% description: Additionally the start time and the end time can be specified per line
52#% guisection: Input
53#%end
54
55#%option
56#% key: start
57#% type: string
58#% label: Valid start date and time of the first map
59#% description: Format for absolute time: "yyyy-mm-dd HH:MM:SS +HHMM", relative time is of type integer.
60#% required: no
61#% multiple: no
62#% guisection: Time & Date
63#%end
64
65#%option
66#% key: end
67#% type: string
68#% label: Valid end date and time of all map
69#% description: Format for absolute time: "yyyy-mm-dd HH:MM:SS +HHMM", relative time is of type integer.
70#% required: no
71#% multiple: no
72#% guisection: Time & Date
73#%end
74
75#%option
76#% key: unit
77#% type: string
78#% label: Time stamp unit
79#% description: Unit must be set in case of relative timestamps
80#% required: no
81#% multiple: no
82#% options: years,months,days,hours,minutes,seconds
83#% guisection: Time & Date
84#%end
85
86#%option
87#% key: increment
88#% type: string
89#% label: Time increment, works only in conjunction with start option
90#% description: Time increment between maps for creation of valid time intervals (format for absolute time: NNN seconds, minutes, hours, days, weeks, months, years; format for relative time is of type integer: 5)
91#% required: no
92#% multiple: no
93#% guisection: Time & Date
94#%end
95
96#%option G_OPT_F_SEP
97#% label: Field separator character of the input file
98#% guisection: Input
99#%end
100
101#%flag
102#% key: i
103#% description: Create an interval (start and end time) in case an increment and the start time are provided
104#% guisection: Time & Date
105#%end
106
107import grass.script as grass
108
109
110############################################################################
111
112
113def main():
114    # Get the options
115    name = options["input"]
116    maps = options["maps"]
117    type = options["type"]
118    file = options["file"]
119    separator = grass.separator(options["separator"])
120    start = options["start"]
121    end = options["end"]
122    unit = options["unit"]
123    increment = options["increment"]
124    interval = flags["i"]
125
126    # Make sure the temporal database exists
127    tgis.init()
128    # Register maps
129    tgis.register_maps_in_space_time_dataset(
130        type=type, name=name, maps=maps, file=file, start=start, end=end,
131        unit=unit, increment=increment, dbif=None, interval=interval, fs=separator)
132
133
134###############################################################################
135
136if __name__ == "__main__":
137    options, flags = grass.parser()
138
139    # lazy imports
140    import grass.temporal as tgis
141
142    try:
143        from builtins import StandardError
144    except ImportError:
145        # python 3
146        StandardError = Exception
147
148    try:
149        tgis.profile_function(main)
150    except StandardError as e:
151        grass.fatal(e)
152