[GRASS-SVN] r51247 - in grass/trunk/temporal: t.register t.support
t.unregister
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Apr 4 04:55:15 EDT 2012
Author: huhabla
Date: 2012-04-04 01:55:14 -0700 (Wed, 04 Apr 2012)
New Revision: 51247
Modified:
grass/trunk/temporal/t.register/test.t.register.raster.sh
grass/trunk/temporal/t.support/t.support.py
grass/trunk/temporal/t.support/test.t.support.sh
grass/trunk/temporal/t.unregister/t.unregister.py
Log:
New map update functionality in t.support. Test update.
Modified: grass/trunk/temporal/t.register/test.t.register.raster.sh
===================================================================
--- grass/trunk/temporal/t.register/test.t.register.raster.sh 2012-04-04 07:46:42 UTC (rev 51246)
+++ grass/trunk/temporal/t.register/test.t.register.raster.sh 2012-04-04 08:55:14 UTC (rev 51247)
@@ -5,8 +5,8 @@
# 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 inputs
-# with relative and absolute time
+# raster with r.mapcalc and create several space time raster datasets
+# with 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
Modified: grass/trunk/temporal/t.support/t.support.py
===================================================================
--- grass/trunk/temporal/t.support/t.support.py 2012-04-04 07:46:42 UTC (rev 51246)
+++ grass/trunk/temporal/t.support/t.support.py 2012-04-04 08:55:14 UTC (rev 51247)
@@ -53,6 +53,11 @@
#%end
#%flag
+#% key: m
+#% description: Update the metadata information and spatial extent of registered maps from the grass spatial database
+#%end
+
+#%flag
#% key: u
#% description: Update metadata information, temporal and spatial extent from registered maps
#%end
@@ -71,6 +76,7 @@
descr = options["description"]
semantic = options["semantictype"]
update = flags["u"]
+ map_update = flags["m"]
# Make sure the temporal database exists
tgis.create_temporal_database()
@@ -82,22 +88,43 @@
id = name
else:
id = name + "@" + mapset
+
+ dbif, connect = tgis.init_dbif(None)
sp = tgis.dataset_factory(type, id)
- if sp.is_in_db() == False:
- grass.fatal(_("%s dataset <%s> not found in temporal database") % (ds.get_type(), name))
+ if sp.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))
- sp.select()
+ 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()
+ sp.update(dbif=dbif)
- if update:
- sp.update_from_registered_maps()
+ if map_update:
+ #Update the registered maps from the grass spatial database
+ statement = ""
+ count = 0
+ maps = sp.get_registered_maps_as_objects(dbif=dbif)
+ for map in maps:
+ map.select(dbif=dbif)
+ map.load()
+ statement += map.update(dbif=dbif, execute=False)
+ grass.percent(count, len(maps), 1)
+ count += 1
+
+ # Execute the collected SQL statenents
+ tgis.execute_transaction(statement, dbif)
+
+ if map_update or update:
+ sp.update_from_registered_maps(dbif=dbif)
+
+ dbif.close()
+
if __name__ == "__main__":
options, flags = grass.parser()
main()
Modified: grass/trunk/temporal/t.support/test.t.support.sh
===================================================================
--- grass/trunk/temporal/t.support/test.t.support.sh 2012-04-04 07:46:42 UTC (rev 51246)
+++ grass/trunk/temporal/t.support/test.t.support.sh 2012-04-04 08:55:14 UTC (rev 51247)
@@ -1,3 +1,11 @@
+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)"
# We create several space time raster datasets
# A simple space ime raster datasets creation and unpdate @test with absolute time
@@ -2,6 +10,18 @@
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.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
+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)"
+t.support --v -m type=strds input=precip_abs1
+t.info type=strds input=precip_abs1
+
# A simple space ime raster datasets creation and update @test with relative time
@@ -13,3 +33,5 @@
t.info type=strds input=precip_rel1
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
Modified: grass/trunk/temporal/t.unregister/t.unregister.py
===================================================================
--- grass/trunk/temporal/t.unregister/t.unregister.py 2012-04-04 07:46:42 UTC (rev 51246)
+++ grass/trunk/temporal/t.unregister/t.unregister.py 2012-04-04 08:55:14 UTC (rev 51247)
@@ -54,35 +54,16 @@
# Make sure the temporal database exists
tgis.create_temporal_database()
- # Unregister maps
- unregister_maps_from_space_time_datasets(type=type, name=name, maps=maps, file=file, dbif=None)
-############################################################################
-
-def unregister_maps_from_space_time_datasets(type, name, maps, file=None, dbif=None):
- """Unregister maps from a single space time dataset or, in case no dataset name is provided,
- unregister from all datasets within the maps are registered.
-
- @param type: The type of the maps raster, vector or raster3d
- @param name: 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.
- @param maps: A comma separated list of map names
- @param file: Input file one map per line
- @param dbif: The database interface to be used
- """
-
if maps and file:
grass.fatal(_("%s= and %s= are mutually exclusive") % ("input","file"))
if not maps and not file:
grass.fatal(_("%s= or %s= must be specified") % ("input","file"))
-
mapset = grass.gisenv()["MAPSET"]
- if dbif == None:
- dbif = tgis.sql_database_interface()
- dbif.connect()
- connect = True
+ dbif, connect = tgis.init_dbif(None)
# In case a space time dataset is specified
if name:
@@ -101,7 +82,7 @@
if sp.is_in_db(dbif) == False:
dbif.close()
- grass.fatal("Space time " + sp.get_new_map_instance(None).get_type() + " dataset <" + name + "> not found")
+ grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
maplist = []
@@ -141,6 +122,7 @@
statement = ""
# Unregister already registered maps
+ grass.message(_("Unregistered maps"))
for mapid in maplist:
grass.percent(count, num_maps, 1)
@@ -169,21 +151,17 @@
count += 1
# Execute the collected SQL statenents
- sql_script = ""
- sql_script += "BEGIN TRANSACTION;\n"
- sql_script += statement
- sql_script += "END TRANSACTION;"
- # print sql_script
+ tgis.execute_transaction(statement, dbif)
+
+ grass.percent(num_maps, num_maps, 1)
- if tgis.dbmi.__name__ == "sqlite3":
- dbif.cursor.executescript(statement)
- else:
- dbif.cursor.execute(statement)
-
# Update space time datasets
+
+ grass.message(_("Unregistered maps from space time dataset(s)"))
if name:
sp.update_from_registered_maps(dbif)
elif len(update_dict) > 0:
+ count = 0
for key in update_dict.keys():
id = update_dict[key]
if type == "rast":
@@ -197,11 +175,10 @@
sp.metadata.select(dbif)
sp.update_from_registered_maps(dbif)
+ grass.percent(count, len(update_dict), 1)
+ count += 1
- if connect == True:
- dbif.close()
-
- grass.percent(num_maps, num_maps, 1)
+ dbif.close()
###############################################################################
More information about the grass-commit
mailing list