[GRASS-SVN] r48187 - grass/trunk/lib/temporal
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 7 12:21:32 EDT 2011
Author: huhabla
Date: 2011-09-07 09:21:32 -0700 (Wed, 07 Sep 2011)
New Revision: 48187
Modified:
grass/trunk/lib/temporal/stds_map_register_table_template.sql
grass/trunk/lib/temporal/str3ds_metadata_table.sql
grass/trunk/lib/temporal/strds_metadata_table.sql
grass/trunk/lib/temporal/stvds_metadata_table.sql
grass/trunk/lib/temporal/test.temporal.py
Log:
More tests, SQL trigger bugfixing and variable renaming.
Modified: grass/trunk/lib/temporal/stds_map_register_table_template.sql
===================================================================
--- grass/trunk/lib/temporal/stds_map_register_table_template.sql 2011-09-07 16:20:32 UTC (rev 48186)
+++ grass/trunk/lib/temporal/stds_map_register_table_template.sql 2011-09-07 16:21:32 UTC (rev 48187)
@@ -26,8 +26,8 @@
UPDATE STDS_base SET modification_time = datetime("NOW") WHERE id = "SPACETIME_ID";
UPDATE STDS_base SET revision = (revision + 1) WHERE id = "SPACETIME_ID";
-- Number of registered maps
- UPDATE STDS_metadata SET number_of_registered_maps =
- (SELECT count.id) FROM SPACETIME_NAME_GRASS_MAP_register)
+ UPDATE STDS_metadata SET number_of_maps =
+ (SELECT count(id) FROM SPACETIME_NAME_GRASS_MAP_register)
WHERE id = "SPACETIME_ID";
-- Update the temporal extent
UPDATE STDS_absolute_time SET start_time =
@@ -70,8 +70,8 @@
UPDATE STDS_base SET modification_time = datetime("NOW") WHERE id = "SPACETIME_ID";
UPDATE STDS_base SET revision = (revision + 1) WHERE id = "SPACETIME_ID";
-- Number of registered maps
- UPDATE STDS_metadata SET number_of_registered_maps =
- (SELECT count.id) FROM SPACETIME_NAME_GRASS_MAP_register)
+ UPDATE STDS_metadata SET number_of_maps =
+ (SELECT count(id) FROM SPACETIME_NAME_GRASS_MAP_register)
WHERE id = "SPACETIME_ID";
-- Update the temporal extent
UPDATE STDS_absolute_time SET start_time =
Modified: grass/trunk/lib/temporal/str3ds_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/str3ds_metadata_table.sql 2011-09-07 16:20:32 UTC (rev 48186)
+++ grass/trunk/lib/temporal/str3ds_metadata_table.sql 2011-09-07 16:21:32 UTC (rev 48187)
@@ -8,21 +8,21 @@
PRAGMA foreign_keys = ON;
CREATE TABLE str3ds_metadata (
- id VARCHAR NOT NULL, -- Id of the space-time raster3d dataset, this is the primary foreign key
- raster3d_register VARCHAR, -- The id of the table in which the raster3d maps are registered for this dataset
- number_of_registered_maps INTEGER, -- The number of registered raster3d maps
- max_min DOUBLE PRECISION, -- The minimal maximum of the registered raster3d maps
- min_min DOUBLE PRECISION, -- The minimal minimum of the registered raster3d maps
- max_max DOUBLE PRECISION, -- The maximal maximum of the registered raster3d maps
- min_max DOUBLE PRECISION, -- The maximal minimum of the registered raster3d maps
- nsres_min DOUBLE PRECISION, -- The lowest north-south resolution of the registered raster3d maps
- nsres_max DOUBLE PRECISION, -- The highest north-south resolution of the registered raster3d maps
- ewres_min DOUBLE PRECISION, -- The lowest east-west resolution of the registered raster3d maps
- ewres_max DOUBLE PRECISION, -- The highest east-west resolution of the registered raster3d maps
- tbres_min DOUBLE PRECISION, -- The lowest top-bottom resolution of the registered raster3d maps
- tbres_max DOUBLE PRECISION, -- The highest top-bottom resolution of the registered raster3d maps
- title VARCHAR, -- Title of the space-time raster3d dataset
- description VARCHAR, -- Detailed description of the space-time raster3d dataset
+ id VARCHAR NOT NULL, -- Id of the space-time raster3d dataset, this is the primary foreign key
+ raster3d_register VARCHAR, -- The id of the table in which the raster3d maps are registered for this dataset
+ number_of_maps INTEGER, -- The number of registered raster3d maps
+ max_min DOUBLE PRECISION, -- The minimal maximum of the registered raster3d maps
+ min_min DOUBLE PRECISION, -- The minimal minimum of the registered raster3d maps
+ max_max DOUBLE PRECISION, -- The maximal maximum of the registered raster3d maps
+ min_max DOUBLE PRECISION, -- The maximal minimum of the registered raster3d maps
+ nsres_min DOUBLE PRECISION, -- The lowest north-south resolution of the registered raster3d maps
+ nsres_max DOUBLE PRECISION, -- The highest north-south resolution of the registered raster3d maps
+ ewres_min DOUBLE PRECISION, -- The lowest east-west resolution of the registered raster3d maps
+ ewres_max DOUBLE PRECISION, -- The highest east-west resolution of the registered raster3d maps
+ tbres_min DOUBLE PRECISION, -- The lowest top-bottom resolution of the registered raster3d maps
+ tbres_max DOUBLE PRECISION, -- The highest top-bottom resolution of the registered raster3d maps
+ title VARCHAR, -- Title of the space-time raster3d dataset
+ description VARCHAR, -- Detailed description of the space-time raster3d dataset
PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES str3ds_base (id) ON DELETE CASCADE
);
@@ -36,7 +36,7 @@
A2.end_time, A2.granularity,
A3.north, A3.south, A3.east, A3.west,
A4.raster3d_register,
- A4.number_of_registered_maps,
+ A4.number_of_maps,
A4.nsres_min, A4.ewres_min,
A4.nsres_max, A4.ewres_max,
A4.tbres_min, A4.tbres_max,
@@ -55,7 +55,7 @@
A2.interval, A2.granularity,
A3.north, A3.south, A3.east, A3.west,
A4.raster3d_register,
- A4.number_of_registered_maps,
+ A4.number_of_maps,
A4.nsres_min, A4.ewres_min,
A4.nsres_max, A4.ewres_max,
A4.tbres_min, A4.tbres_max,
Modified: grass/trunk/lib/temporal/strds_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/strds_metadata_table.sql 2011-09-07 16:20:32 UTC (rev 48186)
+++ grass/trunk/lib/temporal/strds_metadata_table.sql 2011-09-07 16:21:32 UTC (rev 48187)
@@ -8,19 +8,19 @@
PRAGMA foreign_keys = ON;
CREATE TABLE strds_metadata (
- id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
- raster_register VARCHAR, -- The id of the table in which the raster maps are registered for this dataset
- number_of_registered_maps INTEGER, -- The number of registered raster maps
- max_min DOUBLE PRECISION, -- The minimal maximum of the registered raster maps
- min_min DOUBLE PRECISION, -- The minimal minimum of the registered raster maps
- max_max DOUBLE PRECISION, -- The maximal maximum of the registered raster maps
- min_max DOUBLE PRECISION, -- The maximal minimum of the registered raster maps
- nsres_min DOUBLE PRECISION, -- The lowest north-south resolution of the registered raster maps
- nsres_max DOUBLE PRECISION, -- The highest north-south resolution of the registered raster maps
- ewres_min DOUBLE PRECISION, -- The lowest east-west resolution of the registered raster maps
- ewres_max DOUBLE PRECISION, -- The highest east-west resolution of the registered raster maps
- title VARCHAR, -- Title of the space-time raster dataset
- description VARCHAR, -- Detailed description of the space-time raster dataset
+ id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
+ raster_register VARCHAR, -- The id of the table in which the raster maps are registered for this dataset
+ number_of_maps INTEGER, -- The number of registered raster maps
+ max_min DOUBLE PRECISION, -- The minimal maximum of the registered raster maps
+ min_min DOUBLE PRECISION, -- The minimal minimum of the registered raster maps
+ max_max DOUBLE PRECISION, -- The maximal maximum of the registered raster maps
+ min_max DOUBLE PRECISION, -- The maximal minimum of the registered raster maps
+ nsres_min DOUBLE PRECISION, -- The lowest north-south resolution of the registered raster maps
+ nsres_max DOUBLE PRECISION, -- The highest north-south resolution of the registered raster maps
+ ewres_min DOUBLE PRECISION, -- The lowest east-west resolution of the registered raster maps
+ ewres_max DOUBLE PRECISION, -- The highest east-west resolution of the registered raster maps
+ title VARCHAR, -- Title of the space-time raster dataset
+ description VARCHAR, -- Detailed description of the space-time raster dataset
PRIMARY KEY (id),
FOREIGN KEY (id) REFERENCES strds_base (id) ON DELETE CASCADE
);
@@ -34,7 +34,7 @@
A2.end_time, A2.granularity,
A3.north, A3.south, A3.east, A3.west,
A4.raster_register,
- A4.number_of_registered_maps,
+ A4.number_of_maps,
A4.nsres_min, A4.ewres_min,
A4.nsres_max, A4.ewres_max,
A4.min_min, A4.min_max,
@@ -52,7 +52,7 @@
A2.interval, A2.granularity,
A3.north, A3.south, A3.east, A3.west,
A4.raster_register,
- A4.number_of_registered_maps,
+ A4.number_of_maps,
A4.nsres_min, A4.ewres_min,
A4.nsres_max, A4.ewres_max,
A4.min_min, A4.min_max,
Modified: grass/trunk/lib/temporal/stvds_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/stvds_metadata_table.sql 2011-09-07 16:20:32 UTC (rev 48186)
+++ grass/trunk/lib/temporal/stvds_metadata_table.sql 2011-09-07 16:21:32 UTC (rev 48187)
@@ -10,7 +10,7 @@
CREATE TABLE stvds_metadata (
id VARCHAR NOT NULL, -- Name of the space-time vector dataset, this is the primary foreign key
vector_register VARCHAR, -- The id of the table in which the vector maps are registered for this dataset
- number_of_registered_maps INTEGER, -- The number of registered vector maps
+ number_of_maps INTEGER, -- The number of registered vector maps
title VARCHAR, -- Title of the space-time vector dataset
description VARCHAR, -- Detailed description of the space-time vector dataset
PRIMARY KEY (id),
@@ -26,7 +26,7 @@
A2.end_time, A2.granularity,
A3.north, A3.south, A3.east, A3.west,
A4.vector_register,
- A4.number_of_registered_maps,
+ A4.number_of_maps,
A4.title, A4.description
FROM stvds_base A1, stvds_absolute_time A2,
stvds_spatial_extent A3, stvds_metadata A4 WHERE A1.id = A2.id AND
@@ -40,7 +40,7 @@
A2.interval, A2.granularity,
A3.north, A3.south, A3.east, A3.west,
A4.vector_register,
- A4.number_of_registered_maps,
+ A4.number_of_maps,
A4.title, A4.description
FROM stvds_base A1, stvds_relative_time A2,
stvds_spatial_extent A3, stvds_metadata A4 WHERE A1.id = A2.id AND
Modified: grass/trunk/lib/temporal/test.temporal.py
===================================================================
--- grass/trunk/lib/temporal/test.temporal.py 2011-09-07 16:20:32 UTC (rev 48186)
+++ grass/trunk/lib/temporal/test.temporal.py 2011-09-07 16:21:32 UTC (rev 48187)
@@ -278,7 +278,7 @@
def test_map_metadata():
for i in range(2):
- base = raster_metadata(ident="soil" + str(i) + "@PERMANENT", strds_register="PERMANENT_soil_strds-register", datatype="CELL", \
+ base = raster_metadata(ident="soil" + str(i) + "@PERMANENT", strds_register="PERMANENT_soil_strds_register", datatype="CELL", \
cols=500, rows=400, number_of_cells=200000,nsres=1, ewres=1, min=0, max=33)
base.insert()
base.select()
@@ -290,7 +290,7 @@
base.print_self()
for i in range(2):
- base = raster3d_metadata(ident="soil" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_soil_str3ds-register", datatype="FCELL", \
+ base = raster3d_metadata(ident="soil" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_soil_str3ds_register", datatype="FCELL", \
cols=500, rows=400, depths=20, number_of_cells=200000,nsres=1, ewres=1, tbres=10, min=0, max=33)
base.insert()
base.select()
@@ -311,7 +311,43 @@
base.update()
base.select()
base.print_self()
+
+ for i in range(2):
+ base = strds_metadata(ident="soil" + str(i) + "@PERMANENT", raster_register="PERMANENT_soil_raster_register", \
+ title="Test", description="Test description")
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_title("More tests")
+ base.update()
+ base.select()
+ base.print_self()
+ for i in range(2):
+ base = str3ds_metadata(ident="soil" + str(i) + "@PERMANENT", raster3d_register="PERMANENT_soil_raster3d_register", \
+ title="Test", description="Test description")
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_title("More tests")
+ base.update()
+ base.select()
+ base.print_self()
+
+ for i in range(2):
+ base = stvds_metadata(ident="soil" + str(i) + "@PERMANENT", vector_register="PERMANENT_soil_vector_register", \
+ title="Test", description="Test description")
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_title("More tests")
+ base.update()
+ base.select()
+ base.print_self()
+
def test_base_absolute_time_extent_metadata():
for i in range(10):
@@ -476,6 +512,7 @@
def test_raster_dataset():
+ # Create a test map
grass.raster.mapcalc("test = sin(x()) + cos(y())", overwrite = True)
name = "test"
@@ -483,54 +520,64 @@
print "Create a raster object"
+ # We need to specify the name and the mapset as identifier
rds = raster_dataset(name + "@" + mapset)
+ # Load data from the raster map in the mapset
rds.load()
print "Is in db: ", rds.is_in_db()
- rds.base.set_ttype("absolue")
- rds.absolute_time.set_start_time(datetime(year=2000, month=1, day=1))
- rds.absolute_time.set_end_time(datetime(year=2010, month=1, day=1))
+ if rds.is_in_db():
+ # Remove the entry if it is in the db
+ rds.delete()
- # Remove the entry if it is in the db
- rds.delete()
-
+ # Set the absolute valid time
+ rds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
+ end_time= datetime(year=2010, month=1, day=1))
+ # Insert the map data into the SQL database
rds.insert()
+ # Print self info
rds.print_self()
-
+ # The temporal relation must be equal
print rds.temporal_relation(rds)
def test_raster3d_dataset():
+ # Create a test map
grass.raster3d.mapcalc3d("test = sin(x()) + cos(y()) + sin(z())", overwrite = True)
name = "test"
mapset = grass.gisenv()["MAPSET"]
- print "Create a raster3d object"
+ print "Create a raster object"
+ # We need to specify the name and the mapset as identifier
r3ds = raster3d_dataset(name + "@" + mapset)
+ # Load data from the raster map in the mapset
r3ds.load()
print "Is in db: ", r3ds.is_in_db()
- r3ds.print_self()
- r3ds.base.set_ttype("absolue")
- r3ds.absolute_time.set_start_time(datetime(year=2000, month=1, day=1))
- r3ds.absolute_time.set_end_time(datetime(year=2010, month=1, day=1))
+ if r3ds.is_in_db():
+ # Remove the entry if it is in the db
+ r3ds.delete()
- # Remove the entry if it is in the db
- r3ds.delete()
-
+ # Set the absolute valid time
+ r3ds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
+ end_time= datetime(year=2010, month=1, day=1))
+
+ # Insert the map data into the SQL database
r3ds.insert()
+ # Print self info
r3ds.print_self()
-
+ # The temporal relation must be equal
print r3ds.temporal_relation(r3ds)
def test_vector_dataset():
+ # Create a test map
grass.run_command("v.random", output="test", n=20, column="height", zmin=0, \
zmax=100, flags="z", overwrite = True)
@@ -539,34 +586,103 @@
print "Create a vector object"
+ # We need to specify the name and the mapset as identifier
vds = vector_dataset(name + "@" + mapset)
+ # Load data from the raster map in the mapset
vds.load()
print "Is in db: ", vds.is_in_db()
- vds.print_self()
- vds.base.set_ttype("absolue")
- vds.absolute_time.set_start_time(datetime(year=2000, month=1, day=1))
- vds.absolute_time.set_end_time(datetime(year=2010, month=1, day=1))
+ if vds.is_in_db():
+ # Remove the entry if it is in the db
+ vds.delete()
- # Remove the entry if it is in the db
- vds.delete()
-
+ # Set the absolute valid time
+ vds.set_absolute_time(start_time= datetime(year=2000, month=1, day=1), \
+ end_time= datetime(year=2010, month=1, day=1))
+ # Insert the map data into the SQL database
vds.insert()
+ # Print self info
vds.print_self()
-
+ # The temporal relation must be equal
print vds.temporal_relation(vds)
+
+def test_strds_dataset():
+
+ name = "strds_test_1"
+ mapset = grass.gisenv()["MAPSET"]
+
+ print "Create a strds object"
+
+ # We need to specify the name and the mapset as identifier
+ strds = space_time_raster_dataset(ident = name + "@" + mapset)
+ # Check if in db
+ print "Is strds in db: ", strds.is_in_db()
+ # Create a new entry if not in db
+ if strds.is_in_db() == False:
+ strds.set_initial_values(temporal_type = "absolute", granularity="1 day",\
+ semantic_type="event", title="This is a test space time raster dataset", description="A space time raster dataset for testing")
+ strds.insert()
+
+ # Reread the data from the db
+ strds.select()
+ # Print self info
+ strds.print_self()
+
+ # Create a test maps
+ for i in range(11):
+ i = i + 1
+ grass.raster.mapcalc("test" + str(i) + " = sin(x()) + cos(y())", overwrite = True)
+
+ name = "test" + str(i)
+ mapset = grass.gisenv()["MAPSET"]
+ ident = name + "@" + mapset
+
+ print "Create a raster object"
+
+ # We need to specify the name and the mapset as identifier
+ rds = raster_dataset(ident)
+
+ # Load data from the raster map in the mapset
+ rds.load()
+
+ print "Is raster in db: ", rds.is_in_db()
+
+ if rds.is_in_db():
+ rds.select()
+ rds.print_self()
+ # Remove the entry if it is in the db
+ rds.delete()
+ rds.reset(ident)
+ rds.load()
+
+ # Set the absolute valid time
+ rds.set_absolute_time(start_time= datetime(year=2000, month=i, day=1), \
+ end_time= datetime(year=2000, month=i + 1, day=1))
+ # Insert the map data into the SQL database
+ rds.insert()
+ # Register the map in the space time raster dataset
+ strds.register_map(rds)
+ # Print self info
+ rds.print_self()
+
+ strds.select()
+ # Print self info
+ strds.print_self()
+
#test_dict_sql_serializer()
create_temporal_database()
-test_dataset_identifer()
-test_absolute_timestamp()
-test_relative_timestamp()
-test_spatial_extent()
+#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()
-#test_vector_dataset()
\ No newline at end of file
+#test_vector_dataset()
+
+test_strds_dataset()
\ No newline at end of file
More information about the grass-commit
mailing list