[GRASS-SVN] r57379 - in grass/trunk: lib/python/temporal temporal/t.rast.neighbors temporal/t.unregister
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Aug 2 12:29:58 PDT 2013
Author: huhabla
Date: 2013-08-02 12:29:58 -0700 (Fri, 02 Aug 2013)
New Revision: 57379
Modified:
grass/trunk/lib/python/temporal/abstract_dataset.py
grass/trunk/lib/python/temporal/abstract_map_dataset.py
grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
grass/trunk/lib/python/temporal/space_time_datasets.py
grass/trunk/lib/python/temporal/spatial_extent.py
grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
grass/trunk/temporal/t.unregister/t.unregister.py
Log:
Implementing spatial buffering and direct extent object exchange for map objects. Removed spaces.
Modified: grass/trunk/lib/python/temporal/abstract_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_dataset.py 2013-08-02 17:11:11 UTC (rev 57378)
+++ grass/trunk/lib/python/temporal/abstract_dataset.py 2013-08-02 19:29:58 UTC (rev 57379)
@@ -39,30 +39,30 @@
self.msg = msg
def __str__(self):
return repr(self.msg)
-
+
###############################################################################
class AbstractDataset(SpatialTopologyDatasetConnector, TemporalTopologyDatasetConnector):
- """!This is the base class for all datasets
+ """!This is the base class for all datasets
(raster, vector, raster3d, strds, stvds, str3ds)"""
-
+
__metaclass__ = ABCMeta
-
+
def __init__(self):
SpatialTopologyDatasetConnector.__init__(self)
TemporalTopologyDatasetConnector.__init__(self)
-
+
def reset_topology(self):
"""!Reset any information about temporal topology"""
self.reset_spatial_topology()
self.reset_temporal_topology()
-
- def get_number_of_relations(self):
+
+ def get_number_of_relations(self):
"""! Return a dictionary in which the keys are the relation names and the value
are the number of relations.
-
+
The following relations are available:
-
+
Spatial relations
- equivalent
- overlap
@@ -71,7 +71,7 @@
- meet
- cover
- covered
-
+
Temporal relations
- equal
- follows
@@ -84,10 +84,10 @@
- started
- finishes
- finished
-
+
To access topological information the spatial, temporal or booth topologies must be build first
using the SpatioTemporalTopologyBuilder.
-
+
@return the dictionary with relations as keys and number as values or None in case the topology wasn't build
"""
if self.is_temporal_topology_build() and not self.is_spatial_topology_build():
@@ -97,15 +97,15 @@
else:
return self.get_number_of_temporal_relations() + \
self.get_number_of_spatial_relations()
-
+
return None
def set_topology_build_true(self):
"""!Use this method when the spatio-temporal topology was build"""
self.set_spatial_topology_build_true()
self.set_temporal_topology_build_true()
-
+
def set_topology_build_false(self):
"""!Use this method when the spatio-temporal topology was not build"""
self.set_spatial_topology_build_false()
@@ -113,53 +113,53 @@
def is_topology_build(self):
"""!Check if the spatial and temporal topology was build
-
+
@return A dictionary with "spatial" and "temporal" as keys that have boolen values
"""
d = {}
d["spatial"] = self.is_spatial_topology_build()
d["temporal"] = self.is_temporal_topology_build()
-
+
return d
-
+
def print_topology_info(self):
if self.is_temporal_topology_build():
self.print_temporal_topology_info()
if self.is_spatial_topology_build():
self.print_spatial_topology_info()
-
+
def print_topology_shell_info(self):
if self.is_temporal_topology_build():
self.print_temporal_topology_shell_info()
if self.is_spatial_topology_build():
self.print_spatial_topology_shell_info()
-
+
@abstractmethod
def reset(self, ident):
"""!Reset the internal structure and set the identifier
-
+
This method creates the dataset specific internal objects
that store the base information, the spatial and temporal extent
and the metadata. It must be implemented in the dataset
- specific subclasses. This is the code for the
+ specific subclasses. This is the code for the
vector dataset:
-
+
self.base = VectorBase(ident=ident)
self.absolute_time = VectorAbsoluteTime(ident=ident)
self.relative_time = VectorRelativeTime(ident=ident)
self.spatial_extent = VectorSpatialExtent(ident=ident)
self.metadata = VectorMetadata(ident=ident)
-
+
@param ident The identifier of the dataset that "name at mapset" or in case of vector maps "name:layer at mapset"
"""
@abstractmethod
def get_type(self):
"""!Return the type of this class as string
-
- The type can be "vect", "rast", "rast3d", "stvds", "strds" or "str3ds"
-
+
+ The type can be "vect", "rast", "rast3d", "stvds", "strds" or "str3ds"
+
@return "vect", "rast", "rast3d", "stvds", "strds" or "str3ds"
"""
@@ -174,41 +174,41 @@
@abstractmethod
def spatial_overlapping(self, dataset):
"""!Return True if the spatial extents overlap
-
+
@param dataset The abstract dataset to check spatial overlapping
@return True if self and the provided dataset spatial overlap
"""
@abstractmethod
def spatial_intersection(self, dataset):
- """!Return the spatial intersection as spatial_extent
+ """!Return the spatial intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param dataset The abstract dataset to intersect with
@return The intersection spatial extent
"""
@abstractmethod
def spatial_union(self, dataset):
- """!Return the spatial union as spatial_extent
+ """!Return the spatial union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
-
+
@abstractmethod
def spatial_disjoint_union(self, dataset):
"""!Return the spatial union as spatial_extent object.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
-
+
@abstractmethod
def spatial_relation(self, dataset):
"""!Return the spatial relationship between self and dataset
-
+
@param dataset The abstract dataset to compute the spatial relation with self
@return The spatial relationship as string
"""
@@ -252,10 +252,10 @@
def get_temporal_extent_as_tuple(self):
"""!Returns a tuple of the valid start and end time
-
+
Start and end time can be either of type datetime or of type integer,
depending on the temporal type.
-
+
@return A tuple of (start_time, end_time)
"""
start = self.temporal_extent.get_start_time()
@@ -263,16 +263,16 @@
return (start, end)
def get_absolute_time(self):
- """!Returns the start time, the end
+ """!Returns the start time, the end
time and the timezone of the map as tuple
-
+
@attention: The timezone is currently not used.
-
+
The start time is of type datetime.
-
- The end time is of type datetime in case of interval time,
+
+ The end time is of type datetime in case of interval time,
or None on case of a time instance.
-
+
@return A tuple of (start_time, end_time, timezone)
"""
@@ -283,14 +283,14 @@
return (start, end, tz)
def get_relative_time(self):
- """!Returns the start time, the end
+ """!Returns the start time, the end
time and the temporal unit of the dataset as tuple
-
+
The start time is of type integer.
-
- The end time is of type integer in case of interval time,
+
+ The end time is of type integer in case of interval time,
or None on case of a time instance.
-
+
@return A tuple of (start_time, end_time, unit)
"""
@@ -307,14 +307,14 @@
return self.relative_time.get_unit()
def check_relative_time_unit(self, unit):
- """!Check if unit is of type year(s), month(s), day(s), hour(s),
+ """!Check if unit is of type year(s), month(s), day(s), hour(s),
minute(s) or second(s)
@param unit The unit string
@return True if success, False otherwise
"""
# Check unit
- units = ["year", "years", "month", "months", "day", "days", "hour",
+ units = ["year", "years", "month", "months", "day", "days", "hour",
"hours", "minute", "minutes", "second", "seconds"]
if unit not in units:
return False
@@ -322,30 +322,35 @@
def get_temporal_type(self):
"""!Return the temporal type of this dataset
-
+
The temporal type can be absolute or relative
-
+
@return The temporal type of the dataset as string
"""
return self.base.get_ttype()
def get_spatial_extent_as_tuple(self):
"""!Return the spatial extent as tuple
-
+
Top and bottom are set to 0 in case of a two dimensional spatial extent.
-
- @return A the spatial extent as tuple (north, south, east, west, top, bottom)
+
+ @return A the spatial extent as tuple (north, south, east, west, top, bottom)
"""
return self.spatial_extent.get_spatial_extent_as_tuple()
+ def get_spatial_extent(self):
+ """!Return the spatial extent
+ """
+ return self.spatial_extent
+
def select(self, dbif=None):
- """!Select temporal dataset entry from database and fill
+ """!Select temporal dataset entry from database and fill
the internal structure
-
+
The content of every dataset is stored in the temporal database.
- This method must be used to fill this object with the content
+ This method must be used to fill this object with the content
from the temporal database.
-
+
@param dbif The database interface to be used
"""
@@ -367,16 +372,16 @@
"""
return self.base.is_in_db(dbif)
+ @abstractmethod
def delete(self):
"""!Delete dataset from database if it exists"""
- raise ImplementationError("This method must be implemented in the subclasses")
def insert(self, dbif=None, execute=True):
"""!Insert dataset into database
@param dbif The database interface to be used
@param execute If True the SQL statements will be executed.
- If False the prepared SQL statements are returned
+ If False the prepared SQL statements are returned
and must be executed by the caller.
@return The SQL insert statement in case execute=False, or an empty string otherwise
"""
@@ -388,7 +393,7 @@
statement += self.temporal_extent.get_insert_statement_mogrified(dbif)
statement += self.spatial_extent.get_insert_statement_mogrified(dbif)
statement += self.metadata.get_insert_statement_mogrified(dbif)
-
+
if execute:
dbif.execute_transaction(statement)
if connected:
@@ -405,7 +410,7 @@
@param dbif The database interface to be used
@param execute If True the SQL statements will be executed.
- If False the prepared SQL statements are returned
+ If False the prepared SQL statements are returned
and must be executed by the caller.
@param ident The identifier to be updated, useful for renaming
@return The SQL update statement in case execute=False, or an empty string otherwise
@@ -415,9 +420,9 @@
# Build the UPDATE SQL statement
statement = self.base.get_update_statement_mogrified(dbif, ident)
- statement += self.temporal_extent.get_update_statement_mogrified(dbif,
+ statement += self.temporal_extent.get_update_statement_mogrified(dbif,
ident)
- statement += self.spatial_extent.get_update_statement_mogrified(dbif,
+ statement += self.spatial_extent.get_update_statement_mogrified(dbif,
ident)
statement += self.metadata.get_update_statement_mogrified(dbif, ident)
@@ -437,7 +442,7 @@
@param dbif The database interface to be used
@param execute If True the SQL statements will be executed.
- If False the prepared SQL statements are returned
+ If False the prepared SQL statements are returned
and must be executed by the caller.
@param ident The identifier to be updated, useful for renaming
@return The SQL update statement in case execute=False, or an empty string otherwise
@@ -447,7 +452,7 @@
# Build the UPDATE SQL statement
statement = self.base.get_update_all_statement_mogrified(dbif, ident)
- statement += self.temporal_extent.get_update_all_statement_mogrified(dbif,
+ statement += self.temporal_extent.get_update_all_statement_mogrified(dbif,
ident)
statement += self.spatial_extent.get_update_all_statement_mogrified(
dbif, ident)
@@ -465,7 +470,7 @@
def is_time_absolute(self):
"""!Return True in case the temporal type is absolute
-
+
@return True if temporal type is absolute, False otherwise
"""
if "temporal_type" in self.base.D:
@@ -475,14 +480,14 @@
def is_time_relative(self):
"""!Return True in case the temporal type is relative
-
+
@return True if temporal type is relative, False otherwise
"""
if "temporal_type" in self.base.D:
return self.base.get_ttype() == "relative"
else:
return None
-
+
def _get_temporal_extent(self):
"""!Return the temporal extent of the correct internal type
"""
@@ -491,49 +496,49 @@
if self.is_time_relative():
return self.relative_time
return None
-
+
temporal_extent = property(fget=_get_temporal_extent)
def temporal_relation(self, dataset):
"""!Return the temporal relation of self and the provided dataset
-
+
@return The temporal relation as string
"""
return self.temporal_extent.temporal_relation(dataset.temporal_extent)
-
+
def temporal_intersection(self, dataset):
"""!Intersect self with the provided dataset and
return a new temporal extent with the new start and end time
-
+
@param dataset The abstract dataset to temporal intersect with
- @return The new temporal extent with start and end time,
+ @return The new temporal extent with start and end time,
or None in case of no intersection
"""
return self.temporal_extent.intersect(dataset.temporal_extent)
-
+
def temporal_union(self, dataset):
"""!Creates a union with the provided dataset and
return a new temporal extent with the new start and end time.
-
+
@param dataset The abstract dataset to create temporal union with
- @return The new temporal extent with start and end time,
+ @return The new temporal extent with start and end time,
or None in case of no intersection
"""
return self.temporal_extent.union(dataset.temporal_extent)
-
+
def temporal_disjoint_union(self, dataset):
"""!Creates a union with the provided dataset and
return a new temporal extent with the new start and end time.
-
+
@param dataset The abstract dataset to create temporal union with
@return The new temporal extent with start and end time
"""
return self.temporal_extent.disjoint_union(dataset.temporal_extent)
-
+
###############################################################################
class AbstractDatasetComparisonKeyStartTime(object):
- """!This comparison key can be used to sort lists of abstract datasets
+ """!This comparison key can be used to sort lists of abstract datasets
by start time
Example:
@@ -581,7 +586,7 @@
###############################################################################
class AbstractDatasetComparisonKeyEndTime(object):
- """!This comparison key can be used to sort lists of abstract datasets
+ """!This comparison key can be used to sort lists of abstract datasets
by end time
Example:
@@ -627,7 +632,7 @@
return endA != endB
###############################################################################
-
+
if __name__ == "__main__":
import doctest
doctest.testmod()
Modified: grass/trunk/lib/python/temporal/abstract_map_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_map_dataset.py 2013-08-02 17:11:11 UTC (rev 57378)
+++ grass/trunk/lib/python/temporal/abstract_map_dataset.py 2013-08-02 19:29:58 UTC (rev 57379)
@@ -36,9 +36,9 @@
- Abstract methods that must be implemented in the map specific
subclasses
"""
-
+
__metaclass__ = ABCMeta
-
+
def __init__(self):
AbstractDataset.__init__(self)
@@ -207,7 +207,7 @@
self.temporal_extent.print_self()
self.spatial_extent.print_self()
self.metadata.print_self()
-
+
def print_info(self):
"""!Print information about this object in human readable style"""
@@ -328,7 +328,7 @@
def set_time_to_relative(self):
"""!Set the temporal type to relative"""
self.base.set_ttype("relative")
-
+
def set_absolute_time(self, start_time, end_time=None, timezone=None):
"""!Set the absolute time with start time and end time
@@ -348,7 +348,7 @@
if self.get_layer() is not None:
core.fatal(_("Start time must be of type datetime for %(type)s"
" map <%(id)s> with layer: %(l)s") % {
- 'type': self.get_type(), 'id': self.get_map_id(),
+ 'type': self.get_type(), 'id': self.get_map_id(),
'l': self.get_layer()})
else:
core.fatal(_("Start time must be of type datetime for "
@@ -507,6 +507,43 @@
self.write_timestamp_to_grass()
+ def set_temporal_extent(self, temporal_extent):
+ """!Convenient method to set the temporal extent from a temporal extent object
+
+ @param temporal_extent The temporal axtent that should be set for this object
+
+ @code
+ >>> import datetime
+ >>> import grass.temporal as tgis
+ >>> map = tgis.RasterDataset(None)
+ >>> temp_ext = tgis.RelativeTemporalExtent(start_time=1, end_time=2, unit="years")
+ >>> map.set_temporal_extent(temp_ext)
+ >>> print map.get_temporal_extent_as_tuple()
+ (1, 2)
+ >>> map = tgis.VectorDataset(None)
+ >>> temp_ext = tgis.AbsoluteTemporalExtent(start_time=datetime.datetime(2000, 1, 1),
+ ... end_time=datetime.datetime(2001, 1, 1))
+ >>> map.set_temporal_extent(temp_ext)
+ >>> print map.get_temporal_extent_as_tuple()
+ (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0))
+
+ @endcode
+ """
+
+ if issubclass(RelativeTemporalExtent, type(temporal_extent)):
+ start = temporal_extent.get_start_time()
+ end = temporal_extent.get_end_time()
+ unit = temporal_extent.get_unit()
+
+ self.set_relative_time(start, end, unit)
+
+ elif issubclass(AbsoluteTemporalExtent, type(temporal_extent)):
+ start = temporal_extent.get_start_time()
+ end = temporal_extent.get_end_time()
+ tz = temporal_extent.get_timezone()
+
+ self.set_absolute_time(start, end, tz)
+
def temporal_buffer(self, increment, update=False, dbif=None):
"""!Create a temporal buffer based on an increment
@@ -610,8 +647,8 @@
else:
self.set_relative_time(new_start, new_end, unit)
- def set_spatial_extent(self, north, south, east, west, top=0, bottom=0):
- """!Set the spatial extent of the map
+ def set_spatial_extent_from_values(self, north, south, east, west, top=0, bottom=0):
+ """!Set the spatial extent of the map from values
This method only modifies this object and does not commit
the modifications to the temporal database.
@@ -623,9 +660,84 @@
@param top The top edge
@param bottom The bottom edge
"""
- self.spatial_extent.set_spatial_extent(
+ self.spatial_extent.set_spatial_extent_from_values(
north, south, east, west, top, bottom)
+ def set_spatial_extent(self, spatial_extent):
+ """!Set the spatial extent of the map
+
+ This method only modifies this object and does not commit
+ the modifications to the temporal database.
+
+ @param spatial_extent An object of type SpatialExtent or its subclasses
+
+ @code
+ >>> import datetime
+ >>> import grass.temporal as tgis
+ >>> map = tgis.RasterDataset(None)
+ >>> spat_ext = tgis.SpatialExtent(north=10, south=-10, east=20, west=-20, top=5, bottom=-5)
+ >>> map.set_spatial_extent(spat_ext)
+ >>> print map.get_spatial_extent_as_tuple()
+ (10.0, -10.0, 20.0, -20.0, 5.0, -5.0)
+
+ @endcode
+ """
+ self.spatial_extent.set_spatial_extent(spatial_extent)
+
+ def spatial_buffer(self, size, update=False, dbif=None):
+ """!Buffer the spatial extent by a given size in all
+ spatial directions.
+
+ @param size The buffer size, using the unit of the grass region
+
+ @code
+
+ >>> import grass.temporal as tgis
+ >>> map = tgis.RasterDataset(None)
+ >>> spat_ext = tgis.SpatialExtent(north=10, south=-10, east=20, west=-20, top=5, bottom=-5)
+ >>> map.set_spatial_extent(spat_ext)
+ >>> map.spatial_buffer(10)
+ >>> print map.get_spatial_extent_as_tuple()
+ (20.0, -20.0, 30.0, -30.0, 15.0, -15.0)
+
+ @endcode
+ """
+ self.spatial_extent.north += size
+ self.spatial_extent.south -= size
+ self.spatial_extent.east += size
+ self.spatial_extent.west -= size
+ self.spatial_extent.top += size
+ self.spatial_extent.bottom -= size
+
+ if update:
+ self.spatial_extent.update(dbif)
+
+ def spatial_buffer_2d(self, size, update=False, dbif=None):
+ """!Buffer the spatial extent by a given size in 2d
+ spatial directions.
+
+ @param size The buffer size, using the unit of the grass region
+
+ @code
+
+ >>> import grass.temporal as tgis
+ >>> map = tgis.RasterDataset(None)
+ >>> spat_ext = tgis.SpatialExtent(north=10, south=-10, east=20, west=-20, top=5, bottom=-5)
+ >>> map.set_spatial_extent(spat_ext)
+ >>> map.spatial_buffer_2d(10)
+ >>> print map.get_spatial_extent_as_tuple()
+ (20.0, -20.0, 30.0, -30.0, 5.0, -5.0)
+
+ @endcode
+ """
+ self.spatial_extent.north += size
+ self.spatial_extent.south -= size
+ self.spatial_extent.east += size
+ self.spatial_extent.west -= size
+
+ if update:
+ self.spatial_extent.update(dbif)
+
def check_for_correct_time(self):
"""!Check for correct time"""
if self.is_time_absolute():
@@ -696,7 +808,7 @@
#core.verbose(_("Delete %s dataset <%s> from temporal database")
# % (self.get_type(), self.get_id()))
- # Delete yourself from the database, trigger functions will
+ # Delete yourself from the database, trigger functions will
# take care of dependencies
statement += self.base.get_delete_statement()
@@ -736,7 +848,7 @@
#if self.get_layer() is not None:
# core.verbose(_("Unregister %(type)s map <%(map)s> with "
# "layer %(layer)s from space time datasets" % \
- # {'type':self.get_type(), 'map':self.get_map_id(),
+ # {'type':self.get_type(), 'map':self.get_map_id(),
# 'layer':self.get_layer()}))
#else:
# core.verbose(_("Unregister %(type)s map <%(map)s> "
Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py 2013-08-02 17:11:11 UTC (rev 57378)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py 2013-08-02 19:29:58 UTC (rev 57379)
@@ -32,9 +32,9 @@
database, like the computation of the temporal and spatial extent as
well as the collecting of metadata.
"""
-
+
__metaclass__ = ABCMeta
-
+
def __init__(self, ident):
AbstractDataset.__init__(self)
self.reset(ident)
@@ -63,7 +63,7 @@
@param ident The unique identifier of the new object
"""
-
+
@abstractmethod
def get_map_register(self):
"""!Return the name of the map register table
@@ -120,11 +120,11 @@
self.metadata.print_shell_info()
def print_history(self):
- """!Print history information about this class in human readable
+ """!Print history information about this class in human readable
shell style
"""
self.metadata.print_history()
-
+
def set_initial_values(self, temporal_type, semantic_type,
title=None, description=None):
"""!Set the initial values of the space time dataset
@@ -1041,7 +1041,8 @@
self.get_relative_time_unit())
# The fast way
if has_bt_columns:
- map.set_spatial_extent(west=row["west"], east=row["east"],
+ map.set_spatial_extent_from_values(west=row["west"],
+ east=row["east"],
south=row["south"], top=row["top"],
north=row["north"],
bottom=row["bottom"])
@@ -1491,16 +1492,15 @@
# Get the update statement, we update the table entry of the old
# identifier
statement = self.update(dbif, execute=False, ident=old_ident)
-
# We need to rename the raster register table
- statement += "ALTER TABLE %s RENAME TO \'%s\';\n" % \
+ statement += "ALTER TABLE %s RENAME TO \"%s\";\n" % \
(old_map_register_table, new_map_register_table)
# We need to rename the space time dataset in the maps register table
if maps:
for map in maps:
map.select()
- statement += "UPDATE %s SET id = \'%s\' WHERE id = \'%s\';\n"%\
+ statement += "UPDATE %s SET id = \"%s\" WHERE id = \"%s\";\n"%\
(map.get_stds_register(), ident, old_ident)
# Execute the accumulated statements
@@ -1656,7 +1656,7 @@
dbif)
# Commented because of performance issue calling g.message thousend times
#core.verbose(_("Set temporal unit for space time %s dataset "
- # "<%s> to %s") % (map.get_type(), self.get_id(),
+ # "<%s> to %s") % (map.get_type(), self.get_id(),
# map_rel_time_unit))
stds_rel_time_unit = self.get_relative_time_unit()
@@ -1739,11 +1739,11 @@
#if map.get_layer():
# core.verbose(_("Created register table <%s> for "
# "%s map <%s> with layer %s") %
- # (map_register_table, map.get_type(),
+ # (map_register_table, map.get_type(),
# map.get_map_id(), map.get_layer()))
#else:
# core.verbose(_("Created register table <%s> for %s map <%s>") %
- # (map_register_table, map.get_type(),
+ # (map_register_table, map.get_type(),
# map.get_map_id()))
# We need to create the table and register it
@@ -2002,7 +2002,7 @@
else:
# Check if the end time is smaller than the maximum start time
if self.is_time_absolute():
- sql = """SELECT max(start_time) FROM GRASS_MAP_absolute_time
+ sql = """SELECT max(start_time) FROM GRASS_MAP_absolute_time
WHERE GRASS_MAP_absolute_time.id IN
(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register);"""
sql = sql.replace("GRASS_MAP", self.get_new_map_instance(
@@ -2010,7 +2010,7 @@
sql = sql.replace("SPACETIME_NAME",
stds_name + "_" + stds_mapset)
else:
- sql = """SELECT max(start_time) FROM GRASS_MAP_relative_time
+ sql = """SELECT max(start_time) FROM GRASS_MAP_relative_time
WHERE GRASS_MAP_relative_time.id IN
(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register);"""
sql = sql.replace("GRASS_MAP", self.get_new_map_instance(
@@ -2046,7 +2046,7 @@
if use_start_time:
if self.is_time_absolute():
sql = """UPDATE STDS_absolute_time SET end_time =
- (SELECT max(start_time) FROM GRASS_MAP_absolute_time WHERE
+ (SELECT max(start_time) FROM GRASS_MAP_absolute_time WHERE
GRASS_MAP_absolute_time.id IN
(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
) WHERE id = 'SPACETIME_ID';"""
@@ -2058,7 +2058,7 @@
sql = sql.replace("STDS", self.get_type())
elif self.is_time_relative():
sql = """UPDATE STDS_relative_time SET end_time =
- (SELECT max(start_time) FROM GRASS_MAP_relative_time WHERE
+ (SELECT max(start_time) FROM GRASS_MAP_relative_time WHERE
GRASS_MAP_relative_time.id IN
(SELECT id FROM SPACETIME_NAME_GRASS_MAP_register)
) WHERE id = 'SPACETIME_ID';"""
Modified: grass/trunk/lib/python/temporal/space_time_datasets.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets.py 2013-08-02 17:11:11 UTC (rev 57378)
+++ grass/trunk/lib/python/temporal/space_time_datasets.py 2013-08-02 19:29:58 UTC (rev 57379)
@@ -14,7 +14,7 @@
>>> grass.run_command("r3.mapcalc", overwrite=True, expression="str3ds_map_test_case = 1")
0
->>> grass.run_command("v.random", overwrite=True, output="stvds_map_test_case",
+>>> grass.run_command("v.random", overwrite=True, output="stvds_map_test_case",
... n=100, zmin=0, zmax=100, flags="z", column="elevation")
0
@@ -38,25 +38,25 @@
This class provides functions to select, update, insert or delete raster
map information and valid time stamps into the SQL temporal database.
-
+
Usage:
-
+
@code
-
+
>>> import grass.script as grass
>>> init()
>>> grass.use_temp_region()
- >>> grass.run_command("g.region", n=80.0, s=0.0, e=120.0, w=0.0,
+ >>> grass.run_command("g.region", n=80.0, s=0.0, e=120.0, w=0.0,
... t=1.0, b=0.0, res=10.0)
0
- >>> grass.run_command("r.mapcalc", overwrite=True,
+ >>> grass.run_command("r.mapcalc", overwrite=True,
... expression="strds_map_test_case = 1")
0
>>> mapset = grass.gisenv()["MAPSET"]
>>> name = "strds_map_test_case"
>>> identifier = "%s@%s" % (name, mapset)
>>> rmap = RasterDataset(identifier)
- >>> rmap.set_absolute_time(start_time=datetime(2001,1,1),
+ >>> rmap.set_absolute_time(start_time=datetime(2001,1,1),
... end_time=datetime(2012,1,1))
True
>>> rmap.map_exists()
@@ -85,7 +85,7 @@
| Minimum value:.............. 1.0
| Maximum value:.............. 1.0
| STRDS register table ....... None
-
+
>>> newmap = rmap.get_new_instance("new at PERMANENT")
>>> isinstance(newmap, RasterDataset)
True
@@ -111,11 +111,11 @@
True
>>> rmap.is_time_relative()
False
-
+
>>> grass.run_command("g.remove", rast=name)
0
>>> grass.del_temp_region()
-
+
@endcode
"""
def __init__(self, ident):
@@ -130,17 +130,17 @@
return RasterDataset(ident)
def get_new_stds_instance(self, ident):
- """!Return a new space time dataset instance in which maps
+ """!Return a new space time dataset instance in which maps
are stored with the type of this class"""
return SpaceTimeRasterDataset(ident)
def get_stds_register(self):
- """!Return the space time dataset register table name in which stds
+ """!Return the space time dataset register table name in which stds
are listed in which this map is registered"""
return self.metadata.get_strds_register()
def set_stds_register(self, name):
- """!Set the space time dataset register table name in which stds
+ """!Set the space time dataset register table name in which stds
are listed in which this map is registered"""
self.metadata.set_strds_register(name)
@@ -153,43 +153,43 @@
return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
def spatial_intersection(self, dataset):
- """!Return the two dimensional intersection as spatial_extent
+ """!Return the two dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param dataset The abstract dataset to intersect with
@return The intersection spatial extent or None
"""
return self.spatial_extent.intersect_2d(dataset.spatial_extent)
def spatial_union(self, dataset):
- """!Return the two dimensional union as spatial_extent
+ """!Return the two dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent or None
"""
return self.spatial_extent.union_2d(dataset.spatial_extent)
-
+
def spatial_disjoint_union(self, dataset):
"""!Return the two dimensional union as spatial_extent object.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
return self.spatial_extent.disjoint_union_2d(dataset.spatial_extent)
-
+
def get_np_array(self):
"""!Return this raster map as memmap numpy style array to access the raster
values in numpy style without loading the whole map in the RAM.
- In case this raster map does exists in the grass spatial database,
- the map will be exported using r.out.bin to a temporary location
+ In case this raster map does exists in the grass spatial database,
+ the map will be exported using r.out.bin to a temporary location
and assigned to the memmap object that is returned by this function.
- In case the raster map does not exists, an empty temporary
+ In case the raster map does not exists, an empty temporary
binary file will be created and assigned to the memap object.
- You need to call the write function to write the memmap
+ You need to call the write function to write the memmap
array back into grass.
"""
@@ -217,7 +217,7 @@
return False
def write_timestamp_to_grass(self):
- """!Write the timestamp of this map into the map metadata in
+ """!Write the timestamp of this map into the map metadata in
the grass file system based spatial database.
Internally the libgis API functions are used for writing
@@ -237,7 +237,7 @@
(self.get_map_id())))
def remove_timestamp_from_grass(self):
- """!Remove the timestamp from the grass file system based
+ """!Remove the timestamp from the grass file system based
spatial database
Internally the libgis API functions are used for removal
@@ -350,7 +350,7 @@
# Fill spatial extent
- self.set_spatial_extent(north=kvp["north"], south=kvp["south"],
+ self.set_spatial_extent_from_values(north=kvp["north"], south=kvp["south"],
east=kvp["east"], west=kvp["west"])
# Fill metadata
@@ -390,17 +390,17 @@
return Raster3DDataset(ident)
def get_new_stds_instance(self, ident):
- """!Return a new space time dataset instance in which maps
+ """!Return a new space time dataset instance in which maps
are stored with the type of this class"""
return SpaceTimeRaster3DDataset(ident)
def get_stds_register(self):
- """!Return the space time dataset register table name in
+ """!Return the space time dataset register table name in
which stds are listed in which this map is registered"""
return self.metadata.get_str3ds_register()
def set_stds_register(self, name):
- """!Set the space time dataset register table name in
+ """!Set the space time dataset register table name in
which stds are listed in which this map is registered"""
self.metadata.set_str3ds_register(name)
@@ -419,9 +419,9 @@
return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
def spatial_intersection(self, dataset):
- """!Return the three or two dimensional intersection as spatial_extent
+ """!Return the three or two dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param dataset The abstract dataset to intersect with
@return The intersection spatial extent or None
"""
@@ -431,9 +431,9 @@
return self.spatial_extent.intersect_2d(dataset.spatial_extent)
def spatial_union(self, dataset):
- """!Return the three or two dimensional union as spatial_extent
+ """!Return the three or two dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent or None
"""
@@ -441,10 +441,10 @@
return self.spatial_extent.union(dataset.spatial_extent)
else:
return self.spatial_extent.union_2d(dataset.spatial_extent)
-
+
def spatial_disjoint_union(self, dataset):
"""!Return the three or two dimensional union as spatial_extent object.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
@@ -452,19 +452,19 @@
return self.spatial_extent.disjoint_union(dataset.spatial_extent)
else:
return self.spatial_extent.disjoint_union_2d(dataset.spatial_extent)
-
+
def get_np_array(self):
"""!Return this 3D raster map as memmap numpy style array to access the 3D raster
values in numpy style without loading the whole map in the RAM.
- In case this 3D raster map does exists in the grass spatial database,
- the map will be exported using r3.out.bin to a temporary location
+ In case this 3D raster map does exists in the grass spatial database,
+ the map will be exported using r3.out.bin to a temporary location
and assigned to the memmap object that is returned by this function.
- In case the 3D raster map does not exists, an empty temporary
+ In case the 3D raster map does not exists, an empty temporary
binary file will be created and assigned to the memap object.
- You need to call the write function to write the memmap
+ You need to call the write function to write the memmap
array back into grass.
"""
@@ -474,7 +474,7 @@
a.read(self.get_map_id())
return a
-
+
def reset(self, ident):
"""!Reset the internal structure and set the identifier"""
self.base = Raster3DBase(ident=ident)
@@ -492,7 +492,7 @@
return False
def write_timestamp_to_grass(self):
- """!Write the timestamp of this map into the map metadata
+ """!Write the timestamp of this map into the map metadata
in the grass file system based spatial database.
Internally the libgis API functions are used for writing
@@ -568,12 +568,12 @@
kvp["bottom"] = region.bottom
# We need to open the map, this function returns a void pointer
- # but we may need the correct type which is RASTER3D_Map, hence
+ # but we may need the correct type which is RASTER3D_Map, hence
# the casting
g3map = cast(libraster3d.Rast3d_open_cell_old(name, mapset,
- libraster3d.RASTER3D_DEFAULT_WINDOW,
+ libraster3d.RASTER3D_DEFAULT_WINDOW,
libraster3d.RASTER3D_TILE_SAME_AS_FILE,
- libraster3d.RASTER3D_NO_CACHE),
+ libraster3d.RASTER3D_NO_CACHE),
POINTER(libraster3d.RASTER3D_Map))
if not g3map:
@@ -624,7 +624,7 @@
else:
kvp = grass.raster3d_info(self.get_id())
- self.set_spatial_extent(north=kvp["north"], south=kvp["south"],
+ self.set_spatial_extent_from_values(north=kvp["north"], south=kvp["south"],
east=kvp["east"], west=kvp["west"],
top=kvp["top"], bottom=kvp["bottom"])
@@ -667,17 +667,17 @@
return VectorDataset(ident)
def get_new_stds_instance(self, ident):
- """!Return a new space time dataset instance in which maps
+ """!Return a new space time dataset instance in which maps
are stored with the type of this class"""
return SpaceTimeVectorDataset(ident)
def get_stds_register(self):
- """!Return the space time dataset register table name in
+ """!Return the space time dataset register table name in
which stds are listed in which this map is registered"""
return self.metadata.get_stvds_register()
def set_stds_register(self, name):
- """!Set the space time dataset register table name in
+ """!Set the space time dataset register table name in
which stds are listed in which this map is registered"""
self.metadata.set_stvds_register(name)
@@ -696,31 +696,31 @@
return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
def spatial_intersection(self, dataset):
- """!Return the two dimensional intersection as spatial_extent
+ """!Return the two dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param dataset The abstract dataset to intersect with
@return The intersection spatial extent or None
"""
return self.spatial_extent.intersect_2d(dataset.spatial_extent)
def spatial_union(self, dataset):
- """!Return the two dimensional union as spatial_extent
+ """!Return the two dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent or None
"""
return self.spatial_extent.union_2d(dataset.spatial_extent)
-
+
def spatial_disjoint_union(self, dataset):
"""!Return the two dimensional union as spatial_extent object.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
return self.spatial_extent.disjoint_union_2d(dataset.spatial_extent)
-
+
def reset(self, ident):
"""!Reset the internal structure and set the identifier"""
self.base = VectorBase(ident=ident)
@@ -732,14 +732,14 @@
def has_grass_timestamp(self):
"""!Check if a grass file bsased time stamp exists for this map.
"""
- if G_has_vector_timestamp(self.get_name(), self.get_layer(),
+ if G_has_vector_timestamp(self.get_name(), self.get_layer(),
self.get_mapset()):
return True
else:
return False
def write_timestamp_to_grass(self):
- """!Write the timestamp of this map into the map metadata in
+ """!Write the timestamp of this map into the map metadata in
the grass file system based spatial database.
Internally the libgis API functions are used for writing
@@ -760,7 +760,7 @@
(self.get_map_id())))
def remove_timestamp_from_grass(self):
- """!Remove the timestamp from the grass file system based spatial
+ """!Remove the timestamp from the grass file system based spatial
database
Internally the libgis API functions are used for removal
@@ -810,18 +810,18 @@
# Code lend from v.info main.c
if libvector.Vect_open_old_head2(byref(Map), name, mapset, "1") < 2:
# force level 1, open fully
- # NOTE: number of points, lines, boundaries, centroids,
+ # NOTE: number of points, lines, boundaries, centroids,
# faces, kernels is still available
libvector.Vect_set_open_level(1) # no topology
with_topo = False
core.message(_("Open map without topology support"))
if libvector.Vect_open_old2(byref(Map), name, mapset, "1") < 1:
- core.fatal(_("Unable to open vector map <%s>" %
+ core.fatal(_("Unable to open vector map <%s>" %
(libvector.Vect_get_full_name(byref(Map)))))
# Release the vector spatial index memory when closed
libvector.Vect_set_release_support(byref(Map))
-
+
# Read the extent information
bbox = libvector.bound_box()
libvector.Vect_get_map_box(byref(Map), byref(bbox))
@@ -882,7 +882,7 @@
return kvp
def load(self):
- """!Load all info from an existing vector map into the internal
+ """!Load all info from an existing vector map into the internal
structure"""
# Fill base information
@@ -896,7 +896,7 @@
kvp = grass.vector_info(self.get_map_id())
# Fill spatial extent
- self.set_spatial_extent(north=kvp["north"], south=kvp["south"],
+ self.set_spatial_extent_from_values(north=kvp["north"], south=kvp["south"],
east=kvp["east"], west=kvp["west"],
top=kvp["top"], bottom=kvp["bottom"])
@@ -952,31 +952,31 @@
return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
def spatial_intersection(self, dataset):
- """!Return the two dimensional intersection as spatial_extent
+ """!Return the two dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param dataset The abstract dataset to intersect with
@return The intersection spatial extent or None
"""
return self.spatial_extent.intersect_2d(dataset.spatial_extent)
def spatial_union(self, dataset):
- """!Return the two dimensional union as spatial_extent
+ """!Return the two dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent or None
"""
return self.spatial_extent.union_2d(dataset.spatial_extent)
-
+
def spatial_disjoint_union(self, dataset):
"""!Return the two dimensional union as spatial_extent object.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
return self.spatial_extent.disjoint_union_2d(dataset.spatial_extent)
-
+
def reset(self, ident):
"""!Reset the internal structure and set the identifier"""
@@ -1004,7 +1004,7 @@
return SpaceTimeRaster3DDataset(ident)
def get_new_map_instance(self, ident):
- """!Return a new instance of a map dataset which is associated
+ """!Return a new instance of a map dataset which is associated
with the type of this class"""
return Raster3DDataset(ident)
@@ -1034,9 +1034,9 @@
return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
def spatial_intersection(self, dataset):
- """!Return the three or two dimensional intersection as spatial_extent
+ """!Return the three or two dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param dataset The abstract dataset to intersect with
@return The intersection spatial extent or None
"""
@@ -1046,9 +1046,9 @@
return self.spatial_extent.intersect_2d(dataset.spatial_extent)
def spatial_union(self, dataset):
- """!Return the three or two dimensional union as spatial_extent
+ """!Return the three or two dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent or None
"""
@@ -1056,10 +1056,10 @@
return self.spatial_extent.union(dataset.spatial_extent)
else:
return self.spatial_extent.union_2d(dataset.spatial_extent)
-
+
def spatial_disjoint_union(self, dataset):
"""!Return the three or two dimensional union as spatial_extent object.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
@@ -1067,7 +1067,7 @@
return self.spatial_extent.disjoint_union(dataset.spatial_extent)
else:
return self.spatial_extent.disjoint_union_2d(dataset.spatial_extent)
-
+
def reset(self, ident):
"""!Reset the internal structure and set the identifier"""
@@ -1096,7 +1096,7 @@
return SpaceTimeVectorDataset(ident)
def get_new_map_instance(self, ident):
- """!Return a new instance of a map dataset which is associated
+ """!Return a new instance of a map dataset which is associated
with the type of this class"""
return VectorDataset(ident)
@@ -1117,31 +1117,31 @@
return self.spatial_extent.spatial_relation_2d(dataset.spatial_extent)
def spatial_intersection(self, dataset):
- """!Return the two dimensional intersection as spatial_extent
+ """!Return the two dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param dataset The abstract dataset to intersect with
@return The intersection spatial extent or None
"""
return self.spatial_extent.intersect_2d(dataset.spatial_extent)
def spatial_union(self, dataset):
- """!Return the two dimensional union as spatial_extent
+ """!Return the two dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent or None
"""
return self.spatial_extent.union_2d(dataset.spatial_extent)
-
+
def spatial_disjoint_union(self, dataset):
"""!Return the two dimensional union as spatial_extent object.
-
+
@param dataset The abstract dataset to create a union with
@return The union spatial extent
"""
return self.spatial_extent.disjoint_union_2d(dataset.spatial_extent)
-
+
def reset(self, ident):
"""!Reset the internal structure and set the identifier"""
Modified: grass/trunk/lib/python/temporal/spatial_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/spatial_extent.py 2013-08-02 17:11:11 UTC (rev 57378)
+++ grass/trunk/lib/python/temporal/spatial_extent.py 2013-08-02 19:29:58 UTC (rev 57379)
@@ -10,22 +10,22 @@
>>> import grass.temporal as tgis
>>> tgis.init()
->>> extent = tgis.RasterSpatialExtent(
+>>> extent = tgis.RasterSpatialExtent(
... ident="raster at PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
->>> extent = tgis.Raster3DSpatialExtent(
+>>> extent = tgis.Raster3DSpatialExtent(
... ident="raster3d at PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
->>> extent = tgis.VectorSpatialExtent(
+>>> extent = tgis.VectorSpatialExtent(
... ident="vector at PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
->>> extent = tgis.STRDSSpatialExtent(
+>>> extent = tgis.STRDSSpatialExtent(
... ident="strds at PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
->>> extent = tgis.STR3DSSpatialExtent(
+>>> extent = tgis.STR3DSSpatialExtent(
... ident="str3ds at PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
->>> extent = tgis.STVDSSpatialExtent(
+>>> extent = tgis.STVDSSpatialExtent(
... ident="stvds at PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
@@ -43,16 +43,16 @@
class SpatialExtent(SQLDatabaseInterface):
"""!This is the spatial extent base class for all maps and space time datasets
-
+
This class implements a three dimensional axis aligned bounding box
and functions to compute topological relationships
-
+
Usage:
-
+
@code
-
+
>>> init()
- >>> extent = SpatialExtent(table="raster_spatial_extent",
+ >>> extent = SpatialExtent(table="raster_spatial_extent",
... ident="soil at PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
>>> extent.id
@@ -84,39 +84,39 @@
west=180.0
top=100.0
bottom=-20.0
-
+
@endcode
"""
- def __init__(self, table=None, ident=None, north=None, south=None,
+ def __init__(self, table=None, ident=None, north=None, south=None,
east=None, west=None, top=None, bottom=None, proj="XY"):
SQLDatabaseInterface.__init__(self, table, ident)
self.set_id(ident)
- self.set_spatial_extent(north, south, east, west, top, bottom)
+ self.set_spatial_extent_from_values(north, south, east, west, top, bottom)
self.set_projection(proj)
def overlapping_2d(self, extent):
"""!Return True if this (A) and the provided spatial extent (B) overlaps
- in two dimensional space.
+ in two dimensional space.
Code is lend from wind_overlap.c in lib/gis
-
+
Overlapping includes the spatial relations:
-
+
- contain
- in
- cover
- covered
- equivalent
-
+
@code
-
+
>>> A = SpatialExtent(north=80, south=20, east=60, west=10)
>>> B = SpatialExtent(north=80, south=20, east=60, west=10)
>>> A.overlapping_2d(B)
True
-
+
@endcode
-
+
@param extent The spatial extent to check overlapping with
@return True or False
"""
@@ -156,28 +156,28 @@
return True
def overlapping(self, extent):
- """!Return True if this (A) and the provided spatial
+ """!Return True if this (A) and the provided spatial
extent (B) overlaps in three dimensional space.
-
+
Overlapping includes the spatial relations:
-
+
- contain
- in
- cover
- covered
- equivalent
-
+
Usage:
-
+
@code
-
+
>>> A = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
>>> B = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
>>> A.overlapping(B)
True
-
+
@endcode
-
+
@param extent The spatial extent to check overlapping with
@return True or False
"""
@@ -197,9 +197,9 @@
return True
def intersect_2d(self, extent):
- """!Return the two dimensional intersection as spatial_extent
+ """!Return the two dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
@param extent The spatial extent to intersect with
@return The intersection spatial extent
"""
@@ -247,16 +247,16 @@
return new
def intersect(self, extent):
- """!Return the three dimensional intersection as spatial_extent
+ """!Return the three dimensional intersection as spatial_extent
object or None in case no intersection was found.
-
+
Usage:
-
+
@code
-
- >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
+
+ >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
- >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
+ >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
>>> C = A.intersect(B)
>>> C.print_info()
@@ -267,7 +267,7 @@
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=10,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=10,
... bottom=-50, top=50)
>>> C = A.intersect(B)
>>> C.print_info()
@@ -278,7 +278,7 @@
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-50, top=50)
>>> C = A.intersect(B)
>>> C.print_info()
@@ -289,7 +289,7 @@
| West:....................... 30.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=50)
>>> C = A.intersect(B)
>>> C.print_info()
@@ -300,7 +300,7 @@
| West:....................... 30.0
| Top:........................ 50.0
| Bottom:..................... -30.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=30)
>>> C = A.intersect(B)
>>> C.print_info()
@@ -311,10 +311,10 @@
| West:....................... 30.0
| Top:........................ 30.0
| Bottom:..................... -30.0
-
+
@endcode
-
-
+
+
@param extent The spatial extent to intersect with
@return The intersection spatial extent
"""
@@ -342,22 +342,22 @@
new.set_bottom(nB)
return new
-
+
def union_2d(self, extent):
- """!Return the two dimensional union as spatial_extent
+ """!Return the two dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param extent The spatial extent to create a union with
@return The union spatial extent
"""
if not self.overlapping_2d(extent) and not self.meet_2d(extent):
return None
-
+
return self.disjoint_union_2d(extent)
-
+
def disjoint_union_2d(self, extent):
"""!Return the two dimensional union as spatial_extent.
-
+
@param extent The spatial extent to create a union with
@return The union spatial extent
"""
@@ -401,27 +401,27 @@
return new
def union(self, extent):
- """!Return the three dimensional union as spatial_extent
+ """!Return the three dimensional union as spatial_extent
object or None in case the extents does not overlap or meet.
-
+
@param extent The spatial extent to create a union with
@return The union spatial extent
"""
if not self.overlapping(extent) and not self.meet(extent):
return None
-
+
return self.disjoint_union(extent)
-
+
def disjoint_union(self, extent):
"""!Return the three dimensional union as spatial_extent .
-
+
Usage:
-
+
@code
-
- >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
+
+ >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
- >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
+ >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
>>> C = A.disjoint_union(B)
>>> C.print_info()
@@ -432,7 +432,7 @@
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=10,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=10,
... bottom=-50, top=50)
>>> C = A.disjoint_union(B)
>>> C.print_info()
@@ -443,7 +443,7 @@
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-50, top=50)
>>> C = A.disjoint_union(B)
>>> C.print_info()
@@ -454,7 +454,7 @@
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=50)
>>> C = A.disjoint_union(B)
>>> C.print_info()
@@ -465,7 +465,7 @@
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
+ >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=30)
>>> C = A.disjoint_union(B)
>>> C.print_info()
@@ -476,9 +476,9 @@
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
- >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
+ >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
- >>> B = SpatialExtent(north=90, south=80, east=70, west=20,
+ >>> B = SpatialExtent(north=90, south=80, east=70, west=20,
... bottom=-30, top=60)
>>> C = A.disjoint_union(B)
>>> C.print_info()
@@ -489,9 +489,9 @@
| West:....................... 10.0
| Top:........................ 60.0
| Bottom:..................... -50.0
-
+
@endcode
-
+
@param extent The spatial extent to create a disjoint union with
@return The union spatial extent
"""
@@ -516,19 +516,19 @@
new.set_bottom(nB)
return new
-
+
def is_in_2d(self, extent):
"""!Return True if this extent (A) is located in the provided spatial
extent (B) in two dimensions.
-
+
@verbatim
_____
|A _ |
| |_| |
- |_____|B
-
+ |_____|B
+
@endverbatim
-
+
@param extent The spatial extent
@return True or False
"""
@@ -571,22 +571,22 @@
def is_in(self, extent):
"""!Return True if this extent (A) is located in the provided spatial
extent (B) in three dimensions.
-
+
Usage:
-
+
@code
-
- >>> A = SpatialExtent(north=79, south=21, east=59, west=11,
+
+ >>> A = SpatialExtent(north=79, south=21, east=59, west=11,
... bottom=-49, top=49)
- >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
+ >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
>>> A.is_in(B)
True
>>> B.is_in(A)
False
-
+
@endcode
-
+
@param extent The spatial extent
@return True or False
"""
@@ -609,44 +609,44 @@
def contain_2d(self, extent):
"""!Return True if this extent (A) contains the provided spatial
extent (B) in two dimensions.
-
+
Usage:
-
+
@code
-
+
>>> A = SpatialExtent(north=80, south=20, east=60, west=10)
>>> B = SpatialExtent(north=79, south=21, east=59, west=11)
>>> A.contain_2d(B)
True
>>> B.contain_2d(A)
False
-
+
@endcode
-
+
@param extent The spatial extent
@return True or False
"""
return extent.is_in_2d(self)
- def contain(self, extent):
+ def contain(self, extent):
"""!Return True if this extent (A) contains the provided spatial
extent (B) in three dimensions.
-
+
Usage:
-
+
@code
-
- >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
+
+ >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
- >>> B = SpatialExtent(north=79, south=21, east=59, west=11,
+ >>> B = SpatialExtent(north=79, south=21, east=59, west=11,
... bottom=-49, top=49)
>>> A.contain(B)
True
>>> B.contain(A)
False
-
+
@endcode
-
+
@param extent The spatial extent
@return True or False
"""
@@ -655,20 +655,20 @@
def equivalent_2d(self, extent):
"""!Return True if this extent (A) is equal to the provided spatial
extent (B) in two dimensions.
-
+
Usage:
-
+
@code
-
+
>>> A = SpatialExtent(north=80, south=20, east=60, west=10)
>>> B = SpatialExtent(north=80, south=20, east=60, west=10)
>>> A.equivalent_2d(B)
True
>>> B.equivalent_2d(A)
True
-
+
@endcode
-
+
@param extent The spatial extent
@return True or False
"""
@@ -711,22 +711,22 @@
def equivalent(self, extent):
"""!Return True if this extent (A) is equal to the provided spatial
extent (B) in three dimensions.
-
+
Usage:
-
+
@code
-
- >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
+
+ >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
- >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
+ >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
>>> A.equivalent(B)
True
>>> B.equivalent(A)
True
-
+
@endcode
-
+
@param extent The spatial extent
@return True or False
"""
@@ -750,27 +750,27 @@
def cover_2d(self, extent):
"""!Return True if this extent (A) covers the provided spatial
extent (B) in two dimensions.
-
+
@verbatim
_____ _____ _____ _____
|A __| |__ A| |A | B| |B | A|
| |B | | B| | | |__| |__| |
|__|__| |__|__| |_____| |_____|
-
+
_____ _____ _____ _____
|A|B| | |A __| |A _ | |__ A|
| |_| | | |__|B | |B| | B|__| |
|_____| |_____| |_|_|_| |_____|
-
+
_____ _____ _____ _____
|A|B | |_____|A |A|B|A| |_____|A
| | | |B | | | | | |_____|B
|_|___| |_____| |_|_|_| |_____|A
-
+
@endverbatim
-
+
The following cases are excluded:
-
+
- contain
- in
- equivalent
@@ -840,9 +840,9 @@
def cover(self, extent):
"""!Return True if this extent covers the provided spatial
extent in three dimensions.
-
+
The following cases are excluded:
-
+
- contain
- in
- equivalent
@@ -930,9 +930,9 @@
def covered_2d(self, extent):
"""!Return True if this extent is covered by the provided spatial
extent in two dimensions.
-
+
The following cases are excluded:
-
+
- contain
- in
- equivalent
@@ -946,9 +946,9 @@
def covered(self, extent):
"""!Return True if this extent is covered by the provided spatial
extent in three dimensions.
-
+
The following cases are excluded:
-
+
- contain
- in
- equivalent
@@ -963,24 +963,24 @@
"""!Return True if this extent (A) overlaps with the provided spatial
extent (B) in two dimensions.
Code is lend from wind_overlap.c in lib/gis
-
+
@verbatim
_____
|A __|__
| | | B|
|__|__| |
|_____|
-
+
@endverbatim
-
+
The following cases are excluded:
-
+
- contain
- in
- cover
- covered
- equivalent
-
+
@param extent The spatial extent
@return True or False
"""
@@ -1034,13 +1034,13 @@
extent in three dimensions.
The following cases are excluded:
-
+
- contain
- in
- cover
- covered
- equivalent
-
+
@param extent The spatial extent
@return True or False
"""
@@ -1100,9 +1100,9 @@
def meet_2d(self, extent):
"""!Return True if this extent (A) meets with the provided spatial
extent (B) in two dimensions.
-
+
@verbatim
- _____ _____
+ _____ _____
| A | B |
|_____| |
|_____|
@@ -1113,10 +1113,10 @@
___
| A |
| |
- |___|
+ |___|
| B |
- | |
- |_____|
+ | |
+ |_____|
_____
| B |
| |
@@ -1124,9 +1124,9 @@
| A |
| |
|_____|
-
+
@endverbatim
-
+
@param extent The spatial extent
@return True or False
"""
@@ -1136,9 +1136,6 @@
eE = extent.get_east()
eW = extent.get_west()
- eT = extent.get_top()
- eB = extent.get_bottom()
-
N = self.get_north()
S = self.get_south()
E = self.get_east()
@@ -1188,7 +1185,7 @@
def meet(self, extent):
"""!Return True if this extent meets with the provided spatial
extent in three dimensions.
-
+
@param extent The spatial extent
@return True or False
"""
@@ -1309,7 +1306,7 @@
def disjoint(self, extent):
"""!Return True if this extent is disjoint with the provided spatial
extent in three dimensions.
-
+
@param extent The spatial extent
@return True or False
"""
@@ -1334,7 +1331,7 @@
if self.meet(extent):
return False
-
+
return True
def spatial_relation_2d(self, extent):
@@ -1342,7 +1339,7 @@
extent and the provided spatial extent in two dimensions.
Spatial relations are:
-
+
- disjoint
- meet
- overlap
@@ -1351,7 +1348,7 @@
- in
- contain
- equivalent
-
+
Usage: see self.spatial_relation()
"""
@@ -1379,7 +1376,7 @@
extent and the provided spatial extent in three dimensions.
Spatial relations are:
-
+
- disjoint
- meet
- overlap
@@ -1388,12 +1385,12 @@
- in
- contain
- equivalent
-
-
+
+
Usage:
-
+
@code
-
+
>>> A = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
>>> B = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation(B)
@@ -1551,7 +1548,7 @@
>>> B = SpatialExtent(north=90, south=80, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation(B)
'meet'
-
+
@endcode
"""
@@ -1574,9 +1571,17 @@
return "unknown"
- def set_spatial_extent(self, north, south, east, west, top, bottom):
- """!Set the three dimensional spatial extent"""
+ def set_spatial_extent_from_values(self, north, south, east, west, top, bottom):
+ """!Set the three dimensional spatial extent
+ @param north The northern edge
+ @param south The southern edge
+ @param east The eastern edge
+ @param west The western edge
+ @param top The top edge
+ @param bottom The bottom edge
+ """
+
self.set_north(north)
self.set_south(south)
self.set_east(east)
@@ -1584,6 +1589,19 @@
self.set_top(top)
self.set_bottom(bottom)
+ def set_spatial_extent(self, spatial_extent):
+ """!Set the three dimensional spatial extent
+
+ @param spatial_extent An object of type SpatialExtent or its subclasses
+ """
+
+ self.set_north(spatial_extent.get_north())
+ self.set_south(spatial_extent.get_south())
+ self.set_east(spatial_extent.get_east())
+ self.set_west(spatial_extent.get_west())
+ self.set_top(spatial_extent.get_top())
+ self.set_bottom(spatial_extent.get_bottom())
+
def set_projection(self, proj):
"""!Set the projection of the spatial extent it should be XY or LL.
As default the projection is XY
@@ -1593,14 +1611,31 @@
else:
self.D["proj"] = proj
- def set_spatial_extent_2d(self, north, south, east, west):
- """!Set the two dimensional spatial extent"""
+ def set_spatial_extent_from_values_2d(self, north, south, east, west):
+ """!Set the two dimensional spatial extent from values
+ @param north The northern edge
+ @param south The southern edge
+ @param east The eastern edge
+ @param west The western edge
+ """
+
self.set_north(north)
self.set_south(south)
self.set_east(east)
self.set_west(west)
+ def set_spatial_extent_2d(self, spatial_extent):
+ """!Set the three dimensional spatial extent
+
+ @param spatial_extent An object of type SpatialExtent or its subclasses
+ """
+
+ self.set_north(spatial_extent.north)
+ self.set_south(spatial_extent.south)
+ self.set_east(spatial_extent.east)
+ self.set_west(spatial_extent.west)
+
def set_id(self, ident):
"""!Convenient method to set the unique identifier (primary key)"""
self.ident = ident
@@ -1662,7 +1697,7 @@
return self.D["proj"]
def get_volume(self):
- """!Compute the volume of the extent, in case z is zero
+ """!Compute the volume of the extent, in case z is zero
(top == bottom or top - bottom = 1) the area is returned"""
if self.get_projection() == "LL":
@@ -1695,7 +1730,7 @@
return x * y
def get_spatial_extent_as_tuple(self):
- """!Return a tuple (north, south, east, west, top, bottom)
+ """!Return a tuple (north, south, east, west, top, bottom)
of the spatial extent"""
return (
@@ -1754,7 +1789,7 @@
return self.D["bottom"]
else:
return None
-
+
id = property(fget=get_id, fset=set_id)
north = property(fget=get_north, fset=set_north)
south = property(fget=get_south, fset=set_south)
@@ -1787,37 +1822,37 @@
###############################################################################
class RasterSpatialExtent(SpatialExtent):
- def __init__(self, ident=None, north=None, south=None, east=None,
+ def __init__(self, ident=None, north=None, south=None, east=None,
west=None, top=None, bottom=None):
SpatialExtent.__init__(self, "raster_spatial_extent",
ident, north, south, east, west, top, bottom)
class Raster3DSpatialExtent(SpatialExtent):
- def __init__(self, ident=None, north=None, south=None, east=None,
+ def __init__(self, ident=None, north=None, south=None, east=None,
west=None, top=None, bottom=None):
SpatialExtent.__init__(self, "raster3d_spatial_extent",
ident, north, south, east, west, top, bottom)
class VectorSpatialExtent(SpatialExtent):
- def __init__(self, ident=None, north=None, south=None, east=None,
+ def __init__(self, ident=None, north=None, south=None, east=None,
west=None, top=None, bottom=None):
SpatialExtent.__init__(self, "vector_spatial_extent",
ident, north, south, east, west, top, bottom)
class STRDSSpatialExtent(SpatialExtent):
- def __init__(self, ident=None, north=None, south=None, east=None,
+ def __init__(self, ident=None, north=None, south=None, east=None,
west=None, top=None, bottom=None):
SpatialExtent.__init__(self, "strds_spatial_extent",
ident, north, south, east, west, top, bottom)
class STR3DSSpatialExtent(SpatialExtent):
- def __init__(self, ident=None, north=None, south=None, east=None,
+ def __init__(self, ident=None, north=None, south=None, east=None,
west=None, top=None, bottom=None):
SpatialExtent.__init__(self, "str3ds_spatial_extent",
ident, north, south, east, west, top, bottom)
class STVDSSpatialExtent(SpatialExtent):
- def __init__(self, ident=None, north=None, south=None, east=None,
+ def __init__(self, ident=None, north=None, south=None, east=None,
west=None, top=None, bottom=None):
SpatialExtent.__init__(self, "stvds_spatial_extent",
ident, north, south, east, west, top, bottom)
Modified: grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
===================================================================
--- grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py 2013-08-02 17:11:11 UTC (rev 57378)
+++ grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py 2013-08-02 19:29:58 UTC (rev 57379)
@@ -23,6 +23,9 @@
#%option G_OPT_STRDS_INPUT
#%end
+#%option G_OPT_STRDS_OUTPUT
+#%end
+
#%option G_OPT_T_WHERE
#%end
@@ -36,14 +39,6 @@
#%end
#%option
-#% key: output
-#% type: string
-#% description: Name of the output space time raster dataset
-#% required: yes
-#% multiple: no
-#%end
-
-#%option
#% key: method
#% type: string
#% description: Aggregate operation to be performed on the raster maps
@@ -53,7 +48,6 @@
#% answer: average
#%end
-
#%option G_OPT_R_BASE
#%end
Modified: grass/trunk/temporal/t.unregister/t.unregister.py
===================================================================
--- grass/trunk/temporal/t.unregister/t.unregister.py 2013-08-02 17:11:11 UTC (rev 57378)
+++ grass/trunk/temporal/t.unregister/t.unregister.py 2013-08-02 19:29:58 UTC (rev 57379)
@@ -162,7 +162,8 @@
count += 1
# Execute the collected SQL statenents
- dbif.execute_transaction(statement)
+ if statement:
+ dbif.execute_transaction(statement)
grass.percent(num_maps, num_maps, 1)
More information about the grass-commit
mailing list