[GRASS-SVN] r51455 - grass/trunk/temporal/t.support
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Apr 17 08:53:28 EDT 2012
Author: huhabla
Date: 2012-04-17 05:53:28 -0700 (Tue, 17 Apr 2012)
New Revision: 51455
Modified:
grass/trunk/temporal/t.support/t.support.py
grass/trunk/temporal/t.support/test.t.support.sh
Log:
Added the temporal database unregistration of removed maps and the update of effected space time datasets.
Modified: grass/trunk/temporal/t.support/t.support.py
===================================================================
--- grass/trunk/temporal/t.support/t.support.py 2012-04-17 12:48:46 UTC (rev 51454)
+++ grass/trunk/temporal/t.support/t.support.py 2012-04-17 12:53:28 UTC (rev 51455)
@@ -54,7 +54,7 @@
#%flag
#% key: m
-#% description: Update the metadata information and spatial extent of registered maps from the grass spatial database
+#% description: Update the metadata information and spatial extent of registered maps from the grass spatial database. Check for removed maps and delete them from the temporal database and all effected space time datasets.
#%end
#%flag
@@ -73,7 +73,7 @@
name = options["input"]
type = options["type"]
title = options["title"]
- descr = options["description"]
+ description = options["description"]
semantic = options["semantictype"]
update = flags["u"]
map_update = flags["m"]
@@ -92,37 +92,74 @@
dbif = tgis.sql_database_interface_connection()
dbif.connect()
- sp = tgis.dataset_factory(type, id)
+ stds = tgis.dataset_factory(type, id)
- if sp.is_in_db(dbif=dbif) == False:
+ if stds.is_in_db(dbif=dbif) == False:
dbif.close()
- grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
+ grass.fatal(_("Space time %s dataset <%s> not found") % (stds.get_new_map_instance(None).get_type(), id))
- sp.select(dbif=dbif)
- # Temporal type can not be changed
- ttype= sp.get_temporal_type()
- sp.set_initial_values(temporal_type=ttype, semantic_type=semantic, title=title, description=descr)
- # Update only non-null entries
- sp.update(dbif=dbif)
+ stds.select(dbif=dbif)
+
+ update = False
+ if title:
+ stds.metadata.set_title(title=title)
+ update = True
+ # Update only non-null entries
+ if description:
+ stds.metadata.set_description(description=description)
+ update = True
+ if semantic:
+ stds.base.set_semantic_type(semantic_type=semantic)
+ update = True
+ if update:
+ stds.update(dbif=dbif)
+
if map_update:
#Update the registered maps from the grass spatial database
statement = ""
+ # This dict stores the datasets that must be updated
+ dataset_dict = {}
count = 0
- maps = sp.get_registered_maps_as_objects(dbif=dbif)
+ maps = stds.get_registered_maps_as_objects(dbif=dbif)
+
+ # We collect the delete and update statements
for map in maps:
- map.select(dbif=dbif)
- map.load()
- statement += map.update(dbif=dbif, execute=False)
- grass.percent(count, len(maps), 1)
+
+ grass.percent(count, len(maps), 1)
count += 1
+
+ map.select(dbif=dbif)
+
+ # Check if the map is present in the grass spatial database
+ # Update if present, delete if not present
+ if map.map_exists():
+ # Read new metadata from the spatial database
+ map.load()
+ statement += map.update(dbif=dbif, execute=False)
+ else:
+ # Delete the map from the temporal database
+ # We need to update all effected space time datasets
+ rows = map.get_registered_datasets(dbif)
+ if rows:
+ for row in rows:
+ dataset_dict[row["id"]] = row["id"]
+ # Collect the delete statements
+ statement += map.delete(dbif=dbif, update=False, execute=False)
+
# Execute the collected SQL statenents
dbif.execute_transaction(statement)
-
+
+ # Update the effected space time datasets
+ for id in dataset_dict:
+ stds_new = stds.get_new_instance(id)
+ stds_new.select(dbif=dbif)
+ stds_new.update_from_registered_maps(dbif=dbif)
+
if map_update or update:
- sp.update_from_registered_maps(dbif=dbif)
+ stds.update_from_registered_maps(dbif=dbif)
dbif.close()
Modified: grass/trunk/temporal/t.support/test.t.support.sh
===================================================================
--- grass/trunk/temporal/t.support/test.t.support.sh 2012-04-17 12:48:46 UTC (rev 51454)
+++ grass/trunk/temporal/t.support/test.t.support.sh 2012-04-17 12:53:28 UTC (rev 51455)
@@ -8,30 +8,49 @@
r.mapcalc --o expr="prec_6 = rand(0, 650)"
# We create several space time raster datasets
-# A simple space ime raster datasets creation and unpdate @test with absolute time
+# @test Register the maps in two space time datasets
t.create --v --o type=strds temporaltype=absolute output=precip_abs1 title="Test" descr="This is the 1 test strds" semantictype=sum
t.register -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 seconds"
+t.create --v --o type=strds temporaltype=absolute output=precip_abs2 title="Test" descr="This is the 2 test strds" semantictype=sum
+t.register -i input=precip_abs2 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+
+t.create --v --o type=strds temporaltype=relative output=precip_rel1 title="Test" descr="This is the 1 test strds" semantictype=min
+
+# Check metadata update
+t.info type=strds input=precip_rel1
+t.support --v type=strds input=precip_rel1 title="Test support" descr="This is the support test strds" semantictype=max
+t.info type=strds input=precip_rel1
+
+# Check metadata update
t.info type=strds input=precip_abs1
t.support --v type=strds input=precip_abs1 title="Test support" descr="This is the support test strds" semantictype=mean
t.info type=strds input=precip_abs1
-# @test the update functions
+
+# @test the map update function
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=20 res3=20
r.mapcalc --o expr="prec_1 = rand(0, 55)"
r.mapcalc --o expr="prec_2 = rand(0, 45)"
r.mapcalc --o expr="prec_3 = rand(0, 32)"
r.mapcalc --o expr="prec_4 = rand(0, 51)"
r.mapcalc --o expr="prec_5 = rand(0, 30)"
r.mapcalc --o expr="prec_6 = rand(0, 65)"
+
+# The map dependent metadata should have been updated
t.support --v -m type=strds input=precip_abs1
t.info type=strds input=precip_abs1
+t.support --v -m type=strds input=precip_abs2
+t.info type=strds input=precip_abs2
-# A simple space ime raster datasets creation and update @test with relative time
-t.create --v --o type=strds temporaltype=relative output=precip_rel1 title="Test" descr="This is the 1 test strds" semantictype=min
-t.info type=strds input=precip_rel1
-t.support --v type=strds input=precip_rel1 title="Test support" descr="This is the support test strds" semantictype=max
-t.info type=strds input=precip_rel1
+# Remove three maps
+g.remove rast=prec_1,prec_2,prec_3
+# Booth space time datasets should be updated and 3 maps must have been unregistered
+t.support --v -m type=strds input=precip_abs1
+t.info type=strds input=precip_abs1
+t.info type=strds input=precip_abs2
+
t.remove --v type=strds input=precip_abs1,precip_rel1
t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
-g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
\ No newline at end of file
+g.remove rast=prec_4,prec_5,prec_6
\ No newline at end of file
More information about the grass-commit
mailing list