[GRASS-SVN] r48173 - in grass/trunk/lib: python temporal
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 6 15:01:01 EDT 2011
Author: huhabla
Date: 2011-09-06 12:01:01 -0700 (Tue, 06 Sep 2011)
New Revision: 48173
Added:
grass/trunk/lib/temporal/Makefile
Modified:
grass/trunk/lib/python/raster3d.py
grass/trunk/lib/python/temporal.py
grass/trunk/lib/python/vector.py
grass/trunk/lib/temporal/raster3d_metadata_table.sql
grass/trunk/lib/temporal/stds_tables_template.sql
grass/trunk/lib/temporal/test.temporal.py
Log:
Makefile to store sql scripts. Basic structures for spatio-temporal datasets implemented. Vector info implemented in python grass library.
Modified: grass/trunk/lib/python/raster3d.py
===================================================================
--- grass/trunk/lib/python/raster3d.py 2011-09-06 16:35:21 UTC (rev 48172)
+++ grass/trunk/lib/python/raster3d.py 2011-09-06 19:01:01 UTC (rev 48173)
@@ -33,7 +33,7 @@
# run "r3.info -rstgip ..." and parse output
def raster3d_info(map):
- """!Return information about a raster map (interface to
+ """!Return information about a raster3d map (interface to
`r3.info'). Example:
\code
Modified: grass/trunk/lib/python/temporal.py
===================================================================
--- grass/trunk/lib/python/temporal.py 2011-09-06 16:35:21 UTC (rev 48172)
+++ grass/trunk/lib/python/temporal.py 2011-09-06 19:01:01 UTC (rev 48173)
@@ -9,6 +9,7 @@
@code
from grass.script import temporal as grass
+grass.create_temporal_database()
...
@endcode
@@ -19,32 +20,36 @@
@author Soeren Gebbert
"""
-
+import os
import sqlite3
import os
from datetime import datetime, date, time
+import getpass
import core
import raster
+import vector
import raster3d
-import getpass
def get_grass_location_db_path():
grassenv = core.gisenv()
dbpath = os.path.join(grassenv["GISDBASE"], grassenv["LOCATION_NAME"])
- print os.path.join(dbpath, "grass.db")
return os.path.join(dbpath, "grass.db")
def get_sql_template_path():
- return "./"
+ base = os.getenv("GISBASE")
+ base_etc = os.path.join(base, "etc")
+ return os.path.join(base_etc, "sql")
###############################################################################
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"""
+
+ database = get_grass_location_db_path()
# Check if it already exists
- if os.path.exists(get_grass_location_db_path()):
+ if os.path.exists(database):
return False
# Read all SQL scripts and templates
@@ -82,7 +87,7 @@
sqlite3.complete_statement(str3ds_metadata_sql)
# Connect to database
- connection = sqlite3.connect(get_grass_location_db_path())
+ connection = sqlite3.connect(database)
cursor = connection.cursor()
# Execute the SQL statements
@@ -212,12 +217,15 @@
class sql_database_interface(dict_sql_serializer):
"""This is the sql database interface to sqlite3"""
- def __init__(self, table=None, ident=None):
+ def __init__(self, table=None, ident=None, database=None):
dict_sql_serializer.__init__(self)
self.table = table # Name of the table, set in the subclass
- self.database = get_grass_location_db_path()
+ if database == None:
+ self.database = get_grass_location_db_path()
+ else:
+ self.database = database
self.ident = ident
def connect(self):
@@ -454,6 +462,48 @@
###############################################################################
+class stds_base(dataset_identifer):
+ def __init__(self, table=None, ident=None, name=None, mapset=None, semantic_type=None, creator=None, creation_time=None,\
+ modification_time=None, temporal_type=None, revision=1):
+ dataset_identifer.__init__(self, table, ident, name, mapset, creator, creation_time,\
+ modification_time, temporal_type, revision)
+
+ self.set_semantic_type(semantic_type)
+
+ def set_semantic_type(self, semantic_type):
+ """Set the sematnic type of the space time dataset"""
+ self.D["semantic_type"] = semantic_type
+
+ def get_semantic_type(self):
+ """Get the semantic_type of the space time dataset
+ @return None if not found"""
+ if self.D.has_key("semantic_type"):
+ return self.D["semantic_type"]
+ else:
+ return None
+
+###############################################################################
+
+class strds_base(stds_base):
+ def __init__(self, ident=None, name=None, mapset=None,semantic_type=None, creator=None, creation_time=None,\
+ modification_time=None, temporal_type=None, revision=1):
+ stds_base.__init__(self, "strds_base", ident, name, mapset, semantic_type, creator, creation_time,\
+ modification_time, temporal_type, revision)
+
+class str3ds_base(stds_base):
+ def __init__(self, ident=None, name=None, mapset=None,semantic_type=None, creator=None, creation_time=None,\
+ modification_time=None, temporal_type=None, revision=1):
+ stds_base.__init__(self, "str3ds_base", ident, name, mapset, semantic_type, creator, creation_time,\
+ modification_time, temporal_type, revision)
+
+class stvds_base(stds_base):
+ def __init__(self, ident=None, name=None, mapset=None, semantic_type=None, creator=None, creation_time=None,\
+ modification_time=None, temporal_type=None, revision=1):
+ stds_base.__init__(self, "stvds_base", ident, name, mapset, semantic_type, creator, creation_time,\
+ modification_time, temporal_type, revision)
+
+###############################################################################
+
class absolute_timestamp(sql_database_interface):
"""This is the absolute time base class for all maps and spacetime datasets"""
def __init__(self, table=None, ident=None, start_time=None, end_time=None, timezone=None):
@@ -709,6 +759,40 @@
###############################################################################
+class stds_absolute_time(absolute_timestamp):
+ def __init__(self, table=None, ident=None, start_time=None, end_time=None, granularity=None, timezone=None):
+ absolute_timestamp.__init__(self, table, ident, start_time, end_time, timezone)
+
+ self.set_granularity(granularity)
+
+ def set_granularity(self, granularity):
+ """Set the granularity of the space time dataset"""
+ self.D["granularity"] = granularity
+
+ def get_granularity(self):
+ """Get the granularity of the space time dataset
+ @return None if not found"""
+ if self.D.has_key("granularity"):
+ return self.D["granularity"]
+ else:
+ return None
+
+###############################################################################
+
+class strds_absolute_time(stds_absolute_time):
+ def __init__(self, ident=None, start_time=None, end_time=None, granularity=None, timezone=None):
+ stds_absolute_time.__init__(self, "strds_absolute_time", ident, start_time, end_time, granularity, timezone)
+
+class str3ds_absolute_time(stds_absolute_time):
+ def __init__(self, ident=None, start_time=None, end_time=None, granularity=None, timezone=None):
+ stds_absolute_time.__init__(self, "str3ds_absolute_time", ident, start_time, end_time, granularity, timezone)
+
+class stvds_absolute_time(stds_absolute_time):
+ def __init__(self, ident=None, start_time=None, end_time=None, granularity=None, timezone=None):
+ stds_absolute_time.__init__(self, "stvds_absolute_time", ident, start_time, end_time, granularity, timezone)
+
+###############################################################################
+
class relative_timestamp(sql_database_interface):
"""This is the relative time base class for all maps and spacetime datasets"""
def __init__(self, table=None, ident=None, interval=None):
@@ -799,9 +883,43 @@
class vector_relative_time(relative_timestamp):
def __init__(self, ident=None, interval=None):
relative_timestamp.__init__(self, "vector_relative_time", ident, interval)
+
+###############################################################################
+class stds_relative_time(relative_timestamp):
+ def __init__(self, table=None, ident=None, interval=None, granularity=None):
+ relative_timestamp.__init__(self, table, ident, interval)
+
+ self.set_granularity(granularity)
+
+ def set_granularity(self, granularity):
+ """Set the granularity of the space time dataset"""
+ self.D["granularity"] = granularity
+
+ def get_granularity(self):
+ """Get the granularity of the space time dataset
+ @return None if not found"""
+ if self.D.has_key("granularity"):
+ return self.D["granularity"]
+ else:
+ return None
+
###############################################################################
+class strds_relative_time(stds_relative_time):
+ def __init__(self, ident=None, interval=None, granularity=None):
+ stds_relative_time.__init__(self, "strds_relative_time", ident, interval, granularity)
+
+class str3ds_relative_time(stds_relative_time):
+ def __init__(self, ident=None, interval=None, granularity=None):
+ stds_relative_time.__init__(self, "str3ds_relative_time", ident, interval, granularity)
+
+class stvds_relative_time(stds_relative_time):
+ def __init__(self, ident=None, interval=None, granularity=None):
+ stds_relative_time.__init__(self, "stvds_relative_time", ident, interval, granularity)
+
+###############################################################################
+
class spatial_extent(sql_database_interface):
"""This is the spatial extent base class for all maps and spacetime datasets"""
def __init__(self, table=None, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
@@ -914,17 +1032,29 @@
###############################################################################
class raster_spatial_extent(spatial_extent):
- def __init__(self, ident=None, interval=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
+ def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
spatial_extent.__init__(self, "raster_spatial_extent", ident, north, south, east, west, top, bottom)
class raster3d_spatial_extent(spatial_extent):
- def __init__(self, ident=None, interval=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
+ def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
spatial_extent.__init__(self, "raster3d_spatial_extent", ident, north, south, east, west, top, bottom)
class vector_spatial_extent(spatial_extent):
- def __init__(self, ident=None, interval=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
+ def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
spatial_extent.__init__(self, "vector_spatial_extent", ident, north, south, east, west, top, bottom)
+class strds_spatial_extent(spatial_extent):
+ def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
+ spatial_extent.__init__(self, "strds_spatial_extent", ident, north, south, east, west, top, bottom)
+
+class str3ds_spatial_extent(spatial_extent):
+ def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
+ spatial_extent.__init__(self, "str3ds_spatial_extent", ident, north, south, east, west, top, bottom)
+
+class stvds_spatial_extent(spatial_extent):
+ def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
+ spatial_extent.__init__(self, "stvds_spatial_extent", ident, north, south, east, west, top, bottom)
+
###############################################################################
class raster_metadata_base(sql_database_interface):
@@ -1218,9 +1348,6 @@
self.relative_time.print_self()
self.spatial_extent.print_self()
self.metadata.print_self()
-
- def load_from_file(self):
- raise IOError("This method must be implemented in the subclasses")
def is_time_absolute(self):
if self.base.D.has_key("temporal_type"):
@@ -1258,7 +1385,8 @@
self.spatial_extent = raster_spatial_extent(ident=ident)
self.metadata = raster_metadata(ident=ident)
- def load_from_file(self):
+ def load(self):
+ """Load all info from an existing raster map into the internal structure"""
# Get the data from an existing raster map
kvp = raster.raster_info(self.ident)
@@ -1294,7 +1422,6 @@
self.metadata.set_cols(cols)
self.metadata.set_rows(rows)
self.metadata.set_number_of_cells(ncells)
-
###############################################################################
@@ -1312,7 +1439,8 @@
self.spatial_extent = raster3d_spatial_extent(ident=ident)
self.metadata = raster3d_metadata(ident=ident)
- def load_from_file(self):
+ def load(self):
+ """Load all info from an existing raster3d map into the internal structure"""
# Get the data from an existing raster map
kvp = raster3d.raster3d_info(self.ident)
@@ -1336,7 +1464,7 @@
self.metadata.set_nsres(kvp["nsres"])
self.metadata.set_ewres(kvp["ewres"])
- self.metadata.set_ewres(kvp["tbres"])
+ self.metadata.set_tbres(kvp["tbres"])
self.metadata.set_datatype(kvp["datatype"])
self.metadata.set_min(kvp["min"])
self.metadata.set_max(kvp["max"])
@@ -1352,3 +1480,43 @@
self.metadata.set_depths(rows)
self.metadata.set_number_of_cells(ncells)
+
+###############################################################################
+
+class vector_dataset(abstract_dataset):
+ def __init__(self, ident):
+ self.reset(ident)
+
+ def reset(self, ident):
+ """Reset the internal structure and set the identifier"""
+ self.ident = ident
+
+ self.base = vector_base(ident=ident)
+ self.absolute_time = vector_absolute_time(ident=ident)
+ self.relative_time = vector_relative_time(ident=ident)
+ self.spatial_extent = vector_spatial_extent(ident=ident)
+ self.metadata = vector_metadata(ident=ident)
+
+ def load(self):
+ """Load all info from an existing vector map into the internal structure"""
+
+ # Get the data from an existing raster map
+ kvp = vector.vector_info(self.ident)
+
+ # Fill base information
+
+ self.base.set_name(self.ident.split("@")[0])
+ self.base.set_mapset(self.ident.split("@")[1])
+ self.base.set_creator(str(getpass.getuser()))
+
+ # Fill spatial extent
+
+ self.spatial_extent.set_north(kvp["north"])
+ self.spatial_extent.set_south(kvp["south"])
+ self.spatial_extent.set_west(kvp["west"])
+ self.spatial_extent.set_east(kvp["east"])
+ self.spatial_extent.set_top(kvp["top"])
+ self.spatial_extent.set_bottom(kvp["bottom"])
+
+ # Fill metadata .. no metadata yet
+
Modified: grass/trunk/lib/python/vector.py
===================================================================
--- grass/trunk/lib/python/vector.py 2011-09-06 16:35:21 UTC (rev 48172)
+++ grass/trunk/lib/python/vector.py 2011-09-06 19:01:01 UTC (rev 48173)
@@ -163,6 +163,48 @@
return ret
+
+# run "v.info -get ..." and parse output
+
+def vector_info(map):
+ """!Return information about a vector map (interface to
+ `v.info'). Example:
+
+ \code
+ >>> grass.vector_info('random_points')
+ {'comment': '', 'projection': 'x,y', 'creator': 'soeren', 'holes': 0,
+ 'primitives': 20, 'kernels': 0, 'scale': '1:1', 'title': '',
+ 'west': 0.046125489999999998, 'top': 2376.133159, 'boundaries': 0,
+ 'location': 'XYLocation', 'nodes': 0, 'east': 0.97305646000000001,
+ 'source_date': 'Mon Aug 29 10:55:57 2011', 'north': 0.9589993,
+ 'format': 'native', 'faces': 0, 'centroids': 0,
+ 'digitization_threshold': '0.000000', 'islands': 0, 'level': 2,
+ 'mapset': 'test', 'areas': 0, 'name': 'random_points',
+ 'database': '/home/soeren/grassdata', 'bottom': 22.186596999999999,
+ 'lines': 0, 'points': 20, 'map3d': True, 'volumes': 0, 'num_dblinks': 0,
+ 'organization': '', 'south': 0.066047099999999997}
+
+ \endcode
+ @param map map name
+
+ @return parsed vector info
+ """
+
+ s = read_command('v.info', flags = 'get', map = map)
+
+ kv = parse_key_val(s)
+ for k in ['north', 'south', 'east', 'west', 'top', 'bottom']:
+ kv[k] = float(kv[k])
+ for k in ['level', 'num_dblinks']:
+ kv[k] = int(kv[k])
+ for k in ['nodes', 'points', 'lines', 'boundaries', 'centroids', 'areas', 'islands', \
+ 'faces', 'kernels', 'volumes', 'holes', 'primitives']:
+ kv[k] = int(kv[k])
+ if 'map3d' in kv:
+ kv['map3d'] = bool(kv['map3d'])
+ return kv
+
+
# interface for v.db.select
def vector_db_select(map, layer = 1, **kwargs):
Added: grass/trunk/lib/temporal/Makefile
===================================================================
--- grass/trunk/lib/temporal/Makefile (rev 0)
+++ grass/trunk/lib/temporal/Makefile 2011-09-06 19:01:01 UTC (rev 48173)
@@ -0,0 +1,15 @@
+MODULE_TOPDIR = ../..
+
+include $(MODULE_TOPDIR)/include/Make/Other.make
+
+SQLDIR = $(ETC)/sql
+
+SQLFILES:= $(wildcard *.sql)
+
+default: copy_sql_files
+
+copy_sql_files: $(SQLDIR)
+ for i in $(SQLFILES); do $(INSTALL_DATA) $$i $(SQLDIR)/; done
+
+$(SQLDIR):
+ $(MKDIR) $@
\ No newline at end of file
Modified: grass/trunk/lib/temporal/raster3d_metadata_table.sql
===================================================================
--- grass/trunk/lib/temporal/raster3d_metadata_table.sql 2011-09-06 16:35:21 UTC (rev 48172)
+++ grass/trunk/lib/temporal/raster3d_metadata_table.sql 2011-09-06 19:01:01 UTC (rev 48173)
@@ -13,7 +13,7 @@
CREATE TABLE raster3d_metadata (
id VARCHAR NOT NULL, -- The id (PFK) is the unique identifier for all tables, it is based on name and mapset (name at mapset) and is used as primary foreign key
str3ds_register VARCHAR, -- The name of the table storing all space-time raster3d datasets in which this map is registered
- maptype VARCHAR NOT NULL,
+ datatype VARCHAR NOT NULL,
cols INTEGER NOT NULL,
rows INTEGER NOT NULL,
depths INTEGER NOT NULL,
@@ -36,7 +36,7 @@
A1.revision, A1.creator,
A2.start_time, A2.end_time,
A3.north, A3.south, A3.east, A3.west,
- A4.maptype, A4.cols, A4.rows, A4.depths,
+ A4.datatype, A4.cols, A4.rows, A4.depths,
A4.nsres, A4.ewres, A4.tbres,
A4.min, A4.max,
A4.str3ds_register,
@@ -52,7 +52,7 @@
A1.revision, A1.creator,
A2.interval,
A3.north, A3.south, A3.east, A3.west,
- A4.maptype, A4.cols, A4.rows, A4.depths,
+ A4.datatype, A4.cols, A4.rows, A4.depths,
A4.nsres, A4.ewres, A4.tbres,
A4.min, A4.max,
A4.str3ds_register,
Modified: grass/trunk/lib/temporal/stds_tables_template.sql
===================================================================
--- grass/trunk/lib/temporal/stds_tables_template.sql 2011-09-06 16:35:21 UTC (rev 48172)
+++ grass/trunk/lib/temporal/stds_tables_template.sql 2011-09-06 19:01:01 UTC (rev 48173)
@@ -16,8 +16,8 @@
creator VARCHAR NOT NULL, -- Name of the creator
temporal_type VARCHAR NOT NULL, -- The temporal type of the dataset "absolute" or "relative"
semantic_type VARCHAR NOT NULL, -- The semantic data description used for aggregation/decomposition algorithm selection
- creation_time TIMESTAMP NOT NULL, -- The time of creation of the space-time dataset
- modification_time TIMESTAMP NOT NULL, -- The time of the last modification of the space-time dataset
+ creation_time TIMESTAMP NOT NULL, -- The time of creation of the space-time dataset
+ modification_time TIMESTAMP NOT NULL,-- The time of the last modification of the space-time dataset
revision SMALLINT NOT NULL, -- The revision number
PRIMARY KEY (id)
);
@@ -32,8 +32,8 @@
CREATE TABLE STDS_absolute_time (
id VARCHAR NOT NULL, -- Id of the space-time dataset, this is the primary foreign key
- start_time TIMESTAMP, -- Start of the valid time, can be NULL if no map is registered
- end_time TIMESTAMP, -- End of the valid time, can be NULL if no map is registered
+ start_time TIMESTAMP, -- Start of the valid time, can be NULL if no map is registered
+ end_time TIMESTAMP, -- End of the valid time, can be NULL if no map is registered
granularity VARCHAR, -- The granularity "NNN seconds, NNN minutes, NNN hours, NNN days, NNN weeks, NNN months, NNN years"
timezone SMALLINT, -- The time zone number
PRIMARY KEY (id),
Modified: grass/trunk/lib/temporal/test.temporal.py
===================================================================
--- grass/trunk/lib/temporal/test.temporal.py 2011-09-06 16:35:21 UTC (rev 48172)
+++ grass/trunk/lib/temporal/test.temporal.py 2011-09-06 19:01:01 UTC (rev 48173)
@@ -1,5 +1,6 @@
-from temporal import *
import os
+from grass.script.temporal import *
+import grass.script as grass
###############################################################################
@@ -20,7 +21,7 @@
base.print_self()
for i in range(2):
- base = raster3d_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", creator="soeren")
+ base = raster3d_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", creator="soeren")
base.insert()
base.select()
base.print_self()
@@ -31,7 +32,7 @@
base.print_self()
for i in range(2):
- base = vector_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", creator="soeren")
+ base = vector_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", creator="soeren")
base.insert()
base.select()
base.print_self()
@@ -41,6 +42,39 @@
base.select()
base.print_self()
+ for i in range(2):
+ base = strds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", creator="soeren", semantic_type="event", temporal_type="absolute", revision=1)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_creator("rene")
+ base.update()
+ base.select()
+ base.print_self()
+
+ for i in range(2):
+ base = str3ds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", semantic_type="event", creator="soeren")
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_creator("rene")
+ base.update()
+ base.select()
+ base.print_self()
+
+ for i in range(2):
+ base = stvds_base(ident="soil" + str(i) + "@PERMANENT", name="soil" + str(i), mapset="PERMANENT", temporal_type="absolute", semantic_type="event", creator="soeren")
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_creator("rene")
+ base.update()
+ base.select()
+ base.print_self()
+
def test_absolute_timestamp():
for i in range(2):
base = raster_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), timezone=1)
@@ -74,7 +108,40 @@
base.update()
base.select()
base.print_self()
+
+ for i in range(2):
+ base = strds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_start_time(datetime(2010,01,01))
+ base.update()
+ base.select()
+ base.print_self()
+ for i in range(2):
+ base = str3ds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_start_time(datetime(2010,01,01))
+ base.update()
+ base.select()
+ base.print_self()
+
+ for i in range(2):
+ base = stvds_absolute_time(ident="soil" + str(i) + "@PERMANENT", start_time=datetime(2011,01,01), end_time=datetime(2011,07,01), granularity="1 day", timezone=1)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_start_time(datetime(2010,01,01))
+ base.update()
+ base.select()
+ base.print_self()
+
def test_spatial_extent():
for i in range(2):
base = raster_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
@@ -108,7 +175,40 @@
base.update()
base.select()
base.print_self()
+
+ for i in range(2):
+ base = strds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_north(120+i)
+ base.update()
+ base.select()
+ base.print_self()
+ for i in range(2):
+ base = str3ds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_north(120+i)
+ base.update()
+ base.select()
+ base.print_self()
+
+ for i in range(2):
+ base = stvds_spatial_extent(ident="soil" + str(i) + "@PERMANENT", north=100 + i, south=10+i, east=50+i, west=20+i, top=i, bottom=0)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_north(120+i)
+ base.update()
+ base.select()
+ base.print_self()
+
def test_relative_timestamp():
for i in range(2):
base = raster_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i)
@@ -142,28 +242,61 @@
base.update()
base.select()
base.print_self()
+
+ for i in range(2):
+ base = strds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_interval(i+1)
+ base.update()
+ base.select()
+ base.print_self()
+ for i in range(2):
+ base = str3ds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_interval(i+1)
+ base.update()
+ base.select()
+ base.print_self()
+
+ for i in range(2):
+ base = stvds_relative_time(ident="soil" + str(i) + "@PERMANENT", interval=i, granularity=5.5)
+ base.insert()
+ base.select()
+ base.print_self()
+ base.clear()
+ base.set_interval(i+1)
+ base.update()
+ base.select()
+ base.print_self()
+
def test_map_metadata():
for i in range(2):
- base = raster_metadata(ident="soil" + str(i) + "@PERMANENT", strds_register="PERMANENT_soil_strds-register", maptype="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()
base.print_self()
base.clear()
- base.set_maptype("FCELL")
+ base.set_datatype("FCELL")
base.update()
base.select()
base.print_self()
for i in range(2):
- base = raster3d_metadata(ident="soil" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_soil_str3ds-register", maptype="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()
base.print_self()
base.clear()
- base.set_maptype("DCELL")
+ base.set_datatype("DCELL")
base.update()
base.select()
base.print_self()
@@ -244,10 +377,10 @@
for i in range(10):
base = vector_metadata(ident="water" + str(i) + "@PERMANENT", stvds_register="PERMANENT_water_stvds_register")
base.insert()
- base = raster_metadata(ident="water" + str(i) + "@PERMANENT", strds_register="PERMANENT_water_strds-register", maptype="CELL", \
+ base = raster_metadata(ident="water" + str(i) + "@PERMANENT", strds_register="PERMANENT_water_strds-register", datatype="CELL", \
cols=500, rows=400, number_of_cells=200000,nsres=1, ewres=1, min=0, max=33)
base.insert()
- base = raster3d_metadata(ident="water" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_water_str3ds-register", maptype="FCELL", \
+ base = raster3d_metadata(ident="water" + str(i) + "@PERMANENT", str3ds_register="PERMANENT_water_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()
@@ -256,10 +389,10 @@
base.set_stvds_register("PERMANENT_water_stvds_register")
base.update()
base = raster_metadata(ident="water" + str(i) + "@PERMANENT")
- base.set_maptype("DCELL")
+ base.set_datatype("DCELL")
base.update()
base = raster3d_metadata(ident="water" + str(i) + "@PERMANENT")
- base.set_maptype("DCELL")
+ base.set_datatype("DCELL")
base.update()
for i in range(10):
@@ -342,33 +475,98 @@
def test_raster_dataset():
+
+ grass.raster.mapcalc("test = sin(x()) + cos(y())", overwrite = True)
+
+ name = "test"
+ mapset = grass.gisenv()["MAPSET"]
+
print "Create a raster object"
- rds = raster_dataset("a at test")
+ rds = raster_dataset(name + "@" + mapset)
- rds.load_from_file()
+ rds.load()
- print "Is in db: ", rds.base.is_in_db()
+ 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))
# Remove the entry if it is in the db
- rds.base.delete()
+ rds.delete()
rds.insert()
rds.print_self()
print rds.temporal_relation(rds)
+def test_raster3d_dataset():
+
+ grass.raster3d.mapcalc3d("test = sin(x()) + cos(y()) + sin(z())", overwrite = True)
+
+ name = "test"
+ mapset = grass.gisenv()["MAPSET"]
+
+ print "Create a raster3d object"
+
+ r3ds = raster3d_dataset(name + "@" + 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))
+
+ # Remove the entry if it is in the db
+ r3ds.delete()
+
+ r3ds.insert()
+ r3ds.print_self()
+
+ print r3ds.temporal_relation(r3ds)
+
+def test_vector_dataset():
+
+ grass.run_command("v.random", output="test", n=20, column="height", zmin=0, \
+ zmax=100, flags="z", overwrite = True)
+
+ name = "test"
+ mapset = grass.gisenv()["MAPSET"]
+
+ print "Create a vector object"
+
+ vds = vector_dataset(name + "@" + 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))
+
+ # Remove the entry if it is in the db
+ vds.delete()
+
+ vds.insert()
+ vds.print_self()
+
+ print vds.temporal_relation(vds)
+
#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()
\ No newline at end of file
+#test_raster_dataset()
+#test_raster3d_dataset()
+#test_vector_dataset()
\ No newline at end of file
More information about the grass-commit
mailing list