[GRASS-SVN] r48309 - in grass/trunk: lib/python lib/temporal
temporal/t.remove temporal/tr.register temporal/tr.unregister
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Sep 15 19:39:20 EDT 2011
Author: huhabla
Date: 2011-09-15 16:39:19 -0700 (Thu, 15 Sep 2011)
New Revision: 48309
Added:
grass/trunk/temporal/tr.register/test.tr.register.sh
Modified:
grass/trunk/lib/python/tgis_abstract_datasets.py
grass/trunk/lib/python/tgis_core.py
grass/trunk/lib/temporal/test.temporal.py
grass/trunk/temporal/t.remove/t.remove.py
grass/trunk/temporal/tr.register/tr.register.py
grass/trunk/temporal/tr.unregister/tr.unregister.py
Log:
Tests for temporal database handling implemented. All implemented temporal gis modules are now full functional.
Modified: grass/trunk/lib/python/tgis_abstract_datasets.py
===================================================================
--- grass/trunk/lib/python/tgis_abstract_datasets.py 2011-09-15 21:45:29 UTC (rev 48308)
+++ grass/trunk/lib/python/tgis_abstract_datasets.py 2011-09-15 23:39:19 UTC (rev 48309)
@@ -52,8 +52,11 @@
def get_relative_time(self):
"""Returns the relative time interval or None if not present"""
return self.relative_time.get_interval()
+
+ def get_temporal_type(self):
+ """Return the temporal type of this dataset"""
+ return self.base.get_ttype()
-
def get_spatial_extent(self):
"""Return a tuple of spatial extent (north, south, east, west, top, bottom) """
@@ -194,6 +197,17 @@
self.absolute_time.set_start_time(start_time)
self.absolute_time.set_end_time(end_time)
self.absolute_time.set_timezone(timezone)
+
+ def update_absolute_time(self, start_time, end_time=None, timezone=None):
+ """Update the absolute time
+
+ @start_time a datetime object specifying the start time of the map
+ @end_time a datetime object specifying the end time of the map
+ @timezone Thee timezone of the map
+ """
+ self.set_absolute_time(start_time, end_time, timezone)
+ self.absolute_time.update()
+ self.base.update()
def set_relative_time(self, interval):
"""Set the relative time interval
@@ -203,8 +217,18 @@
"""
self.base.set_ttype("relative")
- self.absolute_time.set_interval(interval)
-
+ self.relative_time.set_interval(interval)
+
+ def update_relative_time(self, interval):
+ """Set the relative time interval
+
+ @interval A double value in days
+
+ """
+ self.set_relative_time(interval)
+ self.relative_time.update()
+ self.base.update()
+
def set_spatial_extent(self, north, south, east, west, top=0, bottom=0):
"""Set the spatial extent of the map"""
self.spatial_extent.set_spatial_extent(north, south, east, west, top, bottom)
@@ -217,37 +241,49 @@
* Remove the space time dataset register table
"""
if self.is_in_db():
- # Get all data
- self.select()
- # Remove the map from all registered space time datasets
- if self.get_stds_register() != None:
- # Select all stds tables in which this map is registered
- sql = "SELECT id FROM " + self.get_stds_register()
- #print sql
- self.base.connect()
- self.base.cursor.execute(sql)
- rows = self.base.cursor.fetchall()
- self.base.close()
-
- # For each stds in which the map is registered
- if rows:
- for row in rows:
- # Create a space time dataset object to remove the map
- # from its register
- strds = self.get_new_stds_instance(row["id"])
- strds.select()
- strds.unregister_map(self)
-
- # Remove the strds register table
- sql = "DROP TABLE " + self.get_stds_register()
- #print sql
- self.base.connect()
- self.base.cursor.execute(sql)
- self.base.close()
+ # First we unregister from all dependent space time datasets
+ self.unregister()
+
+ # Remove the strds register table
+ sql = "DROP TABLE " + self.get_stds_register()
+ #print sql
+ self.base.connect()
+ self.base.cursor.execute(sql)
+ self.base.close()
+
+ core.verbose("Delete " + self.get_type() + " dataset <" + self.get_id() + "> from temporal database")
+
# Delete yourself from the database, trigger functions will take care of dependencies
self.base.delete()
+ def unregister(self):
+ """ Remove the map entry in each space time dataset in which this map is registered
+ """
+
+ core.verbose("Unregister " + self.get_type() + " dataset <" + self.get_id() + "> from space time datasets")
+
+ # Select all data from the database
+ self.select()
+ # Remove the map from all registered space time datasets
+ if self.get_stds_register() != None:
+ # Select all stds tables in which this map is registered
+ sql = "SELECT id FROM " + self.get_stds_register()
+ #print sql
+ self.base.connect()
+ self.base.cursor.execute(sql)
+ rows = self.base.cursor.fetchall()
+ self.base.close()
+
+ # For each stds in which the map is registered
+ if rows:
+ for row in rows:
+ # Create a space time dataset object to remove the map
+ # from its register
+ strds = self.get_new_stds_instance(row["id"])
+ strds.select()
+ strds.unregister_map(self)
+
###############################################################################
class abstract_space_time_dataset(abstract_dataset):
@@ -306,7 +342,7 @@
# First we need to check if maps are registered in this dataset and
# unregister them
- core.info("Delete space time " + self.get_new_map_instance(ident=None).get_type() + " dataset: " + self.get_id())
+ core.verbose("Delete space time " + self.get_new_map_instance(ident=None).get_type() + " dataset <" + self.get_id() + "> from temporal database")
if self.get_map_register():
sql = "SELECT id FROM " + self.get_map_register()
@@ -342,7 +378,7 @@
if map.is_in_db() == False:
core.fatal("Only maps with absolute or relative valid time can be registered")
- core.info("Register " + map.get_type() + " map: " + map.get_id())
+ core.verbose("Register " + map.get_type() + " map: " + map.get_id() + " in space time " + map.get_type() + " dataset <" + self.get_id() + ">")
# First select all data from the database
map.select()
@@ -372,8 +408,8 @@
self.base.close()
# In case of no entry make a new one
if row and row[0] == map_id:
- core.warning("Map " + map_id + "is already registered")
- return False
+ core.warning("Map " + map_id + "is already registered. Will unregister map and register again.")
+ self.unregister_map(map)
# Create tables
sql_path = get_sql_template_path()
@@ -400,9 +436,9 @@
# Set the stds register table name and put it into the DB
map.set_stds_register(map_register_table)
map.metadata.update()
+
+ core.verbose("Created register table <" + map_register_table + "> for " + map.get_type() + " map <" + map.get_id() + ">")
- #print "Created map register table ", map_register_table
-
# We need to create the table and register it
if stds_register_table == None:
# Read the SQL template
@@ -435,7 +471,7 @@
self.set_map_register(stds_register_table)
self.metadata.update()
- #print "Created stds register table ", stds_register_table
+ core.verbose("Created register table <" + stds_register_table + "> for space time " + map.get_type() + " dataset <" + self.get_id() + ">")
# Register the stds in the map stds register table
# Check if the entry is already there
@@ -470,9 +506,9 @@
"""
if map.is_in_db() == False:
- core.fatal("Only maps with absolute or relative valid time can be registered")
+ core.fatal("Unable to find map <" + map.get_id() + "> in temporal database")
- core.info("Unegister " + map.get_type() + " map: " + map.get_id())
+ core.verbose("Unregister " + map.get_type() + " map: " + map.get_id() + " from space time " + map.get_type() + " dataset <" + self.get_id() + ">")
# First select all data from the database
map.select()
@@ -491,7 +527,8 @@
# Break if the map is not registered
if row == None:
- core.fatal("Map " + map_id + " is not registered in space time dataset " + self.base.get_id())
+ core.warning("Map " + map_id + " is not registered in space time dataset " + self.base.get_id())
+ return False
# Remove the space time raster dataset from the raster dataset register
if map_register_table != None:
@@ -505,4 +542,6 @@
sql = "DELETE FROM " + stds_register_table + " WHERE id = ?"
self.base.connect()
self.base.cursor.execute(sql, (map_id,))
- self.base.close()
\ No newline at end of file
+ self.base.close()
+
+ return True
\ No newline at end of file
Modified: grass/trunk/lib/python/tgis_core.py
===================================================================
--- grass/trunk/lib/python/tgis_core.py 2011-09-15 21:45:29 UTC (rev 48308)
+++ grass/trunk/lib/python/tgis_core.py 2011-09-15 23:39:19 UTC (rev 48309)
@@ -26,20 +26,131 @@
import os
import sqlite3
import core
-from datetime import datetime, date, time
+import copy
+from datetime import datetime, date, time, timedelta
+###############################################################################
+
def get_grass_location_db_path():
grassenv = core.gisenv()
dbpath = os.path.join(grassenv["GISDBASE"], grassenv["LOCATION_NAME"])
return os.path.join(dbpath, "grass.db")
+###############################################################################
+
def get_sql_template_path():
base = os.getenv("GISBASE")
base_etc = os.path.join(base, "etc")
return os.path.join(base_etc, "sql")
+def test_increment_datetime_by_string():
+
+ dt = datetime(2001, 9, 1, 0, 0, 0)
+ string = "60 seconds, 4 minutes, 12 hours, 10 days, 1 weeks, 5 months, 1 years"
+
+ dt1 = datetime(2003,2,18,12,5,0)
+ dt2 = increment_datetime_by_string(dt, string)
+
+ delta = dt1 -dt2
+
+ if delta.days != 0 or delta.seconds != 0:
+ core.fatal("increment computation is wrong")
+
+def increment_datetime_by_string(mydate, increment, mult = 1):
+ """Return a new datetime object incremented with the provided relative dates specified as string.
+ Additional a multiplier can be specified to multiply the increment bevor adding to the provided datetime object.
+
+ @mydate A datetime object to incremented
+ @increment A string providing increment information:
+ The string may include comma separated values of type seconds, minutes, hours, days, weeks, months and years
+ Example: Increment the datetime 2001-01-01 00:00:00 with "60 seconds, 4 minutes, 12 hours, 10 days, 1 weeks, 5 months, 1 years"
+ will result in the datetime 2003-02-18 12:05:00
+ @mult A multiplier, default is 1
+ """
+
+ if increment:
+
+ seconds = 0
+ minutes = 0
+ hours = 0
+ days = 0
+ weeks = 0
+ months = 0
+ years = 0
+
+ inclist = []
+ # Split the increment string
+ incparts = increment.split(",")
+ for incpart in incparts:
+ inclist.append(incpart.strip().split(" "))
+
+ for inc in inclist:
+ if inc[1].find("seconds") >= 0:
+ seconds = mult * int(inc[0])
+ elif inc[1].find("minutes") >= 0:
+ minutes = mult * int(inc[0])
+ elif inc[1].find("hours") >= 0:
+ hours = mult * int(inc[0])
+ elif inc[1].find("days") >= 0:
+ days = mult * int(inc[0])
+ elif inc[1].find("weeks") >= 0:
+ weeks = mult * int(inc[0])
+ elif inc[1].find("months") >= 0:
+ months = mult * int(inc[0])
+ elif inc[1].find("years") >= 0:
+ years = mult * int(inc[0])
+ else:
+ core.fatal("Wrong increment format: " + increment)
+
+ return increment_datetime(mydate, years, months, weeks, days, hours, minutes, seconds)
+
+ return mydate
+
###############################################################################
+def increment_datetime(mydate, years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0):
+ """Return a new datetime object incremented with the provided relative dates"""
+
+ tdelta_seconds = timedelta(seconds=seconds)
+ tdelta_minutes = timedelta(minutes=minutes)
+ tdelta_hours = timedelta(hours=hours)
+ tdelta_days = timedelta(days=days)
+ tdelta_weeks = timedelta(weeks=weeks)
+ tdelta_months = timedelta(0)
+ tdelta_years = timedelta(0)
+
+ if months > 0:
+ # Compute the actual number of days in the month to add as timedelta
+ year = mydate.year
+ month = mydate.month
+
+ all_months = int(months + month)
+
+ years_to_add = int(all_months/12)
+ residual_months = all_months%12
+
+ # Make a deep copy of the datetime object
+ dt1 = copy.copy(mydate)
+
+ # Make sure the montha starts with a 1
+ if residual_months == 0:
+ residual_months = 1
+
+ dt1 = dt1.replace(year = year + years_to_add, month = residual_months)
+ tdelta_months = dt1 - mydate
+
+ if years > 0:
+ # Make a deep copy of the datetime object
+ dt1 = copy.copy(mydate)
+ # Compute the number of days
+ dt1 = dt1.replace(year=mydate.year + int(years))
+ tdelta_years = dt1 - mydate
+
+ return mydate + tdelta_seconds + tdelta_minutes + tdelta_hours + \
+ tdelta_days + tdelta_weeks + tdelta_months + tdelta_years
+
+###############################################################################
+
def create_temporal_database():
"""This function creates the grass location database structure for raster, vector and raster3d maps
as well as for the space-time datasets strds, str3ds and stvds"""
Modified: grass/trunk/lib/temporal/test.temporal.py
===================================================================
--- grass/trunk/lib/temporal/test.temporal.py 2011-09-15 21:45:29 UTC (rev 48308)
+++ grass/trunk/lib/temporal/test.temporal.py 2011-09-15 23:39:19 UTC (rev 48309)
@@ -815,13 +815,13 @@
test_dict_sql_serializer()
create_temporal_database()
-test_dataset_identifer()
-test_absolute_timestamp()
-test_relative_timestamp()
-test_spatial_extent()
-test_map_metadata()
-test_base_absolute_time_extent_metadata()
-test_absolut_time_temporal_relations()
+#test_dataset_identifer()
+#test_absolute_timestamp()
+#test_relative_timestamp()
+#test_spatial_extent()
+#test_map_metadata()
+#test_base_absolute_time_extent_metadata()
+#test_absolut_time_temporal_relations()
test_raster_dataset()
test_raster3d_dataset()
@@ -829,4 +829,5 @@
test_strds_dataset()
test_str3ds_dataset()
-test_stvds_dataset()
\ No newline at end of file
+test_stvds_dataset()
+test_increment_datetime_by_string()
Modified: grass/trunk/temporal/t.remove/t.remove.py
===================================================================
--- grass/trunk/temporal/t.remove/t.remove.py 2011-09-15 21:45:29 UTC (rev 48308)
+++ grass/trunk/temporal/t.remove/t.remove.py 2011-09-15 23:39:19 UTC (rev 48309)
@@ -24,7 +24,7 @@
#%option
#% key: dataset
#% type: string
-#% description: Name of the new space time or map dataset
+#% description: Name(s) of the space time or map dataset to be removed from the temporal database
#% required: yes
#% multiple: no
#%end
@@ -45,34 +45,41 @@
def main():
# Get the options
- name = options["dataset"]
+ names = options["dataset"]
type = options["type"]
# Make sure the temporal database exists
grass.create_temporal_database()
mapset = grass.gisenv()["MAPSET"]
- id = name + "@" + mapset
+
+ for name in names.split(","):
+ name = name.strip()
+ # Check for the mapset in name
+ if name.find("@") < 0:
+ id = name + "@" + mapset
+ else:
+ id = name
- if type == "strds":
- sp = grass.space_time_raster_dataset(id)
- if type == "str3ds":
- sp = grass.space_time_raster3d_dataset(id)
- if type == "stvds":
- sp = grass.space_time_vector_dataset(id)
- if type == "raster":
- sp = grass.raster_dataset(id)
- if type == "raster3d":
- sp = grass.raster3d_dataset(id)
- if type == "vector":
- sp = grass.vector_dataset(id)
+ if type == "strds":
+ sp = grass.space_time_raster_dataset(id)
+ if type == "str3ds":
+ sp = grass.space_time_raster3d_dataset(id)
+ if type == "stvds":
+ sp = grass.space_time_vector_dataset(id)
+ if type == "raster":
+ sp = grass.raster_dataset(id)
+ if type == "raster3d":
+ sp = grass.raster3d_dataset(id)
+ if type == "vector":
+ sp = grass.vector_dataset(id)
- if sp.is_in_db() == False:
- grass.fatal("Dataset <" + name + "> not found in temporal database")
+ if sp.is_in_db() == False:
+ grass.fatal("Dataset <" + name + "> not found in temporal database")
- # Insert content from db
- sp.select()
- sp.delete()
+ # We need to read some data from the temporal database
+ sp.select()
+ sp.delete()
if __name__ == "__main__":
options, flags = grass.core.parser()
Added: grass/trunk/temporal/tr.register/test.tr.register.sh
===================================================================
--- grass/trunk/temporal/tr.register/test.tr.register.sh (rev 0)
+++ grass/trunk/temporal/tr.register/test.tr.register.sh 2011-09-15 23:39:19 UTC (rev 48309)
@@ -0,0 +1,59 @@
+# This is a test to register and unregister raster maps in
+# space time raster dataset.
+# The raster maps will be registered in different space time raster
+# datasets
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster with r.mapcalc and create two space time raster datasets
+# with relative and absolute time
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r.mapcalc --o expr="prec_1 = rand(0, 550)"
+r.mapcalc --o expr="prec_2 = rand(0, 450)"
+r.mapcalc --o expr="prec_3 = rand(0, 320)"
+r.mapcalc --o expr="prec_4 = rand(0, 510)"
+r.mapcalc --o expr="prec_5 = rand(0, 300)"
+r.mapcalc --o expr="prec_6 = rand(0, 650)"
+
+
+# The first @test
+# We create the space time raster datasets and register the raster maps with absolute time interval
+
+t.create --v --o type=strds temporaltype=absolute dataset=precip_abs1 gran="1 senconds" title="A test" descr="A test"
+t.create --v --o type=strds temporaltype=absolute dataset=precip_abs2 gran="1 minutes" title="A test" descr="A test"
+t.create --v --o type=strds temporaltype=absolute dataset=precip_abs3 gran="1 hours" title="A test" descr="A test"
+t.create --v --o type=strds temporaltype=absolute dataset=precip_abs4 gran="1 days" title="A test" descr="A test"
+t.create --v --o type=strds temporaltype=absolute dataset=precip_abs5 gran="1 weeks" title="A test" descr="A test"
+t.create --v --o type=strds temporaltype=absolute dataset=precip_abs6 gran="1 months" title="A test" descr="A test"
+t.create --v --o type=strds temporaltype=absolute dataset=precip_abs7 gran="1 years" title="A test" descr="A test"
+
+tr.register --v dataset=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 seconds"
+t.info type=strds dataset=precip_abs1
+tr.unregister --v dataset=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.info type=strds dataset=precip_abs1
+
+tr.register --v dataset=precip_abs2 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 seconds, 5 minutes"
+t.info type=strds dataset=precip_abs2
+
+tr.register --v dataset=precip_abs3 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="8 hours"
+t.info type=strds dataset=precip_abs3
+tr.unregister --v maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.info type=strds dataset=precip_abs3
+
+tr.register dataset=precip_abs4 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="3 days"
+t.info type=strds dataset=precip_abs4
+
+tr.register dataset=precip_abs5 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="4 weeks"
+t.info type=strds dataset=precip_abs5
+
+tr.register dataset=precip_abs6 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-08-01" increment="2 months"
+t.info type=strds dataset=precip_abs6
+
+tr.register dataset=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 years, 3 months, 1 days, 4 hours"
+t.info type=strds dataset=precip_abs7
+
+t.remove --v type=raster dataset=prec_1,prec_2,prec_3
+t.remove --v type=strds dataset=precip_abs1,precip_abs2,precip_abs3,precip_abs4,precip_abs5,precip_abs6,precip_abs7
+t.remove --v type=raster dataset=prec_4,prec_5,prec_6
\ No newline at end of file
Modified: grass/trunk/temporal/tr.register/tr.register.py
===================================================================
--- grass/trunk/temporal/tr.register/tr.register.py 2011-09-15 21:45:29 UTC (rev 48308)
+++ grass/trunk/temporal/tr.register/tr.register.py 2011-09-15 23:39:19 UTC (rev 48309)
@@ -39,7 +39,7 @@
#%option
#% key: start
#% type: string
-#% description: The start date and time of the first raster map, in case the map has no date (format absolute: "yyyy-mm-dd HH:MM:SS", relative 5.0)
+#% description: The start date and time of the first raster map, in case the map has no date (format absolute: "yyyy-mm-dd HH:MM:SS", format relative 5.0)
#% required: no
#% multiple: no
#%end
@@ -47,15 +47,14 @@
#%option
#% key: increment
#% type: string
-#% description: Time increment between maps for time stamp creation (NNN seconds, minutes, hours, days, weeks)
+#% description: Time increment between maps for time stamp creation (format absolute: NNN seconds, minutes, hours, days, weeks, months, years; format relative: 1.0)
#% required: no
#% multiple: no
#%end
import datetime
-from datetime import timedelta
-import time
import grass.script as grass
+from copy import *
#######################
#####################################################
@@ -67,6 +66,9 @@
start = options["start"]
increment = options["increment"]
+ # Make sure the temporal database exists
+ grass.create_temporal_database()
+
mapset = grass.gisenv()["MAPSET"]
id = name + "@" + mapset
@@ -81,13 +83,6 @@
maplist = (maps,)
else:
maplist = tuple(maps.split(","))
-
- if increment:
- if sp.is_time_absolute():
- inc_value = float(increment.split(" ")[0])
- inc_unit = increment.split(" ")[1]
- else:
- inc_value = float(increment)
count = 0
for mapname in maplist:
@@ -99,52 +94,39 @@
# Put the map into the database
if map.is_in_db() == False:
map.load()
-
- # Put map with time interval in the database
map.insert()
else:
map.select()
-
- if map.get_temporal_type() != sp.get_temporal_type():
- grass.fatal("Unable to register map. The map has a different temporal types.")
+ if map.get_temporal_type() != sp.get_temporal_type():
+ grass.fatal("Unable to register map <" + map.get_id() + ">. The temporal types are different.")
# Set the time interval
if start:
- grass.info("Set/overwrite time interval for map " + mapname)
if sp.is_time_absolute():
-
+ # Create the start time object
if start.find(":") > 0:
time_format = "%Y-%m-%d %H:%M:%S"
else:
time_format = "%Y-%m-%d"
-
- start_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(start, time_format)))
+
+ start_time = datetime.datetime.strptime(start, time_format)
end_time = None
+ # Add the increment
if increment:
- if inc_unit.find("seconds") >= 0:
- tdelta = timedelta(seconds=inc_value)
- elif inc_unit.find("minutes") >= 0:
- tdelta = timedelta(minutes=inc_value)
- elif inc_unit.find("hours") >= 0:
- tdelta = timedelta(hours=inc_value)
- elif inc_unit.find("days") >= 0:
- tdelta = timedelta(days=inc_value)
- elif inc_unit.find("weeks") >= 0:
- tdelta = timedelta(weeks=inc_value)
- else:
- grass.fatal("Wrong increment format: " + increment)
+ start_time = grass.increment_datetime_by_string(start_time, increment, count)
+ end_time = grass.increment_datetime_by_string(start_time, increment, 1)
- start_time += count * tdelta
- end_time = start_time + tdelta
-
- map.set_absolute_time(start_time, end_time)
- map.absolute_time.update()
+ grass.verbose("Set absolute time interval for map <" + mapid + "> to " + str(start_time) + " - " + str(end_time))
+ map.update_absolute_time(start_time, end_time)
else:
- interval = float(start) + count * inc_value
- map.set_relative_time(interval)
- map.arelative_time.update()
+ if increment:
+ interval = float(start) + count * float(increment)
+ else:
+ interval = float(start)
+ grass.verbose("Set relative time interval for map <" + mapid + "> to " + str(interval))
+ map.update_relative_time(interval)
# Register map
sp.register_map(map)
Modified: grass/trunk/temporal/tr.unregister/tr.unregister.py
===================================================================
--- grass/trunk/temporal/tr.unregister/tr.unregister.py 2011-09-15 21:45:29 UTC (rev 48308)
+++ grass/trunk/temporal/tr.unregister/tr.unregister.py 2011-09-15 23:39:19 UTC (rev 48309)
@@ -5,7 +5,7 @@
# MODULE: tr.unregister
# AUTHOR(S): Soeren Gebbert
#
-# PURPOSE: Unregister raster map a space time raster dataset
+# PURPOSE: Unregister raster maps from space time raster datasets
# COPYRIGHT: (C) 2011 by the GRASS Development Team
#
# This program is free software under the GNU General Public
@@ -15,16 +15,16 @@
#############################################################################
#%module
-#% description: Register raster maps in a space time raster dataset
+#% description: Unregister raster map(s) from a specific or all space time raster dataset in which it is registered
#% keywords: spacetime raster dataset
#% keywords: raster
#%end
#%option
-#% key: input
+#% key: dataset
#% type: string
-#% description: Name of an existing space time raster dataset
-#% required: yes
+#% description: Name of an existing space time raster dataset. If no name is provided the raster map(s) are unregistered from all space time datasets in which they are registered.
+#% required: no
#% multiple: no
#%end
@@ -42,9 +42,44 @@
def main():
# Get the options
- input = options["input"]
+ name = options["dataset"]
maps = options["maps"]
+ # Make sure the temporal database exists
+ grass.create_temporal_database()
+
+ mapset = grass.gisenv()["MAPSET"]
+
+ # In case a space time raster dataset is specified
+ if name:
+
+ id = name + "@" + mapset
+
+ sp = grass.space_time_raster_dataset(id)
+ # Read content from db
+ sp.select()
+
+ if sp.is_in_db() == False:
+ grass.fatal("Space time " + sp.get_new_map_instance(None).get_type() + " dataset <" + name + "> not found")
+
+ # Build the list of maps
+ if maps.find(",") == -1:
+ maplist = (maps,)
+ else:
+ maplist = tuple(maps.split(","))
+
+ for mapname in maplist:
+ mapid = mapname + "@" + mapset
+ map = grass.raster_dataset(mapid)
+
+ # Unregister map if in database
+ if map.is_in_db() == True:
+ if name:
+ sp.unregister_map(map)
+ else:
+ map.select()
+ map.unregister()
+
if __name__ == "__main__":
options, flags = grass.core.parser()
main()
More information about the grass-commit
mailing list