Note: A new GRASS GIS stable version has been released: GRASS GIS 7.4. Go directly to the new manual page here
The abstract_dataset module provides the AbstractDataset class that is the base class for all map layer and Space Time Datasets.
(C) 2011-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: temporal.spatial_topology_dataset_connector.SpatialTopologyDatasetConnector, temporal.temporal_topology_dataset_connector.TemporalTopologyDatasetConnector
This is the base class for all datasets (raster, vector, raster3d, strds, stvds, str3ds)
Check if unit is of type year(s), month(s), day(s), hour(s), minute(s) or second(s)
Parameters: | unit – The unit string |
---|---|
Returns: | True if success, False otherwise |
Returns the start time, the end time of the map as tuple
The start time is of type datetime.
The end time is of type datetime in case of interval time, or None on case of a time instance.
Returns: | A tuple of (start_time, end_time) |
---|
Return the unique identifier of the dataset :return: The id of the dataset “name(:layer)@mapset” as string
Return the mapset :return: The mapset in which the dataset was created as string
Return a new instance with the type of this class
Parameters: | ident – The identifier of the new dataset instance |
---|---|
Returns: | A new instance with the type of this object |
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
- in
- contain
- meet
- cover
- covered
Temporal relations:
- equal
- follows
- precedes
- overlaps
- overlapped
- during (including starts, finishes)
- contains (including started, finished)
- starts
- started
- finishes
- finished
To access topological information the spatial, temporal or booth topologies must be build first using the SpatioTemporalTopologyBuilder.
Returns: | The dictionary with relations as keys and number as values or None in case the topology wasn’t build |
---|
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, or None on case of a time instance.
Returns: | A tuple of (start_time, end_time, unit) |
---|
Returns the relative time unit :return: The relative time unit as string, None if not present
Return the spatial extent as tuple
Top and bottom are set to 0 in case of a two dimensional spatial extent.
Returns: | A the spatial extent as tuple (north, south, east, west, top, bottom) |
---|
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.
Returns: | A tuple of (start_time, end_time) |
---|
Return the temporal type of this dataset
The temporal type can be absolute or relative
Returns: | The temporal type of the dataset as string |
---|
Return the type of this class as string
The type can be “vector”, “raster”, “raster3d”, “stvds”, “strds” or “str3ds”
Returns: | “vector”, “raster”, “raster3d”, “stvds”, “strds” or “str3ds” |
---|
Insert dataset into database
Parameters: |
|
---|---|
Returns: | The SQL insert statement in case execute=False, or an empty string otherwise |
Check if the dataset is registered in the database
Parameters: | dbif – The database interface to be used |
---|---|
Returns: | True if the dataset is registered in the database |
Return True if this class is a space time dataset
Returns: | True if this class is a space time dataset, False otherwise |
---|
Return True in case the temporal type is absolute
Returns: | True if temporal type is absolute, False otherwise |
---|
Return True in case the temporal type is relative
Returns: | True if temporal type is relative, False otherwise |
---|
Check if the spatial and temporal topology was build
Returns: | A dictionary with “spatial” and “temporal” as keys that have boolen values |
---|
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 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)
Parameters: | ident – The identifier of the dataset that “name@mapset” or in case of vector maps “name:layer@mapset” |
---|
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 from the temporal database.
Parameters: | dbif – The database interface to be used |
---|
Return the spatial union as spatial_extent object.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Return the spatial intersection as spatial_extent object or None in case no intersection was found.
Parameters: | dataset – The abstract dataset to intersect with |
---|---|
Returns: | The intersection spatial extent |
Return True if the spatial extents overlap
Parameters: | dataset – The abstract dataset to check spatial overlapping |
---|---|
Returns: | True if self and the provided dataset spatial overlap |
Return the spatial relationship between self and dataset
Parameters: | dataset – The abstract dataset to compute the spatial relation with self |
---|---|
Returns: | The spatial relationship as string |
Return the spatial union as spatial_extent object or None in case the extents does not overlap or meet.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Creates a union with the provided dataset and return a new temporal extent with the new start and end time.
Parameters: | dataset – The abstract dataset to create temporal union with |
---|---|
Returns: | The new temporal extent with start and end time |
Return the temporal extent of the correct internal type
Intersect self with the provided dataset and return a new temporal extent with the new start and end time
Parameters: | dataset – The abstract dataset to temporal intersect with |
---|---|
Returns: | The new temporal extent with start and end time, or None in case of no intersection |
Return the temporal relation of self and the provided dataset
Returns: | The temporal relation as string |
---|
Creates a union with the provided dataset and return a new temporal extent with the new start and end time.
Parameters: | dataset – The abstract dataset to create temporal union with |
---|---|
Returns: | The new temporal extent with start and end time, or None in case of no intersection |
Update the dataset entry in the database from the internal structure excluding None variables
Parameters: |
|
---|---|
Returns: | The SQL update statement in case execute=False, or an empty string otherwise |
Update the dataset entry in the database from the internal structure and include None variables.
Parameters: |
|
---|---|
Returns: | The SQL update statement in case execute=False, or an empty string otherwise |
Bases: object
This comparison key can be used to sort lists of abstract datasets by end time
Example:
# Return all maps in a space time raster dataset as map objects map_list = strds.get_registered_maps_as_objects() # Sort the maps in the list by end time sorted_map_list = sorted(map_list, key=AbstractDatasetComparisonKeyEndTime)
Bases: object
This comparison key can be used to sort lists of abstract datasets by start time
Example:
# Return all maps in a space time raster dataset as map objects map_list = strds.get_registered_maps_as_objects() # Sort the maps in the list by start time sorted_map_list = sorted(map_list, key=AbstractDatasetComparisonKeyStartTime)
The abstract_map_dataset module provides the AbstractMapDataset class that is the base class for all map layer.
(C) 2011-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: temporal.abstract_dataset.AbstractDataset
This is the base class for all maps (raster, vector, raster3d).
The temporal extent, the spatial extent and the metadata of maps are stored in the temporal database. Maps can be registered in the temporal database, updated and deleted.
This class provides all functionalities that are needed to manage maps in the temporal database. That are:
Add a new space time dataset to the register
Parameters: |
|
---|---|
Returns: | The SQL statements if execute=False, else an empty string |
Convenient method to build the unique identifier
Existing layer and mapset definitions in the name string will be reused
Parameters: |
|
---|---|
Returns: | the id of the map as “name(:layer)@mapset” while layer is optional |
Check if the raster or voxel resolution is finer than the current resolution
Vector maps have no resolution, since they store the coordinates directly.
Returns: | “finer” or “coarser” |
---|
Delete a map entry from database if it exists
Remove dependent entries:
- Remove the map entry in each space time dataset in which this map is registered
- Remove the space time dataset register table
Parameters: |
|
---|---|
Returns: | The SQL statements if execute=False, else an empty string, None in case of a failure |
Return the layer of the map
Returns: | the layer of the map or None in case no layer is defined |
---|
Return the map id. The map id is the unique identifier in grass and must not be equal to the primary key identifier (id) of the map in the database. Since vector maps may have layer information, the unique id is a combination of name, layer and mapset.
Use get_map_id() every time your need to access the grass map in the file system but not to identify map information in the temporal database.
Returns: | The map id “name@mapset“ |
---|
Return a new space time dataset instance that store maps with the type of this map object (raster, raster_3d or vector)
:param ident The identifier of the space time dataset :return: The new space time dataset instance
Return all space time dataset ids in which this map is registered as as a list of strings, or None if this map is not registered in any space time dataset.
Parameters: | dbif – The database interface to be used |
---|---|
Returns: | A list of ids of all space time datasets in which this map is registered |
Check if a grass file based time stamp exists for this map.
Returns: | True is the grass file based time stamped exists for this map |
---|
Insert the map content into the database from the internal structure
This functions assures that the timestamp is written to the grass file system based database in addition to the temporal database entry. The stds register table will be created as well. Hence maps can only be registered in a space time dataset, when they were inserted in the temporal database beforehand.
Parameters: |
|
---|---|
Returns: | The SQL insert statement in case execute=False, or an empty string otherwise |
Return True in case the map exists in the grass spatial database
Returns: | True if map exists, False otherwise |
---|
Read the timestamp of this map from the map metadata in the grass file system based spatial database and set the internal time stamp that should be insert/updated in the temporal database.
Remove a space time dataset from the register
Parameters: |
|
---|---|
Returns: | The SQL statements if execute=False, else an empty string |
Remove the timestamp from the grass file system based spatial database
Set the absolute time with start time and end time
The end time is optional and must be set to None in case of time instance.
This method only modifies this object and does not commit the modifications to the temporal database.
Parameters: |
|
---|---|
Returns: | True for success and False otherwise |
Set the relative time interval
The end time is optional and must be set to None in case of time instance.
This method only modifies this object and does not commit the modifications to the temporal database.
Parameters: |
|
---|---|
Returns: | True for success and False otherwise |
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
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.
Parameters: |
|
---|
Convenient method to set the temporal extent from a temporal extent object
Parameters: | temporal_extent – The temporal extent that should be set for this object |
---|
Buffer the spatial extent by a given size in all spatial directions.
Parameters: | size – The buffer size, using the unit of the grass region |
---|
Buffer the spatial extent by a given size in 2d spatial directions.
Parameters: | size – The buffer size, using the unit of the grass region |
---|
Create a temporal buffer based on an increment
For absolute time the increment must be a string of type “integer unit” Unit can be year, years, month, months, day, days, hour, hours, minute, minutes, day or days.
Parameters: |
|
---|
Usage:
Remove the map entry in each space time dataset in which this map is registered
Parameters: |
|
---|---|
Returns: | The SQL statements if execute=False, else an empty string |
Update the map content in the database from the internal structure excluding None variables
This functions assures that the timestamp is written to the grass file system based database in addition to the temporal database entry.
Parameters: |
|
---|---|
Returns: | The SQL insert statement in case execute=False, or an empty string otherwise |
Update the absolute time
The end time is optional and must be set to None in case of time instance.
This functions assures that the timestamp is written to the grass file system based database in addition to the temporal database entry.
Parameters: |
|
---|
Update the map content in the database from the internal structure including None variables
This functions assures that the timestamp is written to the grass file system based database in addition to the temporal database entry.
Parameters: |
|
---|---|
Returns: | The SQL insert statement in case execute=False, or an empty string otherwise |
Update the relative time interval
The end time is optional and must be set to None in case of time instance.
This functions assures that the timestamp is written to the grass file system based database in addition to the temporal database entry.
Parameters: |
|
---|
The abstract_space_time_dataset module provides the AbstractSpaceTimeDataset class that is the base class for all space time datasets.
(C) 2011-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: temporal.abstract_dataset.AbstractDataset
Abstract space time dataset class
Base class for all space time datasets.
This class represents an abstract space time dataset. Convenient functions to select, update, insert or delete objects of this type in the SQL temporal database exists as well as functions to register or unregister raster maps.
Parts of the temporal logic are implemented in the SQL temporal database, like the computation of the temporal and spatial extent as well as the collecting of metadata.
Check the temporal topology of all maps of the current space time dataset or of an optional list of maps
Correct topology means, that time intervals are not overlap or that intervals does not contain other intervals. Equal time intervals are not allowed.
The optional map list must be ordered by start time
Allowed and not allowed temporal relationships for correct topology:
Parameters: |
|
---|---|
Returns: | True if topology is correct |
Count the number of gaps between temporal neighbors
Parameters: |
|
---|---|
Returns: | The numbers of gaps between temporal neighbors |
Count the temporal relations between the registered maps.
The map list must be ordered by start time. Temporal relations are counted by analysing the sparse upper right side temporal relationships matrix.
Parameters: |
|
---|---|
Returns: | A dictionary with counted temporal relationships |
Return the temporal type of the registered maps as dictionary
The map list must be ordered by start time
The temporal type can be:
Parameters: |
|
---|
Create the command string that was used to create this space time dataset.
The command string should be set with self.metadata.set_command()
Returns: | The command string |
---|
Create the name of the map register table of this space time dataset
A uuid and the map type are used to create the table name
ATTENTION: It must be assured that the base object has selected its content from the database.
Returns: | The name of the map register table |
---|
Delete a space time dataset from the temporal database
This method removes the space time dataset from the temporal database and drops its map register table
Parameters: |
|
---|---|
Returns: | The SQL statements if execute == False, else an empty string |
Return the granularity of the space time dataset
Granularity can be of absolute time or relative time. In case of absolute time a string containing an integer value and the time unit (years, months, days, hours, minuts, seconds). In case of relative time an integer value is expected.
Returns: | The granularity |
---|
Return the initial values: temporal_type, semantic_type, title, description
Return the name of the map register table :return: The map register table name
Return a new instance of a map which is associated with the type of this object
Parameters: | ident – The unique identifier of the new object |
---|
Return SQL rows of all registered maps.
In case columns are not specified, each row includes all columns specified in the datatype specific view.
Parameters: |
|
---|---|
Returns: | SQL rows of all registered maps, In case nothing found None is returned |
Return all or a subset of the registered maps as ordered object list for spatio-temporal topological operations that require the spatio-temporal extent only
The objects are initialized with their id’s‘ and the spatio-temporal extent (temporal type, start time, end time, west, east, south, north, bottom and top). In case more map information are needed, use the select() method for each listed object.
Parameters: |
|
---|---|
Returns: | The ordered map object list, In case nothing found None is returned |
Return all registered maps as ordered (by start_time) object list with “gap” map objects (id==None) for spatio-temporal topological operations that require the temporal extent only.
Each list entry is a list of AbstractMapDatasets objects which are potentially equal the actual granule, contain the actual granule or are located in the actual granule. Hence for each granule a list of AbstractMapDatasets can be expected.
Maps that overlap the granule are ignored.
The granularity of the space time dataset is used as increment in case the granule is not user defined.
A valid temporal topology (no overlapping or inclusion allowed) is needed to get correct results.
Space time datasets with interval time, time instances and mixed time are supported.
Gaps between maps are identified as unregistered maps with id==None.
The objects are initialized with their id’s‘ and the spatio-temporal extent (temporal type, start time, end time, west, east, south, north, bottom and top). In case more map information are needed, use the select() method for each listed object.
Parameters: |
|
---|---|
Returns: | ordered list of map lists. Each list represents a single granule, or None in case nothing found |
Return all or a subset of the registered maps as ordered (by start_time) object list with “gap” map objects (id==None) for spatio-temporal topological operations that require the spatio-temporal extent only.
Gaps between maps are identified as maps with id==None
The objects are initialized with their id’s‘ and the spatio-temporal extent (temporal type, start time, end time, west, east, south, north, bottom and top). In case more map information are needed, use the select() method for each listed object.
Parameters: |
|
---|---|
Returns: | ordered object list, in case nothing found None is returned |
Return all or a subset of the registered maps as ordered object list with spatio-temporal topological relationship information.
The objects are initialized with their id’s‘ and the spatio-temporal extent (temporal type, start time, end time, west, east, south, north, bottom and top). In case more map information are needed, use the select() method for each listed object.
Parameters: |
|
---|---|
Returns: | The ordered map object list, In case nothing found None is returned |
Insert the space time dataset content into the database from the internal structure
The map register table will be created, so that maps can be registered.
Parameters: |
|
---|---|
Returns: | The SQL insert statement in case execute=False, or an empty string otherwise |
Check if a map is registered in the space time dataset
Parameters: |
|
---|---|
Returns: | True if success, False otherwise |
Print the spatio-temporal relationships for each map of the space time dataset or for each map of the optional list of maps
Parameters: |
|
---|
Register a map in the space time dataset.
This method takes care of the registration of a map in a space time dataset.
In case the map is already registered this function will break with a warning and return False.
This method raises a FatalError exception in case of a fatal error
Parameters: |
|
---|---|
Returns: | True if success, False otherwise |
Rename the space time dataset
This method renames the space time dataset, the map register table and updates the entries in registered maps stds register.
Renaming does not work with Postgresql yet.
Parameters: |
|
---|
Resample a list of AbstractMapDatasets by a given granularity
The provided map list must be sorted by start time. A valid temporal topology (no overlapping or inclusion allowed) is needed to receive correct results.
Maps with interval time, time instances and mixed time are supported.
The temporal topology search order is as follows:
Each entry in the resulting list is a list of AbstractMapDatasets objects. Hence for each granule a list of AbstractMapDatasets can be expected.
Gaps between maps are identified as unregistered maps with id==None.
Parameters: |
|
---|---|
Returns: | ordered list of map lists. Each list represents a single granule, or None in case nothing found |
Usage:
>>> import grass.temporal as tgis >>> maps = [] >>> for i in xrange(3): ... map = tgis.RasterDataset("map%i@PERMANENT"%i) ... check = map.set_relative_time(i + 2, i + 3, "days") ... maps.append(map) >>> grans = tgis.AbstractSpaceTimeDataset.resample_maplist_by_granularity(maps,0,8,1) >>> for map_list in grans: ... print map_list[0].get_id(), map_list[0].get_temporal_extent_as_tuple() None (0, 1) None (1, 2) map0@PERMANENT (2, 3) map1@PERMANENT (3, 4) map2@PERMANENT (4, 5) None (5, 6) None (6, 7) None (7, 8) >>> maps = [] >>> map1 = tgis.RasterDataset("map1@PERMANENT") >>> check = map1.set_relative_time(2, 6, "days") >>> maps.append(map1) >>> map2 = tgis.RasterDataset("map2@PERMANENT") >>> check = map2.set_relative_time(7, 13, "days") >>> maps.append(map2) >>> grans = tgis.AbstractSpaceTimeDataset.resample_maplist_by_granularity(maps,0,16,2) >>> for map_list in grans: ... print map_list[0].get_id(), map_list[0].get_temporal_extent_as_tuple() None (0, 2) map1@PERMANENT (2, 4) map1@PERMANENT (4, 6) map2@PERMANENT (6, 8) map2@PERMANENT (8, 10) map2@PERMANENT (10, 12) map2@PERMANENT (12, 14) None (14, 16) >>> maps = [] >>> map1 = tgis.RasterDataset("map1@PERMANENT") >>> check = map1.set_relative_time(2, None, "days") >>> maps.append(map1) >>> map2 = tgis.RasterDataset("map2@PERMANENT") >>> check = map2.set_relative_time(7, None, "days") >>> maps.append(map2) >>> grans = tgis.AbstractSpaceTimeDataset.resample_maplist_by_granularity(maps,0,16,2) >>> for map_list in grans: ... print map_list[0].get_id(), map_list[0].get_temporal_extent_as_tuple() None (0, 2) map1@PERMANENT (2, 4) None (4, 6) map2@PERMANENT (6, 8) None (8, 10) None (10, 12) None (12, 14) None (14, 16) >>> maps = [] >>> map1 = tgis.RasterDataset("map1@PERMANENT") >>> check = map1.set_absolute_time(datetime(2000, 4,1), datetime(2000, 6, 1)) >>> maps.append(map1) >>> map2 = tgis.RasterDataset("map2@PERMANENT") >>> check = map2.set_absolute_time(datetime(2000, 8,1), datetime(2000, 12, 1)) >>> maps.append(map2) >>> grans = tgis.AbstractSpaceTimeDataset.resample_maplist_by_granularity(maps,datetime(2000,1,1),datetime(2001,4,1),"1 month") >>> for map_list in grans: ... print map_list[0].get_id(), map_list[0].get_temporal_extent_as_tuple() None (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2000, 2, 1, 0, 0)) None (datetime.datetime(2000, 2, 1, 0, 0), datetime.datetime(2000, 3, 1, 0, 0)) None (datetime.datetime(2000, 3, 1, 0, 0), datetime.datetime(2000, 4, 1, 0, 0)) map1@PERMANENT (datetime.datetime(2000, 4, 1, 0, 0), datetime.datetime(2000, 5, 1, 0, 0)) map1@PERMANENT (datetime.datetime(2000, 5, 1, 0, 0), datetime.datetime(2000, 6, 1, 0, 0)) None (datetime.datetime(2000, 6, 1, 0, 0), datetime.datetime(2000, 7, 1, 0, 0)) None (datetime.datetime(2000, 7, 1, 0, 0), datetime.datetime(2000, 8, 1, 0, 0)) map2@PERMANENT (datetime.datetime(2000, 8, 1, 0, 0), datetime.datetime(2000, 9, 1, 0, 0)) map2@PERMANENT (datetime.datetime(2000, 9, 1, 0, 0), datetime.datetime(2000, 10, 1, 0, 0)) map2@PERMANENT (datetime.datetime(2000, 10, 1, 0, 0), datetime.datetime(2000, 11, 1, 0, 0)) map2@PERMANENT (datetime.datetime(2000, 11, 1, 0, 0), datetime.datetime(2000, 12, 1, 0, 0)) None (datetime.datetime(2000, 12, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0)) None (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2001, 2, 1, 0, 0)) None (datetime.datetime(2001, 2, 1, 0, 0), datetime.datetime(2001, 3, 1, 0, 0)) None (datetime.datetime(2001, 3, 1, 0, 0), datetime.datetime(2001, 4, 1, 0, 0))
Sample this space time dataset with the temporal topology of a second space time dataset
In case spatial is True, the spatial overlap between temporal related maps is performed. Only temporal related and spatial overlapping maps are returned.
Return all registered maps as ordered (by start_time) object list. Each list entry is a list of map objects which are potentially located in temporal relation to the actual granule of the second space time dataset.
Each entry in the object list is a dict. The actual sampler map and its temporal extent (the actual granule) and the list of samples are stored:
list = self.sample_by_dataset(stds=sampler, method=[
"during","overlap","contains","equal"])
for entry in list:
granule = entry["granule"]
maplist = entry["samples"]
for map in maplist:
map.select()
map.print_info()
A valid temporal topology (no overlapping or inclusion allowed) is needed to get correct results in case of gaps in the sample dataset.
Gaps between maps are identified as unregistered maps with id==None.
The objects are initialized with their id’s‘ and the spatio-temporal extent (temporal type, start time, end time, west, east, south, north, bottom and top). In case more map information are needed, use the select() method for each listed object.
Parameters: |
|
---|---|
Returns: | A list of lists of map objects or None in case nothing was found None |
Sample this space time dataset with the temporal topology of a second space time dataset using SQL queries.
This function is very slow for huge large space time datasets but can run several times in the same process without problems.
The sample dataset must have “interval” as temporal map type, so all sample maps have valid interval time.
In case spatial is True, the spatial overlap between temporal related maps is performed. Only temporal related and spatial overlapping maps are returned.
Return all registered maps as ordered (by start_time) object list with “gap” map objects (id==None). Each list entry is a list of map objects which are potentially located in temporal relation to the actual granule of the second space time dataset.
Each entry in the object list is a dict. The actual sampler map and its temporal extent (the actual granule) and the list of samples are stored:
list = self.sample_by_dataset(stds=sampler, method=[
"during","overlap","contain","equal"])
for entry in list:
granule = entry["granule"]
maplist = entry["samples"]
for map in maplist:
map.select()
map.print_info()
A valid temporal topology (no overlapping or inclusion allowed) is needed to get correct results in case of gaps in the sample dataset.
Gaps between maps are identified as unregistered maps with id==None.
The objects are initialized with their id’s‘ and the spatio-temporal extent (temporal type, start time, end time, west, east, south, north, bottom and top). In case more map information are needed, use the select() method for each listed object.
Parameters: |
|
---|---|
Returns: | A list of lists of map objects or None in case nothing was found None |
Set the aggregation type of the space time dataset
Parameters: | aggregation_type – The aggregation type of the space time dataset |
---|
Set the granularity
The granularity is usually computed by the space time dataset at runtime.
Granularity can be of absolute time or relative time. In case of absolute time a string containing an integer value and the time unit (years, months, days, hours, minuts, seconds). In case of relative time an integer value is expected.
This method only modifies this object and does not commit the modifications to the temporal database.
Parameters: | granularity – The granularity of the dataset |
---|
Set the initial values of the space time dataset
In addition the command creation string is generated an inserted into the metadata object.
This method only modifies this object and does not commit the modifications to the temporal database.
The insert() function must be called to commit this content into the temporal database.
Parameters: |
|
---|
Set the name of the map register table
This table stores all map names which are registered in this space time dataset.
This method only modifies this object and does not commit the modifications to the temporal database.
Parameters: | name – The name of the register table |
---|
Set the relative time unit which may be of type: years, months, days, hours, minutes or seconds
All maps registered in a (relative time) space time dataset must have the same unit
This method only modifies this object and does not commit the modifications to the temporal database.
Parameters: | unit – The relative time unit |
---|
Temporally shift each registered map with the provided granularity
Parameters: |
|
---|---|
Returns: | True something to shift, False if nothing to shift or wrong granularity |
Temporally shift each map in the list with the provided granularity
This method does not perform any temporal database operations.
Parameters: |
|
---|---|
Returns: | The modified map list, None if nothing to shift or wrong granularity |
>>> import grass.temporal as tgis
>>> maps = []
>>> for i in range(5):
... map = tgis.RasterDataset(None)
... if i%2 == 0:
... check = map.set_relative_time(i, i + 1, 'years')
... else:
... check = map.set_relative_time(i, None, 'years')
... maps.append(map)
>>> for map in maps:
... map.temporal_extent.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 0
| End time:................... 1
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 1
| End time:................... None
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 2
| End time:................... 3
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 3
| End time:................... None
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 4
| End time:................... 5
| Relative time unit:......... years
>>> maps = tgis.AbstractSpaceTimeDataset.shift_map_list(maps, 5)
>>> for map in maps:
... map.temporal_extent.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 5
| End time:................... 6
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 6
| End time:................... None
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 7
| End time:................... 8
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 8
| End time:................... None
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 9
| End time:................... 10
| Relative time unit:......... years
For each registered map snap the end time to the start time of its temporal nearest neighbor in the future
Maps with equal time stamps are not snapped
Parameters: | dbif – The database interface to be used |
---|
For each map in the list snap the end time to the start time of its temporal nearest neighbor in the future.
Maps with equal time stamps are not snapped.
The granularity of the map list will be used to create the end time of the last map in case it has a time instance as timestamp.
This method does not perform any temporal database operations.
Parameters: | maps – A list of maps with initialized temporal extent |
---|---|
Returns: | The modified map list, None nothing to shift or wrong granularity |
Usage:
>>> import grass.temporal as tgis
>>> maps = []
>>> for i in range(5):
... map = tgis.RasterDataset(None)
... if i%2 == 0:
... check = map.set_relative_time(i, i + 1, 'years')
... else:
... check = map.set_relative_time(i, None, 'years')
... maps.append(map)
>>> for map in maps:
... map.temporal_extent.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 0
| End time:................... 1
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 1
| End time:................... None
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 2
| End time:................... 3
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 3
| End time:................... None
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 4
| End time:................... 5
| Relative time unit:......... years
>>> maps = tgis.AbstractSpaceTimeDataset.snap_map_list(maps)
>>> for map in maps:
... map.temporal_extent.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 0
| End time:................... 1
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 1
| End time:................... 2
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 2
| End time:................... 3
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 3
| End time:................... 4
| Relative time unit:......... years
+-------------------- Relative time -----------------------------------------+
| Start time:................. 4
| End time:................... 5
| Relative time unit:......... years
Unregister a map from the space time dataset.
This method takes care of the un-registration of a map from a space time dataset.
Parameters: |
|
---|---|
Returns: | The SQL statements if execute == False, else an empty string, None in case of a failure |
Append the current command string to any existing command string in the metadata class and calls metadata update
Parameters: | dbif – The database interface to be used |
---|
This methods updates the modification time, the spatial and temporal extent as well as type specific metadata. It should always been called after maps are registered or unregistered/deleted from the space time dataset.
The update of the temporal extent checks if the end time is set correctly. In case the registered maps have no valid end time (None) the maximum start time will be used. If the end time is earlier than the maximum start time, it will be replaced by the maximum start time.
Parameters: | dbif – The database interface to be used |
---|
Aggregation methods for space time raster datasets
Usage:
import grass.temporal as tgis
tgis.aggregate_raster_maps(dataset, mapset, inputs, base, start, end, count, method, register_null, dbif)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
author: | Soeren Gebbert |
---|
Aggregate a list of raster input maps with r.series
Parameters: |
|
---|---|
Returns: | A list of RasterDataset objects that contain the new map names and the temporal extent for map registration |
Aggregate a list of raster input maps with r.series
Parameters: |
|
---|
Gather all maps from dataset using a specific sample method
Parameters: |
|
---|
This packages includes all base classes to store basic information like id, name, mapset creation and modification time as well as sql serialization and de-serialization and the sql database interface.
Usage:
>>> import grass.temporal as tgis
>>> tgis.init()
>>> rbase = tgis.RasterBase(ident="soil@PERMANENT")
>>> vbase = tgis.VectorBase(ident="soil:1@PERMANENT")
>>> r3base = tgis.Raster3DBase(ident="soil@PERMANENT")
>>> strdsbase = tgis.STRDSBase(ident="soil@PERMANENT")
>>> stvdsbase = tgis.STVDSBase(ident="soil@PERMANENT")
>>> str3dsbase = tgis.STR3DSBase(ident="soil@PERMANENT")
(C) 2011-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
author: | Soeren Gebbert |
---|
Bases: temporal.base.SQLDatabaseInterface
This is the base class for all maps to store the space time datasets as comma separated string in which they are registered
Usage:
>>> init() >>> t = AbstractSTDSRegister("raster", "soil@PERMANENT", "A@P,B@P,C@P") >>> t.id 'soil@PERMANENT' >>> t.registered_stds 'A@P,B@P,C@P'
Convenient method to get the unique identifier (primary key)
Returns: | None if not found |
---|
Get the comma separated list of space time datasets ids in which this map is registered
Returns: | None if not found |
---|
Convenient method to get the unique identifier (primary key)
Returns: | None if not found |
---|
Get the comma separated list of space time datasets ids in which this map is registered
Returns: | None if not found |
---|
Convenient method to set the unique identifier (primary key)
Parameters: | ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” |
---|
Bases: temporal.base.SQLDatabaseInterface
This is the base class for all maps and spacetime datasets storing basic identification information
Usage:
>>> init()
>>> t = DatasetBase("raster", "soil@PERMANENT", creator="soeren", ctime=datetime(2001,1,1), ttype="absolute")
>>> t.id
'soil@PERMANENT'
>>> t.name
'soil'
>>> t.mapset
'PERMANENT'
>>> t.creator
'soeren'
>>> t.ctime
datetime.datetime(2001, 1, 1, 0, 0)
>>> t.ttype
'absolute'
>>> t.print_info()
+-------------------- Basic information -------------------------------------+
| Id: ........................ soil@PERMANENT
| Name: ...................... soil
| Mapset: .................... PERMANENT
| Creator: ................... soeren
| Temporal type: ............. absolute
| Creation time: ............. 2001-01-01 00:00:00
>>> t.print_shell_info()
id=soil@PERMANENT
name=soil
mapset=PERMANENT
creator=soeren
temporal_type=absolute
creation_time=2001-01-01 00:00:00
Get the creator of the dataset :return: None if not found
Get the creation time of the dataset, datatype is datetime :return: None if not found
Get the creation time of the dataset, datatype is datetime :return: None if not found
Convenient method to get the unique identifier (primary key)
Returns: | None if not found |
---|
Convenient method to get the layer of the map (part of primary key)
Layer are currently supported for vector maps
Returns: | None if not found |
---|
Convenient method to get the unique map identifier without layer information
Returns: | the name of the vector map as “name@mapset” or None in case the id was not set |
---|
Convenient method to get the unique identifier (primary key)
Returns: | None if not found |
---|
Convenient method to get the unique map identifier without layer information
Returns: | the name of the vector map as “name@mapset” or None in case the id was not set |
---|
Get the name of mapset of this dataset :return: None if not found
Get the name of the dataset :return: None if not found
Set the creator of the dataset
Parameters: | creator – The name of the creator |
---|
Set the creation time of the dataset, if nothing set the current time is used
Parameters: | ctime – The current time of type datetime |
---|
Convenient method to set the unique identifier (primary key)
Parameters: | ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” |
---|
Convenient method to set the layer of the map (part of primary key)
Layer are supported for vector maps
Parameters: | layer – The layer of the map |
---|
Set the mapset of the dataset
Parameters: | mapset – The name of the mapset in which this dataset is stored |
---|
Set the temporal type of the dataset: absolute or relative, if nothing set absolute time will assumed
Parameters: | ttype – The temporal type of the dataset “absolute or relative” |
---|
Get the temporal type of the map :return: None if not found
Bases: object
Convert the content of the dbmi dictionary like row into the internal dictionary
Parameters: | row – The dictionary like row to store in the internal dict |
---|
Convert the internal dictionary into a string of semicolon separated SQL statements The keys are the column names and the values are the row entries
Usage:
>>> init()
>>> t = DictSQLSerializer()
>>> t.D["id"] = "soil@PERMANENT"
>>> t.D["name"] = "soil"
>>> t.D["mapset"] = "PERMANENT"
>>> t.D["creator"] = "soeren"
>>> t.D["creation_time"] = datetime(2001,1,1)
>>> t.D["modification_time"] = datetime(2001,1,1)
>>> t.serialize(type="SELECT", table="raster_base")
('SELECT name , creator , creation_time , modification_time , mapset , id FROM raster_base ;\n', ())
>>> t.serialize(type="INSERT", table="raster_base")
('INSERT INTO raster_base ( name ,creator ,creation_time ,modification_time ,mapset ,id ) VALUES (? ,? ,? ,? ,? ,?) ;\n', ('soil', 'soeren', datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0), 'PERMANENT', 'soil@PERMANENT'))
>>> t.serialize(type="UPDATE", table="raster_base")
('UPDATE raster_base SET name = ? ,creator = ? ,creation_time = ? ,modification_time = ? ,mapset = ? ,id = ? ;\n', ('soil', 'soeren', datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0), 'PERMANENT', 'soil@PERMANENT'))
>>> t.serialize(type="UPDATE ALL", table="raster_base")
('UPDATE raster_base SET name = ? ,creator = ? ,creation_time = ? ,modification_time = ? ,mapset = ? ,id = ? ;\n', ('soil', 'soeren', datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0), 'PERMANENT', 'soil@PERMANENT'))
:param type: must be SELECT. INSERT, UPDATE
:param table: The name of the table to select, insert or update
:param where: The optional where statement
:return: a tuple containing the SQL string and the arguments
Bases: temporal.base.DatasetBase
Time stamped 3D raster map base information class
Bases: temporal.base.AbstractSTDSRegister
Time stamped 3D raster map base information class
Bases: temporal.base.DatasetBase
Time stamped raster map base information class
Bases: temporal.base.AbstractSTDSRegister
Time stamped raster map base information class
Bases: temporal.base.DictSQLSerializer
This class represents the SQL database interface
Functions to insert, select and update the internal structure of this class in the temporal database are implemented. This is the base class for raster, raster3d, vector and space time datasets data management classes:
Usage:
>>> init()
>>> t = SQLDatabaseInterface("raster", "soil@PERMANENT")
>>> t.mapset = get_current_mapset()
>>> t.D["name"] = "soil"
>>> t.D["mapset"] = "PERMANENT"
>>> t.D["creator"] = "soeren"
>>> t.D["creation_time"] = datetime(2001,1,1)
>>> t.get_delete_statement()
"DELETE FROM raster WHERE id = 'soil@PERMANENT';\n"
>>> t.get_is_in_db_statement()
"SELECT id FROM raster WHERE id = 'soil@PERMANENT';\n"
>>> t.get_select_statement()
("SELECT creation_time , mapset , name , creator FROM raster WHERE id = 'soil@PERMANENT';\n", ())
>>> t.get_select_statement_mogrified()
"SELECT creation_time , mapset , name , creator FROM raster WHERE id = 'soil@PERMANENT';\n"
>>> t.get_insert_statement()
('INSERT INTO raster ( creation_time ,mapset ,name ,creator ) VALUES (? ,? ,? ,?) ;\n', (datetime.datetime(2001, 1, 1, 0, 0), 'PERMANENT', 'soil', 'soeren'))
>>> t.get_insert_statement_mogrified()
"INSERT INTO raster ( creation_time ,mapset ,name ,creator ) VALUES ('2001-01-01 00:00:00' ,'PERMANENT' ,'soil' ,'soeren') ;\n"
>>> t.get_update_statement()
("UPDATE raster SET creation_time = ? ,mapset = ? ,name = ? ,creator = ? WHERE id = 'soil@PERMANENT';\n", (datetime.datetime(2001, 1, 1, 0, 0), 'PERMANENT', 'soil', 'soeren'))
>>> t.get_update_statement_mogrified()
"UPDATE raster SET creation_time = '2001-01-01 00:00:00' ,mapset = 'PERMANENT' ,name = 'soil' ,creator = 'soeren' WHERE id = 'soil@PERMANENT';\n"
>>> t.get_update_all_statement()
("UPDATE raster SET creation_time = ? ,mapset = ? ,name = ? ,creator = ? WHERE id = 'soil@PERMANENT';\n", (datetime.datetime(2001, 1, 1, 0, 0), 'PERMANENT', 'soil', 'soeren'))
>>> t.get_update_all_statement_mogrified()
"UPDATE raster SET creation_time = '2001-01-01 00:00:00' ,mapset = 'PERMANENT' ,name = 'soil' ,creator = 'soeren' WHERE id = 'soil@PERMANENT';\n"
Delete the entry of this object from the temporal database
Parameters: | dbif – The database interface to be used, if None a temporary connection will be established |
---|
Return the sql statement and the argument list in database specific style :return: The INSERT string
Return the insert statement as mogrified string
Parameters: | dbif – The database interface to be used, if None a temporary connection will be established |
---|---|
Returns: | The INSERT string |
Return the selection string that checks if this object is registered in the temporal database :return: The SELECT string
Return the sql statement and the argument list in database specific style :return: The SELECT string
Return the select statement as mogrified string
Parameters: | dbif – The database interface to be used, if None a temporary connection will be established |
---|---|
Returns: | The SELECT string |
Return the name of the table in which the internal data are inserted, updated or selected :return: The name of the table
Return the sql statement and the argument list in database specific style
Parameters: | ident – The identifier to be updated, useful for renaming |
---|---|
Returns: | The UPDATE string |
Return the update all statement as mogrified string
Parameters: |
|
---|---|
Returns: | The UPDATE string |
Return the sql statement and the argument list in database specific style
Parameters: | ident – The identifier to be updated, useful for renaming |
---|---|
Returns: | The UPDATE string |
Return the update statement as mogrified string
Parameters: |
|
---|---|
Returns: | The UPDATE string |
Serialize the content of this object and store it in the temporal database using the internal identifier
Parameters: | dbif – The database interface to be used, if None a temporary connection will be established |
---|
Check if this object is present in the temporal database
Parameters: | dbif – The database interface to be used, if None a temporary connection will be established |
---|---|
Returns: | True if this object is present in the temporal database, False otherwise |
Select the content from the temporal database and store it in the internal dictionary structure
Parameters: | dbif – The database interface to be used, if None a temporary connection will be established |
---|
Serialize the content of this object and update it in the temporal database using the internal identifier
Only object entries which are exists (not None) are updated
Parameters: |
|
---|
Serialize the content of this object, including None objects, and update it in the temporal database using the internal identifier
param dbif: The database interface to be used, if None a temporary connection will be established param ident: The identifier to be updated, useful for renaming
Bases: temporal.base.DatasetBase
Base class for space time datasets
This class adds the semantic type member variable to the dataset base class.
Usage:
>>> init()
>>> t = STDSBase("stds", "soil@PERMANENT", semantic_type="average", creator="soeren", ctime=datetime(2001,1,1), ttype="absolute", mtime=datetime(2001,1,1))
>>> t.semantic_type
'average'
>>> t.print_info()
+-------------------- Basic information -------------------------------------+
| Id: ........................ soil@PERMANENT
| Name: ...................... soil
| Mapset: .................... PERMANENT
| Creator: ................... soeren
| Temporal type: ............. absolute
| Creation time: ............. 2001-01-01 00:00:00
| Modification time:.......... 2001-01-01 00:00:00
| Semantic type:.............. average
>>> t.print_shell_info()
id=soil@PERMANENT
name=soil
mapset=PERMANENT
creator=soeren
temporal_type=absolute
creation_time=2001-01-01 00:00:00
modification_time=2001-01-01 00:00:00
semantic_type=average
Get the modification time of the space time dataset, datatype is datetime
Returns: | None if not found |
---|
Get the semantic type of the space time dataset :return: None if not found
Get the semantic type of the space time dataset :return: None if not found
Bases: temporal.base.STDSBase
Space time 3D raster dataset base information class
Bases: temporal.base.STDSBase
Space time raster dataset base information class
Bases: temporal.base.STDSBase
Space time vector dataset base information class
Bases: temporal.base.DatasetBase
Time stamped vector map base information class
Bases: temporal.base.AbstractSTDSRegister
Time stamped vector map base information class
Fast and exit-safe interface to GRASS C-library functions using ctypes and multiprocessing
(C) 2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: object
Fast and exit-safe interface to GRASS C-libraries functions
This class implements a fast and exit-safe interface to the GRASS gis, raster, 3D raster and vector C-libraries functions.
The C-libraries functions are called via ctypes in a subprocess using a pipe (multiprocessing.Pipe) to transfer the text messages. Hence, the process that uses the CLibrariesInterface will not be exited, if a G_fatal_error() was invoked in the subprocess. In this case the CLibrariesInterface object will simply start a new subprocess and restarts the pipeline.
Usage:
>>> import grass.script as gscript
>>> import grass.temporal as tgis
>>> gscript.use_temp_region()
>>> gscript.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, res3=10.0)
0
>>> tgis.init()
>>> gscript.run_command("r.mapcalc", expression="test = 1", overwrite=True, quiet=True)
0
>>> gscript.run_command("r3.mapcalc", expression="test = 1", overwrite=True, quiet=True)
0
>>> gscript.run_command("v.random", output="test", n=10, overwrite=True, quiet=True)
0
>>> gscript.run_command("r.timestamp", map="test", date='12 Mar 1995 10:34:40', overwrite=True, quiet=True)
0
>>> gscript.run_command("r3.timestamp", map="test", date='12 Mar 1995 10:34:40', overwrite=True, quiet=True)
0
>>> gscript.run_command("v.timestamp", map="test", date='12 Mar 1995 10:34:40', overwrite=True, quiet=True)
0
# Check mapsets
>>> ciface = tgis.CLibrariesInterface()
>>> mapsets = ciface.available_mapsets()
>>> mapsets[0] == tgis.get_current_mapset()
True
# Raster map
>>> ciface = tgis.CLibrariesInterface()
>>> check = ciface.raster_map_exists("test", tgis.get_current_mapset())
>>> print check
True
>>> ciface.read_raster_info("test", tgis.get_current_mapset())
{'rows': 12, 'north': 80.0, 'min': 1, 'datatype': 'CELL', 'max': 1, 'ewres': 10.0, 'cols': 8, 'west': 0.0, 'east': 120.0, 'nsres': 10.0, 'south': 0.0}
>>> check = ciface.has_raster_timestamp("test", tgis.get_current_mapset())
>>> print check
True
>>> if check:
... res = ciface.read_raster_timestamp("test", tgis.get_current_mapset())
... if res[0]:
... print str(res[1][0]), str(res[1][0])
... ciface.remove_raster_timestamp("test", tgis.get_current_mapset())
1995-03-12 10:34:40 1995-03-12 10:34:40
1
>>> ciface.has_raster_timestamp("test", tgis.get_current_mapset())
False
>>> ciface.write_raster_timestamp("test", tgis.get_current_mapset(), "13 Jan 1999 14:30:05")
1
>>> ciface.has_raster_timestamp("test", tgis.get_current_mapset())
True
# 3D raster map
>>> check = ciface.raster3d_map_exists("test", tgis.get_current_mapset())
>>> print check
True
>>> ciface.read_raster3d_info("test", tgis.get_current_mapset())
{'tbres': 1.0, 'rows': 12, 'north': 80.0, 'bottom': 0.0, 'datatype': 'DCELL', 'max': 1.0, 'top': 1.0, 'min': 1.0, 'cols': 8, 'depths': 1, 'west': 0.0, 'ewres': 10.0, 'east': 120.0, 'nsres': 10.0, 'south': 0.0}
>>> check = ciface.has_raster3d_timestamp("test", tgis.get_current_mapset())
>>> print check
True
>>> if check:
... res = ciface.read_raster3d_timestamp("test", tgis.get_current_mapset())
... if res[0]:
... print str(res[1][0]), str(res[1][0])
... ciface.remove_raster3d_timestamp("test", tgis.get_current_mapset())
1995-03-12 10:34:40 1995-03-12 10:34:40
1
>>> ciface.has_raster3d_timestamp("test", tgis.get_current_mapset())
False
>>> ciface.write_raster3d_timestamp("test", tgis.get_current_mapset(), "13 Jan 1999 14:30:05")
1
>>> ciface.has_raster3d_timestamp("test", tgis.get_current_mapset())
True
# Vector map
>>> check = ciface.vector_map_exists("test", tgis.get_current_mapset())
>>> print check
True
>>> kvp = ciface.read_vector_info("test", tgis.get_current_mapset())
>>> print kvp['points']
10
>>> check = ciface.has_vector_timestamp("test", tgis.get_current_mapset(), None)
>>> print check
True
>>> if check:
... res = ciface.read_vector_timestamp("test", tgis.get_current_mapset())
... if res[0]:
... print str(res[1][0]), str(res[1][0])
... ciface.remove_vector_timestamp("test", tgis.get_current_mapset())
1995-03-12 10:34:40 1995-03-12 10:34:40
1
>>> ciface.has_vector_timestamp("test", tgis.get_current_mapset())
False
>>> ciface.write_vector_timestamp("test", tgis.get_current_mapset(), "13 Jan 1999 14:30:05")
1
>>> ciface.has_vector_timestamp("test", tgis.get_current_mapset())
True
>>> ciface.get_driver_name()
'sqlite'
>>> ciface.get_database_name().split("/")[-1]
'sqlite.db'
>>> mapset = ciface.get_mapset()
>>> location = ciface.get_location()
>>> gisdbase = ciface.get_gisdbase()
>>> gscript.del_temp_region()
Return all available mapsets the user can access as a list of strings
Returns: | Names of available mapsets as list of strings |
---|
Return the temporal database name of a specific mapset
Parameters: | mapset – Name of the mapset |
---|---|
Returns: | Name of the database or None if no temporal database present |
Return the temporal database name of a specific mapset
Parameters: | mapset – Name of the mapset |
---|---|
Returns: | Name of the database or None if no temporal database present |
Return the temporal database driver of a specific mapset
Parameters: | mapset – Name of the mapset |
---|---|
Returns: | Name of the driver or None if no temporal database present |
Check if a file based 3D raster timetamp exists
Parameters: |
|
---|---|
Returns: | True if exists, False if not |
Check if a file based raster timetamp exists
Parameters: |
|
---|---|
Returns: | True if exists, False if not |
Check if a file based vector timetamp exists
Parameters: |
|
---|---|
Returns: | True if exists, False if not |
Check if a 3D raster map exists in the spatial database
Parameters: |
|
---|---|
Returns: | True if exists, False if not |
Check if a raster map exists in the spatial database
Parameters: |
|
---|---|
Returns: | True if exists, False if not |
Read the 3D raster map info from the file system and store the content into a dictionary
Parameters: |
|
---|---|
Returns: | The key value pairs of the map specific metadata, or None in case of an error |
Read a file based 3D raster timetamp
Please have a look at the documentation G_read_raster3d_timestamp for the return values description.
The end time may be None in case of a time instance.
Parameters: |
|
---|---|
Returns: | The return value of G_read_raster3d_timestamp |
Read the raster map info from the file system and store the content into a dictionary
Parameters: |
|
---|---|
Returns: | The key value pairs of the map specific metadata, or None in case of an error |
Read a file based raster timetamp
Please have a look at the documentation G_read_raster_timestamp for the return values description.
The end time may be None in case of a time instance.
Parameters: |
|
---|---|
Returns: | The return value of G_read_raster_timestamp |
Read the vector map info from the file system and store the content into a dictionary
Parameters: |
|
---|---|
Returns: | The key value pairs of the map specific metadata, or None in case of an error |
Read a file based vector timetamp
Please have a look at the documentation G_read_vector_timestamp for the return values description.
The end time may be None in case of a time instance.
Parameters: |
|
---|---|
Returns: | The return value ofG_read_vector_timestamp and the timestamps |
Remove a file based 3D raster timetamp
Please have a look at the documentation G_remove_raster3d_timestamp for the return values description.
Parameters: |
|
---|---|
Returns: | The return value of G_remove_raster3d_timestamp |
Remove a file based raster timetamp
Please have a look at the documentation G_remove_raster_timestamp for the return values description.
Parameters: |
|
---|---|
Returns: | The return value of G_remove_raster_timestamp |
Remove a file based vector timetamp
Please have a look at the documentation G_remove_vector_timestamp for the return values description.
Parameters: |
|
---|---|
Returns: | The return value of G_remove_vector_timestamp |
Stop the messenger server and close the pipe
This method should be called at exit using the package atexit
Check if a vector map exists in the spatial database
Parameters: |
|
---|---|
Returns: | True if exists, False if not |
Write a file based 3D raster timetamp
Please have a look at the documentation G_write_raster3d_timestamp for the return values description.
Parameters: |
|
---|---|
Returns: | The return value of G_write_raster3d_timestamp |
Write a file based raster timetamp
Please have a look at the documentation G_write_raster_timestamp for the return values description.
Parameters: |
|
---|---|
Returns: | The return value of G_write_raster_timestamp |
Write a file based vector timestamp
Please have a look at the documentation G_write_vector_timestamp for the return values description.
Parameters: |
|
---|---|
Returns: | The return value of G_write_vector_timestamp |
Bases: object
This module provides the functionality to create the temporal SQL database and to establish a connection to the database.
Usage:
>>> import grass.temporal as tgis
>>> # Create the temporal database
>>> tgis.init()
>>> # Establish a database connection
>>> dbif, connected = tgis.init_dbif(None)
>>> dbif.connect()
>>> # Execute a SQL statement
>>> dbif.execute_transaction("SELECT datetime(0, 'unixepoch', 'localtime');")
>>> # Mogrify an SQL statement
>>> dbif.mogrify_sql_statement(["SELECT name from raster_base where name = ?",
... ("precipitation",)])
"SELECT name from raster_base where name = 'precipitation'"
>>> dbif.close()
(C) 2011-2014 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
author: | Soeren Gebbert |
---|
Bases: object
This class represents the database interface connection and provides access to the chosen backend modules.
The following DBMS are supported:
- sqlite via the sqlite3 standard library
- postgresql via psycopg2
Check if a table exists in the temporal database
Parameters: |
|
---|---|
Returns: | True if the table exists, False otherwise |
TODO: There may be several temporal databases in a location, hence the mapset is used to query the correct temporal database.
Close the DBMI connection TODO: There may be several temporal databases in a location, hence close all temporal databases that have been opened. Use a dictionary to manage different connections.
Connect to the DBMI to execute SQL statements
Supported backends are sqlite3 and postgresql
param dbstring: The database connection string
Execute a SQL statement
Parameters: | statement – The executable SQL statement or SQL script |
---|
Execute a transactional SQL statement
The BEGIN and END TRANSACTION statements will be added automatically to the sql statement
Parameters: | statement – The executable SQL statement or SQL script |
---|
Return the SQL statement and arguments as executable SQL string
TODO: Use the mapset argument to identify the correct database driver
Parameters: |
|
---|
Usage:
>>> init()
>>> dbif = SQLDatabaseInterfaceConnection()
>>> dbif.mogrify_sql_statement(["SELECT ctime FROM raster_base WHERE id = ?",
... ["soil@PERMANENT",]])
"SELECT ctime FROM raster_base WHERE id = 'soil@PERMANENT'"
Bases: object
Check if a table exists in the temporal database
Parameters: |
|
---|---|
Returns: | True if the table exists, False otherwise |
TODO: There may be several temporal databases in a location, hence the mapset is used to query the correct temporal database.
Close the DBMI connection
There may be several temporal databases in a location, hence close all temporal databases that have been opened.
Connect to the DBMI to execute SQL statements
Supported backends are sqlite3 and postgresql
Parameters: | mapset – The mapset of the abstract dataset or temporal database location, if None the current mapset will be used |
---|
Execute a transactional SQL statement
The BEGIN and END TRANSACTION statements will be added automatically to the sql statement
Parameters: | statement – The executable SQL statement or SQL script |
---|
Return the SQL statement and arguments as executable SQL string
Parameters: |
|
---|
This function will create the temporal database
It will create all tables and triggers that are needed to run the temporal GIS
Parameters: | dbif – The database interface to be used |
---|
Return a list of of mapset names with temporal database driver and names that are accessable from the current mapset.
Returns: | A dictionary, mapset names are keys, the tuple (driver, database) are the values |
---|
Return the current gis database (gisdbase)
This is the fastest way to receive the current gisdbase. The current gisdbase is set by init() and stored in a global variable. This function provides access to this global variable.
Return the current location
This is the fastest way to receive the current location. The current location is set by init() and stored in a global variable. This function provides access to this global variable.
Return the current mapset
This is the fastest way to receive the current mapset. The current mapset is set by init() and stored in a global variable. This function provides access to this global variable.
Return True if the mapsets should be checked while insert, update, delete requests and space time dataset registration.
If this global variable is set True, then maps can only be registered in space time datasets with the same mapset. In addition, only maps in the current mapset can be inserted, updated or deleted from the temporal database. Overwrite this global variable by: g.gisenv set=”TGIS_DISABLE_MAPSET_CHECK=True”
..warning:
Be aware to face corrupted temporal database in case this
global variable is set to False. This feature is highly
experimental and violates the grass permission guidance.
Return True if the map timestamps should be written to the spatial database metadata as well.
If this global variable is set True, the timestamps of maps will be written as textfiles for each map that will be inserted or updated in the temporal database using the C-library timestamp interface. Overwrite this global variable by: g.gisenv set=”TGIS_DISABLE_TIMESTAMP_WRITE=True”
..warning:
Be aware that C-libraries can not access timestamp information if
they are not written as spatial database metadata, hence modules
that make use of timestamps using the C-library interface will not
work with maps that were created without writing the timestamps.
Return True if a FatalError exception is raised instead of calling sys.exit(1) in case a fatal error was invoked with msgr.fatal()
Return the temporal GIS backend as string
Returns: | either “sqlite” or “pg” |
---|
Return the C-library interface that provides a fast and exit safe interface to the C-library libgis, libraster, libraster3d and libvector functions
Return the temporal database string specified with t.connect
Return the preprocessed temporal database string
This string is the temporal database string set with t.connect that was processed to substitue location, gisdbase and mapset varibales.
Get the version number of the temporal framework :returns: The version number of the temporal framework as string
Return the temporal database backend parameter style
Returns: | “qmark” or “” |
---|
Return the temporal GIS message interface which is of type grass.pygrass.message.Messenger()
Use this message interface to print messages to stdout using the GRASS C-library messaging system.
Return the tgis metadata table as a list of rows (dicts) or None if not present
Parameters: | dbif – The database interface to be used |
---|---|
Returns: | The selected rows with key/value columns or None |
Get the version number of the temporal framework :returns: The version number of the temporal framework as string
This function set the correct database backend from GRASS environmental variables and creates the grass temporal database structure for raster, vector and raster3d maps as well as for the space-time datasets strds, str3ds and stvds in case it does not exists.
Several global variables are initiated and the messenger and C-library interface subprocesses are spawned.
Re-run this function in case the following GRASS variables change while the process runs:
Re-run this function if the following t.connect variables change while the process runs:
The following environmental variables are checked:
- GRASS_TGIS_PROFILE (True, False, 1, 0)
- GRASS_TGIS_RAISE_ON_ERROR (True, False, 1, 0)
..warning:
This functions must be called before any spatio-temporal processing can be started
param raise_fatal_error: Set this True to assure that the init() function does not kill a persistent process like the GUI. If set True a grass.pygrass.messages.FatalError exception will be raised in case a fatal error occurs in the init process, otherwise sys.exit(1) will be called.
This method checks if the database interface connection exists, if not a new one will be created, connected and True will be returned. If the database interface exists but is connected, the connection will be established.
Returns: | the tuple (dbif, True|False) |
---|
Usage code sample:
dbif, connect = tgis.init_dbif(None)
sql = dbif.mogrify_sql_statement(["SELECT * FROM raster_base WHERE ? = ?"],
["id", "soil@PERMANENT"])
dbif.execute_transaction(sql)
if connect:
dbif.close()
Define behavior on fatal error, invoked using the tgis messenger interface (msgr.fatal())
The messenger interface will be restarted using the new error policy
Parameters: | raise_exp – True to raise a FatalError exception instead of calling sys.exit(1) when using the tgis messenger interface |
---|
>>> import grass.temporal as tgis
>>> tgis.init()
>>> ignore = tgis.set_raise_on_error(False)
>>> msgr = tgis.get_tgis_message_interface()
>>> tgis.get_raise_on_error()
False
>>> msgr.fatal("Ohh no no no!")
Traceback (most recent call last):
File "__init__.py", line 239, in fatal
sys.exit(1)
SystemExit: 1
>>> tgis.set_raise_on_error(True)
False
>>> msgr.fatal("Ohh no no no!")
Traceback (most recent call last):
File "__init__.py", line 241, in fatal
raise FatalError(message)
FatalError: Ohh no no no!
Traceback (most recent call last):
File "__init__.py", line 241, in fatal
raise FatalError(message)
FatalError: Ohh no no no!
Returns: | current status |
---|
Functions for mathematical datetime operations
(C) 2011-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Modify the datetime object to fit the given granularity
Usage:
>>> dt = datetime(2001, 8, 8, 12,30,30)
>>> adjust_datetime_to_granularity(dt, "5 seconds")
datetime.datetime(2001, 8, 8, 12, 30, 30)
>>> adjust_datetime_to_granularity(dt, "20 minutes")
datetime.datetime(2001, 8, 8, 12, 30)
>>> adjust_datetime_to_granularity(dt, "20 minutes")
datetime.datetime(2001, 8, 8, 12, 30)
>>> adjust_datetime_to_granularity(dt, "3 hours")
datetime.datetime(2001, 8, 8, 12, 0)
>>> adjust_datetime_to_granularity(dt, "5 days")
datetime.datetime(2001, 8, 8, 0, 0)
>>> adjust_datetime_to_granularity(dt, "2 weeks")
datetime.datetime(2001, 8, 6, 0, 0)
>>> adjust_datetime_to_granularity(dt, "6 months")
datetime.datetime(2001, 8, 1, 0, 0)
>>> adjust_datetime_to_granularity(dt, "2 years")
datetime.datetime(2001, 1, 1, 0, 0)
>>> adjust_datetime_to_granularity(dt, "2 years, 3 months, 5 days, 3 hours, 3 minutes, 2 seconds")
datetime.datetime(2001, 8, 8, 12, 30, 30)
>>> adjust_datetime_to_granularity(dt, "3 months, 5 days, 3 minutes")
datetime.datetime(2001, 8, 8, 12, 30)
>>> adjust_datetime_to_granularity(dt, "3 weeks, 5 days")
datetime.datetime(2001, 8, 8, 0, 0)
Check if a string can be converted into a datetime object
Supported ISO string formats are:
Time zones are not supported
Parameters: | time_string – The time string to be checked for conversion |
---|---|
Returns: | datetime: object or an error message string in case of an error |
Return a dictionary with the accumulated delta in year, month, day, hour, minute and second
Usage:
>>> start = datetime(2001, 1, 1, 00,00,00) >>> end = datetime(2001, 1, 1, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 0, 'second': 0, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 0} >>> start = datetime(2001, 1, 1, 00,00,14) >>> end = datetime(2001, 1, 1, 00,00,44) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 0, 'second': 30, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 0} >>> start = datetime(2001, 1, 1, 00,00,44) >>> end = datetime(2001, 1, 1, 00,01,14) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 0, 'second': 30, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 1} >>> start = datetime(2001, 1, 1, 00,00,30) >>> end = datetime(2001, 1, 1, 00,05,30) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 0, 'second': 300, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 5} >>> start = datetime(2001, 1, 1, 00,00,00) >>> end = datetime(2001, 1, 1, 00,01,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 0, 'second': 0, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 1} >>> start = datetime(2011,10,31, 00,45,00) >>> end = datetime(2011,10,31, 01,45,00) >>> compute_datetime_delta(start, end) {'hour': 1, 'second': 0, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 60} >>> start = datetime(2011,10,31, 00,45,00) >>> end = datetime(2011,10,31, 01,15,00) >>> compute_datetime_delta(start, end) {'hour': 1, 'second': 0, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 30} >>> start = datetime(2011,10,31, 00,45,00) >>> end = datetime(2011,10,31, 12,15,00) >>> compute_datetime_delta(start, end) {'hour': 12, 'second': 0, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 690} >>> start = datetime(2011,10,31, 00,00,00) >>> end = datetime(2011,10,31, 01,00,00) >>> compute_datetime_delta(start, end) {'hour': 1, 'second': 0, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 0} >>> start = datetime(2011,10,31, 00,00,00) >>> end = datetime(2011,11,01, 01,00,00) >>> compute_datetime_delta(start, end) {'hour': 25, 'second': 0, 'max_days': 1, 'year': 0, 'day': 1, 'minute': 0} >>> start = datetime(2011,10,31, 12,00,00) >>> end = datetime(2011,11,01, 06,00,00) >>> compute_datetime_delta(start, end) {'hour': 18, 'second': 0, 'max_days': 0, 'year': 0, 'day': 0, 'minute': 0} >>> start = datetime(2011,11,01, 00,00,00) >>> end = datetime(2011,12,01, 01,00,00) >>> compute_datetime_delta(start, end) {'hour': 721, 'month': 1, 'second': 0, 'max_days': 30, 'year': 0, 'day': 0, 'minute': 0} >>> start = datetime(2011,11,01, 00,00,00) >>> end = datetime(2011,11,05, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'second': 0, 'max_days': 4, 'year': 0, 'day': 4, 'minute': 0} >>> start = datetime(2011,10,06, 00,00,00) >>> end = datetime(2011,11,05, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'second': 0, 'max_days': 30, 'year': 0, 'day': 30, 'minute': 0} >>> start = datetime(2011,12,02, 00,00,00) >>> end = datetime(2012,01,01, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'second': 0, 'max_days': 30, 'year': 1, 'day': 30, 'minute': 0} >>> start = datetime(2011,01,01, 00,00,00) >>> end = datetime(2011,02,01, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 1, 'second': 0, 'max_days': 31, 'year': 0, 'day': 0, 'minute': 0} >>> start = datetime(2011,12,01, 00,00,00) >>> end = datetime(2012,01,01, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 1, 'second': 0, 'max_days': 31, 'year': 1, 'day': 0, 'minute': 0} >>> start = datetime(2011,12,01, 00,00,00) >>> end = datetime(2012,06,01, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 6, 'second': 0, 'max_days': 183, 'year': 1, 'day': 0, 'minute': 0} >>> start = datetime(2011,06,01, 00,00,00) >>> end = datetime(2021,06,01, 00,00,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 120, 'second': 0, 'max_days': 3653, 'year': 10, 'day': 0, 'minute': 0} >>> start = datetime(2011,06,01, 00,00,00) >>> end = datetime(2012,06,01, 12,00,00) >>> compute_datetime_delta(start, end) {'hour': 8796, 'month': 12, 'second': 0, 'max_days': 366, 'year': 1, 'day': 0, 'minute': 0} >>> start = datetime(2011,06,01, 00,00,00) >>> end = datetime(2012,06,01, 12,30,00) >>> compute_datetime_delta(start, end) {'hour': 8796, 'month': 12, 'second': 0, 'max_days': 366, 'year': 1, 'day': 0, 'minute': 527790} >>> start = datetime(2011,06,01, 00,00,00) >>> end = datetime(2012,06,01, 12,00,05) >>> compute_datetime_delta(start, end) {'hour': 8796, 'month': 12, 'second': 31665605, 'max_days': 366, 'year': 1, 'day': 0, 'minute': 0} >>> start = datetime(2011,06,01, 00,00,00) >>> end = datetime(2012,06,01, 00,30,00) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 12, 'second': 0, 'max_days': 366, 'year': 1, 'day': 0, 'minute': 527070} >>> start = datetime(2011,06,01, 00,00,00) >>> end = datetime(2012,06,01, 00,00,05) >>> compute_datetime_delta(start, end) {'hour': 0, 'month': 12, 'second': 31622405, 'max_days': 366, 'year': 1, 'day': 0, 'minute': 0}
Returns: | A dictionary with year, month, day, hour, minute and second as keys() |
---|
Create a datetime string based on a datetime object and a provided granularity that can be used as suffix for map names.
dateteime=2001-01-01 00:00:00, granularity=”1 month” returns “2001_01”
Parameters: |
|
---|---|
Returns: | A string |
Convert a python datetime object into a GRASS datetime string
>>> import grass.temporal as tgis
>>> import dateutil.parser as parser
>>> dt = parser.parse("2011-01-01 10:00:00 +01:30")
>>> tgis.datetime_to_grass_datetime_string(dt)
'01 jan 2011 10:00:00 +0090'
>>> dt = parser.parse("2011-01-01 10:00:00 +02:30")
>>> tgis.datetime_to_grass_datetime_string(dt)
'01 jan 2011 10:00:00 +0150'
>>> dt = parser.parse("2011-01-01 10:00:00 +12:00")
>>> tgis.datetime_to_grass_datetime_string(dt)
'01 jan 2011 10:00:00 +0720'
>>> dt = parser.parse("2011-01-01 10:00:00 -01:30")
>>> tgis.datetime_to_grass_datetime_string(dt)
'01 jan 2011 10:00:00 -0090'
Return a new datetime object decremented with the provided relative dates specified as string. Additional a multiplier can be specified to multiply the increment before adding to the provided datetime object.
Usage:
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "31 days"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(2000, 12, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "1 month"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(2000, 12, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "2 month"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(2000, 11, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "24 months"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(1999, 1, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "48 months"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(1997, 1, 1, 0, 0)
>>> dt = datetime(2001, 6, 1, 0, 0, 0)
>>> string = "5 months"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(2001, 1, 1, 0, 0)
>>> dt = datetime(2001, 6, 1, 0, 0, 0)
>>> string = "7 months"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(2000, 11, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "1 year"
>>> decrement_datetime_by_string(dt, string)
datetime.datetime(2000, 1, 1, 0, 0)
Parameters: |
|
---|---|
Returns: | The new datetime object or none in case of an error |
Return a new datetime object incremented with the provided relative dates specified as string. Additional a multiplier can be specified to multiply the increment before adding to the provided datetime object.
Usage:
>>> dt = datetime(2001, 9, 1, 0, 0, 0)
>>> string = "60 seconds, 4 minutes, 12 hours, 10 days, 1 weeks, 5 months, 1 years"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2003, 2, 18, 12, 5)
>>> dt = datetime(2001, 11, 1, 0, 0, 0)
>>> string = "1 months"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2001, 12, 1, 0, 0)
>>> dt = datetime(2001, 11, 1, 0, 0, 0)
>>> string = "13 months"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2002, 12, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "72 months"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2007, 1, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "72 months"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2007, 1, 1, 0, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "5 minutes"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2001, 1, 1, 0, 5)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "49 hours"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2001, 1, 3, 1, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "3600 seconds"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2001, 1, 1, 1, 0)
>>> dt = datetime(2001, 1, 1, 0, 0, 0)
>>> string = "30 days"
>>> increment_datetime_by_string(dt, string)
datetime.datetime(2001, 1, 31, 0, 0)
Parameters: |
|
---|---|
Returns: | The new datetime object or none in case of an error |
Return a new datetime object incremented with the provided relative dates and times
Return a new datetime object incremented with the provided relative dates specified as string. Additional a multiplier can be specified to multiply the increment before adding to the provided datetime object.
Parameters: |
|
---|---|
Returns: | The new datetime object or none in case of an error |
Convert the double value representing days into a timedelta object.
Convert the double value representing seconds into a timedelta object.
Convert a string into a datetime object
In case datutil is not installed the supported ISO string formats are:
If dateutil is installed, all string formats of the dateutil module are supported, as well as time zones
Parameters: | time_string – The time string to convert |
---|---|
Returns: | datetime object or None in case the string could not be converted |
Extract functions for space time raster, 3d raster and vector datasets
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Extract a subset of a space time raster, raster3d or vector dataset
A mapcalc expression can be provided to process the temporal extracted maps. Mapcalc expressions are supported for raster and raster3d maps.
Parameters: |
|
---|
Object factory
Usage:
import grass.temporal as tgis
tgis.register_maps_in_space_time_dataset(type, name, maps)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
A factory functions to create space time or map datasets
Parameters: |
|
---|
GUI support functions
(C) 2008-2011 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Return a list of space time datasets of absolute and relative time
Parameters: | type – element type (strds, str3ds, stvds) |
---|---|
Returns: | a list of space time dataset ids |
List of temporal elements grouped by mapsets.
Returns a dictionary where the keys are mapset names and the values are lists of space time datasets in that mapset. Example:
>>> tgis.tlist_grouped('strds')['PERMANENT']
['precipitation', 'temperature']
Parameters: |
|
---|---|
Returns: | directory of mapsets/elements |
Functions to create space time dataset lists
Usage:
import grass.temporal as tgis
tgis.register_maps_in_space_time_dataset(type, name, maps)
(C) 2012-2016 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS GIS for details.
authors: | Soeren Gebbert |
---|
Return a list of time stamped maps or space time datasets of a specific temporal type that are registred in the temporal database
This method returns a dictionary, the keys are the available mapsets, the values are the rows from the SQL database query.
Parameters: |
|
---|---|
Returns: | A dictionary with the rows of the SQL query for each available mapset |
>>> import grass.temporal as tgis
>>> tgis.init()
>>> name = "list_stds_test"
>>> sp = tgis.open_new_stds(name=name, type="strds",
... temporaltype="absolute", title="title", descr="descr",
... semantic="mean", dbif=None, overwrite=True)
>>> mapset = tgis.get_current_mapset()
>>> stds_list = tgis.get_dataset_list("strds", "absolute", columns="name")
>>> rows = stds_list[mapset]
>>> for row in rows:
... if row["name"] == name:
... print True
True
>>> stds_list = tgis.get_dataset_list("strds", "absolute",
... columns="name,mapset", where="mapset = '%s'"%(mapset))
>>> rows = stds_list[mapset]
>>> for row in rows:
... if row["name"] == name and row["mapset"] == mapset:
... print True
True
>>> check = sp.delete()
List the maps of a space time dataset using different methods
Parameters: |
|
---|
Raster and 3d raster mapcalculation functions
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Perform map-calculations of maps from different space time raster/raster3d datasets, using a specific sampling method to select temporal related maps.
A mapcalc expression must be provided to process the temporal selected maps. Temporal operators are available in addition to the r.mapcalc operators:
Supported operators for relative and absolute time are:
and fractions of days or the unit in case of relative time
the time series in days and fractions of days or the unit in case of relative time
the time series in days and fractions of days or the unit in case of relative time
Supported operators for absolute time:
start_doy() - Day of year (doy) from the start time [1 - 366]
the start of the week is monday == 1
start_year() - The year of the start time [0 - 9999]
start_month() - The month of the start time [1 - 12]
start_week() - Week of year of the start time [1 - 54]
start_day() - Day of month from the start time [1 - 31]
start_hour() - The hour of the start time [0 - 23]
start_minute() - The minute of the start time [0 - 59]
start_second() - The second of the start time [0 - 59]
end_doy() - Day of year (doy) from the end time [1 - 366]
the start of the week is monday == 1
end_year() - The year of the end time [0 - 9999]
end_month() - The month of the end time [1 - 12]
end_week() - Week of year of the end time [1 - 54]
end_day() - Day of month from the end time [1 - 31]
end_hour() - The hour of the end time [0 - 23]
end_minute() - The minute of the end time [0 - 59]
end_second() - The minute of the end time [0 - 59]
Parameters: |
|
---|
Metadata classes for map layer and space time datasets
Usage:
>>> import grass.temporal as tgis
>>> tgis.init()
>>> meta = tgis.RasterMetadata()
>>> meta = tgis.Raster3DMetadata()
>>> meta = tgis.VectorMetadata()
>>> meta = tgis.STRDSMetadata()
>>> meta = tgis.STR3DSMetadata()
>>> meta = tgis.STVDSMetadata()
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: temporal.metadata.RasterMetadataBase
This is the raster3d metadata class
This class is the interface to the raster3d_metadata table in the temporal database that stores the metadata of all registered 3D raster maps.
The metadata includes all raster metadata variables and additional the number of depths, the top-bottom resolution and the space time 3D raster dataset register table is stored.
Usage:
>>> init()
>>> meta = Raster3DMetadata(ident="soil@PERMANENT",
... datatype="FCELL", cols=100, rows=100, depths=100,
... number_of_cells=1000000, nsres=0.1, ewres=0.1, tbres=0.1,
... min=0, max=100)
>>> meta.datatype
'FCELL'
>>> meta.cols
100
>>> meta.rows
100
>>> meta.depths
100
>>> meta.number_of_cells
1000000
>>> meta.nsres
0.1
>>> meta.ewres
0.1
>>> meta.tbres
0.1
>>> meta.min
0.0
>>> meta.max
100.0
>>> meta.print_info()
+-------------------- Metadata information ----------------------------------+
| Datatype:................... FCELL
| Number of columns:.......... 100
| Number of rows:............. 100
| Number of cells:............ 1000000
| North-South resolution:..... 0.1
| East-west resolution:....... 0.1
| Minimum value:.............. 0.0
| Maximum value:.............. 100.0
| Number of depths:........... 100
| Top-Bottom resolution:...... 0.1
>>> meta.print_shell_info()
datatype=FCELL
cols=100
rows=100
number_of_cells=1000000
nsres=0.1
ewres=0.1
min=0.0
max=100.0
depths=100
tbres=0.1
Get number of depths :return: None if not found
Get top-bottom resolution :return: None if not found
Bases: temporal.metadata.RasterMetadataBase
This is the raster metadata class
This class is the interface to the raster_metadata table in the temporal database that stores the metadata of all registered raster maps.
The metadata includes the datatype, number of cols, rows and cells and the north-south and east west resolution of the map. Additionally the minimum and maximum valuesare stored.
Usage:
>>> init()
>>> meta = RasterMetadata(ident="soil@PERMANENT",
... datatype="CELL", cols=100, rows=100, number_of_cells=10000, nsres=0.1,
... ewres=0.1, min=0, max=100)
>>> meta.datatype
'CELL'
>>> meta.cols
100
>>> meta.rows
100
>>> meta.number_of_cells
10000
>>> meta.nsres
0.1
>>> meta.ewres
0.1
>>> meta.min
0.0
>>> meta.max
100.0
>>> meta.print_info()
+-------------------- Metadata information ----------------------------------+
| Datatype:................... CELL
| Number of columns:.......... 100
| Number of rows:............. 100
| Number of cells:............ 10000
| North-South resolution:..... 0.1
| East-west resolution:....... 0.1
| Minimum value:.............. 0.0
| Maximum value:.............. 100.0
>>> meta.print_shell_info()
datatype=CELL
cols=100
rows=100
number_of_cells=10000
nsres=0.1
ewres=0.1
min=0.0
max=100.0
Bases: temporal.base.SQLDatabaseInterface
This is the metadata base class for time stamped raster and raster3d maps
Usage:
>>> init()
>>> meta = RasterMetadataBase(table="metadata", ident="soil@PERMANENT",
... datatype="CELL", cols=100, rows=100, number_of_cells=10000, nsres=0.1,
... ewres=0.1, min=0, max=100)
>>> meta.datatype
'CELL'
>>> meta.cols
100
>>> meta.rows
100
>>> meta.number_of_cells
10000
>>> meta.nsres
0.1
>>> meta.ewres
0.1
>>> meta.min
0.0
>>> meta.max
100.0
>>> meta.print_info()
| Datatype:................... CELL
| Number of columns:.......... 100
| Number of rows:............. 100
| Number of cells:............ 10000
| North-South resolution:..... 0.1
| East-west resolution:....... 0.1
| Minimum value:.............. 0.0
| Maximum value:.............. 100.0
>>> meta.print_shell_info()
datatype=CELL
cols=100
rows=100
number_of_cells=10000
nsres=0.1
ewres=0.1
min=0.0
max=100.0
Get number of cols :return: None if not found
Get the map type :return: None if not found
Get east-west resolution :return: None if not found
Convenient method to get the unique identifier (primary key) :return: None if not found
Get the maximum cell value :return: None if not found
Get the minimum cell value :return: None if not found
Get the north-south resolution :return: None if not found
Get number of cells :return: None if not found
Get number of rows :return: None if not found
Bases: temporal.base.SQLDatabaseInterface
This is the space time dataset metadata base class for strds, stvds and str3ds datasets setting/getting the id, the title and the description
Usage:
>>> init() >>> meta = STDSMetadataBase(ident="soils@PERMANENT", ... title="Soils", description="Soils 1950 - 2010") >>> meta.id 'soils@PERMANENT' >>> meta.title 'Soils' >>> meta.description 'Soils 1950 - 2010' >>> meta.number_of_maps >>> meta.print_info() | Number of registered maps:.. None | | Title: | Soils | Description: | Soils 1950 - 2010 | Command history: >>> meta.print_shell_info() number_of_maps=None
Get description :return: None if not found
Convenient method to get the unique identifier (primary key) :return: None if not found
Get the number of registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Convenient method to get the unique identifier (primary key) :return: None if not found
Get the number of registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the title :return: None if not found
Bases: temporal.metadata.STDSMetadataBase
This is the space time dataset metadata base class for strds and str3ds datasets
Most of the metadata values are set by SQL scripts in the database when new maps are added. Therefor only some set- an many get-functions are available.
Usage:
>>> init()
>>> meta = STDSRasterMetadataBase(ident="soils@PERMANENT",
... title="Soils", description="Soils 1950 - 2010")
>>> meta.id
'soils@PERMANENT'
>>> meta.title
'Soils'
>>> meta.description
'Soils 1950 - 2010'
>>> meta.number_of_maps
>>> meta.min_max
>>> meta.max_max
>>> meta.min_min
>>> meta.max_min
>>> meta.nsres_min
>>> meta.nsres_max
>>> meta.ewres_min
>>> meta.ewres_max
>>> meta.print_info()
| North-South resolution min:. None
| North-South resolution max:. None
| East-west resolution min:... None
| East-west resolution max:... None
| Minimum value min:.......... None
| Minimum value max:.......... None
| Maximum value min:.......... None
| Maximum value max:.......... None
| Aggregation type:........... None
| Number of registered maps:.. None
|
| Title:
| Soils
| Description:
| Soils 1950 - 2010
| Command history:
>>> meta.print_shell_info()
aggregation_type=None
number_of_maps=None
nsres_min=None
nsres_max=None
ewres_min=None
ewres_max=None
min_min=None
min_max=None
max_min=None
max_max=None
Get the aggregation type of the dataset (mean, min, max, ...) :return: None if not found
Get the maximal east-west resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal east-west resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the aggregation type of the dataset (mean, min, max, ...) :return: None if not found
Get the maximal east-west resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal east-west resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the maximal maximum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal maximum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the maximal minimum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal minimum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the maximal north-south resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal north-south resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the maximal maximum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal maximum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the maximal minimum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal minimum of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the maximal north-south resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal north-south resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Bases: temporal.metadata.STDSRasterMetadataBase
This is the space time 3D raster metadata class
This class is the interface to the str3ds_metadata table in the temporal database that stores the metadata of all registered space time 3D raster datasets
Most of the metadata values are set by SQL scripts in the database when new 3D raster maps are added. Therefor only some set- an many get-functions are available.
Usage:
>>> init()
>>> meta = STR3DSMetadata(ident="soils@PERMANENT",
... title="Soils", description="Soils 1950 - 2010")
>>> meta.id
'soils@PERMANENT'
>>> meta.title
'Soils'
>>> meta.description
'Soils 1950 - 2010'
>>> meta.number_of_maps
>>> meta.min_max
>>> meta.max_max
>>> meta.min_min
>>> meta.max_min
>>> meta.nsres_min
>>> meta.nsres_max
>>> meta.ewres_min
>>> meta.ewres_max
>>> meta.tbres_min
>>> meta.tbres_max
>>> meta.raster3d_register
>>> meta.print_info()
+-------------------- Metadata information ----------------------------------+
| 3D raster register table:... None
| Top-bottom resolution min:.. None
| Top-bottom resolution max:.. None
| North-South resolution min:. None
| North-South resolution max:. None
| East-west resolution min:... None
| East-west resolution max:... None
| Minimum value min:.......... None
| Minimum value max:.......... None
| Maximum value min:.......... None
| Maximum value max:.......... None
| Aggregation type:........... None
| Number of registered maps:.. None
|
| Title:
| Soils
| Description:
| Soils 1950 - 2010
| Command history:
>>> meta.print_shell_info()
aggregation_type=None
number_of_maps=None
nsres_min=None
nsres_max=None
ewres_min=None
ewres_max=None
min_min=None
min_max=None
max_min=None
max_max=None
tbres_min=None
tbres_max=None
raster3d_register=None
Get the raster3d map register table name :return: None if not found
Get the maximal top-bottom resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal top-bottom resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the raster3d map register table name :return: None if not found
Get the maximal top-bottom resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the minimal top-bottom resolution of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Bases: temporal.metadata.STDSRasterMetadataBase
This is the raster metadata class
This class is the interface to the strds_metadata table in the temporal database that stores the metadata of all registered space time raster datasets
Most of the metadata values are set by SQL scripts in the database when new raster maps are added. Therefor only some set- an many get-functions are available.
Usage:
>>> init()
>>> meta = STRDSMetadata(ident="soils@PERMANENT",
... title="Soils", description="Soils 1950 - 2010")
>>> meta.id
'soils@PERMANENT'
>>> meta.title
'Soils'
>>> meta.description
'Soils 1950 - 2010'
>>> meta.number_of_maps
>>> meta.min_max
>>> meta.max_max
>>> meta.min_min
>>> meta.max_min
>>> meta.nsres_min
>>> meta.nsres_max
>>> meta.ewres_min
>>> meta.ewres_max
>>> meta.raster_register
>>> meta.print_info()
+-------------------- Metadata information ----------------------------------+
| Raster register table:...... None
| North-South resolution min:. None
| North-South resolution max:. None
| East-west resolution min:... None
| East-west resolution max:... None
| Minimum value min:.......... None
| Minimum value max:.......... None
| Maximum value min:.......... None
| Maximum value max:.......... None
| Aggregation type:........... None
| Number of registered maps:.. None
|
| Title:
| Soils
| Description:
| Soils 1950 - 2010
| Command history:
>>> meta.print_shell_info()
aggregation_type=None
number_of_maps=None
nsres_min=None
nsres_max=None
ewres_min=None
ewres_max=None
min_min=None
min_max=None
max_min=None
max_max=None
raster_register=None
Get the raster map register table name :return: None if not found
Bases: temporal.metadata.STDSMetadataBase
This is the space time vector dataset metadata class
This class is the interface to the stvds_metadata table in the temporal database that stores the metadata of all registered space time vector datasets
Most of the metadata values are set by SQL scripts in the database when new vector maps are added. Therefor only some set- an many get-functions are available.
Usage:
>>> init() >>> meta = STVDSMetadata(ident="lidars@PERMANENT", ... title="LIDARS", description="LIDARS 2008 - 2010") >>> meta.id 'lidars@PERMANENT' >>> meta.title 'LIDARS' >>> meta.description 'LIDARS 2008 - 2010' >>> meta.number_of_maps >>> meta.number_of_points >>> meta.number_of_lines >>> meta.number_of_boundaries >>> meta.number_of_centroids >>> meta.number_of_faces >>> meta.number_of_kernels >>> meta.number_of_primitives >>> meta.number_of_nodes >>> meta.number_of_areas >>> meta.number_of_islands >>> meta.number_of_holes >>> meta.number_of_volumes >>> meta.print_info() +-------------------- Metadata information ----------------------------------+ | Vector register table:...... None | Number of points ........... None | Number of lines ............ None | Number of boundaries ....... None | Number of centroids ........ None | Number of faces ............ None | Number of kernels .......... None | Number of primitives ....... None | Number of nodes ............ None | Number of areas ............ None | Number of islands .......... None | Number of holes ............ None | Number of volumes .......... None | Number of registered maps:.. None | | Title: | LIDARS | Description: | LIDARS 2008 - 2010 | Command history: >>> meta.print_shell_info() number_of_maps=None vector_register=None points=None lines=None boundaries=None centroids=None faces=None kernels=None primitives=None nodes=None areas=None islands=None holes=None volumes=None
Get the number of areas of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of boundaries of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of centroids of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of faces of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of holes of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of islands of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of kernels of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of lines of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of nodes of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of points of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of primitives of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of volumes of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of areas of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of boundaries of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of centroids of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of faces of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of holes of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of islands of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of kernels of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of lines of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of nodes of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of points of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of primitives of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the number of volumes of all registered maps, this value is set in the database automatically via SQL, so no setter exists :return: None if not found
Get the vector map register table name :return: None if not found
Bases: temporal.base.SQLDatabaseInterface
This is the vector metadata class
This class is the interface to the vector_metadata table in the temporal database that stores the metadata of all registered vector maps.
Usage:
>>> init()
>>> meta = VectorMetadata(ident="lidar@PERMANENT", is_3d=True,
... number_of_points=1, number_of_lines=2, number_of_boundaries=3,
... number_of_centroids=4, number_of_faces=5, number_of_kernels=6,
... number_of_primitives=7, number_of_nodes=8, number_of_areas=9,
... number_of_islands=10, number_of_holes=11, number_of_volumes=12)
>>> meta.id
'lidar@PERMANENT'
>>> meta.is_3d
True
>>> meta.number_of_points
1
>>> meta.number_of_lines
2
>>> meta.number_of_boundaries
3
>>> meta.number_of_centroids
4
>>> meta.number_of_faces
5
>>> meta.number_of_kernels
6
>>> meta.number_of_primitives
7
>>> meta.number_of_nodes
8
>>> meta.number_of_areas
9
>>> meta.number_of_islands
10
>>> meta.number_of_holes
11
>>> meta.number_of_volumes
12
>>> meta.print_info()
+-------------------- Metadata information ----------------------------------+
| Is map 3d .................. True
| Number of points ........... 1
| Number of lines ............ 2
| Number of boundaries ....... 3
| Number of centroids ........ 4
| Number of faces ............ 5
| Number of kernels .......... 6
| Number of primitives ....... 7
| Number of nodes ............ 8
| Number of areas ............ 9
| Number of islands .......... 10
| Number of holes ............ 11
| Number of volumes .......... 12
>>> meta.print_shell_info()
is_3d=True
points=1
lines=2
boundaries=3
centroids=4
faces=5
kernels=6
primitives=7
nodes=8
areas=9
islands=10
holes=11
volumes=12
Return True if the map is three dimensional, False if not and None if not info was found
Convenient method to get the unique identifier (primary key) :return: None if not found
Get the number of boundaries of the vector map :return: None if not found
Get the number of centroids of the vector map :return: None if not found
Get the number of islands of the vector map :return: None if not found
Get the number of kernels of the vector map :return: None if not found
Get the number of points of the vector map :return: None if not found
Get the number of primitives of the vector map :return: None if not found
Get the number of volumes of the vector map :return: None if not found
Convenient method to get the unique identifier (primary key) :return: None if not found
Return True if the map is three dimensional, False if not and None if not info was found
Get the number of areas of the vector map :return: None if not found
Get the number of boundaries of the vector map :return: None if not found
Get the number of centroids of the vector map :return: None if not found
Get the number of faces of the vector map :return: None if not found
Get the number of holes of the vector map :return: None if not found
Get the number of islands of the vector map :return: None if not found
Get the number of kernels of the vector map :return: None if not found
Get the number of lines of the vector map :return: None if not found
Get the number of nodes of the vector map :return: None if not found
Get the number of points of the vector map :return: None if not found
Get the number of primitives of the vector map :return: None if not found
Get the number of volumes of the vector map :return: None if not found
Set the number of boundaries of the vector map
Functions to open or create space time datasets
Usage:
import grass.temporal as tgis
tgis.register_maps_in_space_time_dataset(type, name, maps)
(C) 2012-2014 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Parameters: |
|
---|---|
Returns: | A map dataset object |
This function will raise a FatalError in case of an error.
Check if a new space time dataset of a specific type can be created
Parameters: |
|
---|---|
Returns: | A space time dataset object that must be filled with content before insertion in the temporal database |
This function will raise a FatalError in case of an error.
Parameters: |
|
---|---|
Returns: | A map dataset object |
Create a new space time dataset of a specific type
Parameters: |
|
---|---|
Returns: | The new created space time dataset |
This function will raise a FatalError in case of an error.
This function opens an existing space time dataset and return the created and initialized object of the specified type.
This function will call exit() or raise a grass.pygrass.messages.FatalError in case the type is wrong, or the space time dataset was not found.
Parameters: |
|
---|---|
Returns: | New stds object |
Functions to register map layer in space time datasets and the temporal database
Usage:
import grass.temporal as tgis
tgis.register_maps_in_space_time_dataset(type, name, maps)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Assign the valid time to a map dataset
Parameters: |
|
---|
Register a list of AbstractMapDataset objects in the temporal database and optional in a space time dataset.
Parameters: |
|
---|
Use this method to register maps in space time datasets.
Additionally a start time string and an increment string can be specified to assign a time interval automatically to the maps.
It takes care of the correct update of the space time datasets from all registered maps.
Parameters: |
|
---|
Sampling functions for space time datasets
Usage:
import grass.temporal as tgis
tgis.register_maps_in_space_time_dataset(type, name, maps)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Sample the input space time datasets with a sample space time dataset, return the created map matrix and optionally print the result to stdout
In case multiple maps are located in the current granule, the map names are separated by comma.
In case a layer is present, the names map ids are extended in this form: “name:layer@mapset”
Attention: Do not use the comma as separator for printing
param intype: Type of the input space time dataset (strds, stvds or str3ds) param sampletype: Type of the sample space time datasets (strds, stvds or str3ds) param inputs: Name or comma separated names of space time datasets or a list of map names param sampler: Name of a space time dataset used for temporal sampling param header: Set True to print column names param separator: The field separator character between the columns param method: The method to be used for temporal sampling (start,during,contain,overlap,equal) as comma separated string or as a list of methods param spatial: Perform spatial overlapping check param print_only: If set True (default) then the result of the sampling will be printed to stdout, if set to False the resulting map matrix will be returned. return: The map matrix or None if nothing found
Map layer and space time dataset classes
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: temporal.abstract_map_dataset.AbstractMapDataset
Raster3d dataset class
This class provides functions to select, update, insert or delete raster3d map information and valid time stamps into the SQL temporal database.
Usage:
>>> 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,
... t=100.0, b=0.0, res=10.0, res3=10.0)
0
>>> grass.run_command("r3.mapcalc", overwrite=True, quiet=True,
... expression="str3ds_map_test_case = 1")
0
>>> grass.run_command("r3.timestamp", map="str3ds_map_test_case",
... date="15 jan 1999", quiet=True)
0
>>> mapset = get_current_mapset()
>>> name = "str3ds_map_test_case"
>>> identifier = "%s@%s" % (name, mapset)
>>> r3map = Raster3DDataset(identifier)
>>> r3map.map_exists()
True
>>> r3map.read_timestamp_from_grass()
True
>>> r3map.get_temporal_extent_as_tuple()
(datetime.datetime(1999, 1, 15, 0, 0), None)
>>> r3map.load()
True
>>> r3map.spatial_extent.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 0.0
| East:.. .................... 120.0
| West:....................... 0.0
| Top:........................ 100.0
| Bottom:..................... 0.0
>>> r3map.absolute_time.print_info()
+-------------------- Absolute time -----------------------------------------+
| Start time:................. 1999-01-15 00:00:00
| End time:................... None
>>> r3map.metadata.print_info()
+-------------------- Metadata information ----------------------------------+
| Datatype:................... DCELL
| Number of columns:.......... 8
| Number of rows:............. 12
| Number of cells:............ 960
| North-South resolution:..... 10.0
| East-west resolution:....... 10.0
| Minimum value:.............. 1.0
| Maximum value:.............. 1.0
| Number of depths:........... 10
| Top-Bottom resolution:...... 10.0
>>> newmap = r3map.get_new_instance("new@PERMANENT")
>>> isinstance(newmap, Raster3DDataset)
True
>>> newstr3ds = r3map.get_new_stds_instance("new@PERMANENT")
>>> isinstance(newstr3ds, SpaceTimeRaster3DDataset)
True
>>> r3map.get_type()
'raster3d'
>>> r3map.set_absolute_time(start_time=datetime(2001,1,1),
... end_time=datetime(2012,1,1))
True
>>> r3map.get_absolute_time()
(datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 0, 0))
>>> r3map.get_temporal_extent_as_tuple()
(datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 0, 0))
>>> r3map.get_name()
'str3ds_map_test_case'
>>> r3map.get_mapset() == mapset
True
>>> r3map.get_temporal_type()
'absolute'
>>> r3map.get_spatial_extent_as_tuple()
(80.0, 0.0, 120.0, 0.0, 100.0, 0.0)
>>> r3map.is_time_absolute()
True
>>> r3map.is_time_relative()
False
>>> grass.run_command("g.remove", flags="f", type="raster_3d", name=name, quiet=True)
0
>>> grass.del_temp_region()
Return a new space time dataset instance in which maps are stored with the type of this class
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 and assigned to the memmap object that is returned by this function.
In case the 3D raster map does not exist, 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 array back into grass.
Check if a grass file bsased time stamp exists for this map.
Returns: | True if success, False on error |
---|
Return True if this class is a space time dataset
Returns: | True if this class is a space time dataset, False otherwise |
---|
Load all info from an existing 3d raster map into the internal structure
This method checks first if the map exists, in case it exists the metadata of the map is put into this object and True is returned
Returns: | True is the map exists and the metadata was filled successfully and getting the data was successfull, False otherwise |
---|
Return True in case the map exists in the grass spatial database
Returns: | True if map exists, False otherwise |
---|
Read the timestamp of this map from the map metadata in the grass file system based spatial database and set the internal time stamp that should be insert/updated in the temporal database.
Returns: | True if success, False on error |
---|
Remove the timestamp from the grass file system based spatial database
Returns: | True if success, False on error |
---|
Return the three or two dimensional union as spatial_extent object.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Return the three or two dimensional intersection as spatial_extent object or None in case no intersection was found.
Parameters: | dataset – The abstract dataset to intersect with |
---|---|
Returns: | The intersection spatial extent or None |
Bases: temporal.abstract_map_dataset.AbstractMapDataset
Raster dataset class
This class provides functions to select, update, insert or delete raster map information and valid time stamps into the SQL temporal database.
Usage:
>>> 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,
... t=1.0, b=0.0, res=10.0)
0
>>> grass.run_command("r.mapcalc", overwrite=True, quiet=True,
... expression="strds_map_test_case = 1")
0
>>> grass.run_command("r.timestamp", map="strds_map_test_case",
... date="15 jan 1999", quiet=True)
0
>>> mapset = get_current_mapset()
>>> name = "strds_map_test_case"
>>> identifier = "%s@%s" % (name, mapset)
>>> rmap = RasterDataset(identifier)
>>> rmap.map_exists()
True
>>> rmap.read_timestamp_from_grass()
True
>>> rmap.get_temporal_extent_as_tuple()
(datetime.datetime(1999, 1, 15, 0, 0), None)
>>> rmap.load()
True
>>> rmap.spatial_extent.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 0.0
| East:.. .................... 120.0
| West:....................... 0.0
| Top:........................ 0.0
| Bottom:..................... 0.0
>>> rmap.absolute_time.print_info()
+-------------------- Absolute time -----------------------------------------+
| Start time:................. 1999-01-15 00:00:00
| End time:................... None
>>> rmap.metadata.print_info()
+-------------------- Metadata information ----------------------------------+
| Datatype:................... CELL
| Number of columns:.......... 8
| Number of rows:............. 12
| Number of cells:............ 96
| North-South resolution:..... 10.0
| East-west resolution:....... 10.0
| Minimum value:.............. 1.0
| Maximum value:.............. 1.0
>>> newmap = rmap.get_new_instance("new@PERMANENT")
>>> isinstance(newmap, RasterDataset)
True
>>> newstrds = rmap.get_new_stds_instance("new@PERMANENT")
>>> isinstance(newstrds, SpaceTimeRasterDataset)
True
>>> rmap.get_type()
'raster'
>>> rmap.set_absolute_time(start_time=datetime(2001,1,1),
... end_time=datetime(2012,1,1))
True
>>> rmap.get_absolute_time()
(datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 0, 0))
>>> rmap.get_temporal_extent_as_tuple()
(datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 0, 0))
>>> rmap.get_name()
'strds_map_test_case'
>>> rmap.get_mapset() == mapset
True
>>> rmap.get_temporal_type()
'absolute'
>>> rmap.get_spatial_extent_as_tuple()
(80.0, 0.0, 120.0, 0.0, 0.0, 0.0)
>>> rmap.is_time_absolute()
True
>>> rmap.is_time_relative()
False
>>> grass.run_command("g.remove", flags="f", type="raster", name=name, quiet=True)
0
>>> grass.del_temp_region()
Return a new space time dataset instance in which maps are stored with the type of this class
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 and assigned to the memmap object that is returned by this function.
In case the raster map does not exist, 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 array back into grass.
Check if a grass file bsased time stamp exists for this map.
Returns: | True if success, False on error |
---|
Return True if this class is a space time dataset
Returns: | True if this class is a space time dataset, False otherwise |
---|
Load all info from an existing raster map into the internal structure
This method checks first if the map exists, in case it exists the metadata of the map is put into this object and True is returned
Returns: | True is the map exists and the metadata was filled successfully and getting the data was successfull, False otherwise |
---|
Return True in case the map exists in the grass spatial database
Returns: | True if map exists, False otherwise |
---|
Read the timestamp of this map from the map metadata in the grass file system based spatial database and set the internal time stamp that should be insert/updated in the temporal database.
Returns: | True if success, False on error |
---|
Remove the timestamp from the grass file system based spatial database
Internally the libgis API functions are used for removal
Returns: | True if success, False on error |
---|
Return the two dimensional union as spatial_extent object.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Return the two dimensional intersection as spatial_extent object or None in case no intersection was found.
Parameters: | dataset – The abstract dataset to intersect with |
---|---|
Returns: | The intersection spatial extent or None |
Bases: temporal.abstract_space_time_dataset.AbstractSpaceTimeDataset
Space time raster3d dataset class
Return a new instance of a map dataset which is associated with the type of this class
Return True if this class is a space time dataset
Returns: | True if this class is a space time dataset, False otherwise |
---|
Return the three or two dimensional union as spatial_extent object.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Bases: temporal.abstract_space_time_dataset.AbstractSpaceTimeDataset
Space time raster dataset class
Return a new instance of a map dataset which is associated ” “with the type of this class
Return True if this class is a space time dataset
Returns: | True if this class is a space time dataset, False otherwise |
---|
Return the two dimensional union as spatial_extent object.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Bases: temporal.abstract_space_time_dataset.AbstractSpaceTimeDataset
Space time vector dataset class
Return a new instance of a map dataset which is associated with the type of this class
Return True if this class is a space time dataset
Returns: | True if this class is a space time dataset, False otherwise |
---|
Return the two dimensional union as spatial_extent object.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Bases: temporal.abstract_map_dataset.AbstractMapDataset
Vector dataset class
This class provides functions to select, update, insert or delete vector map information and valid time stamps into the SQL temporal database.
Usage:
>>> 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,
... t=1.0, b=0.0, res=10.0)
0
>>> grass.run_command("v.random", overwrite=True, output="stvds_map_test_case",
... n=100, zmin=0, zmax=100, flags="z", column="elevation", quiet=True)
0
>>> grass.run_command("v.timestamp", map="stvds_map_test_case",
... date="15 jan 1999", quiet=True)
0
>>> mapset = get_current_mapset()
>>> name = "stvds_map_test_case"
>>> identifier = "%s@%s" % (name, mapset)
>>> vmap = VectorDataset(identifier)
>>> vmap.map_exists()
True
>>> vmap.read_timestamp_from_grass()
True
>>> vmap.get_temporal_extent_as_tuple()
(datetime.datetime(1999, 1, 15, 0, 0), None)
>>> vmap.load()
True
>>> vmap.absolute_time.print_info()
+-------------------- Absolute time -----------------------------------------+
| Start time:................. 1999-01-15 00:00:00
| End time:................... None
>>> vmap.metadata.print_info()
+-------------------- Metadata information ----------------------------------+
| Is map 3d .................. True
| Number of points ........... 100
| Number of lines ............ 0
| Number of boundaries ....... 0
| Number of centroids ........ 0
| Number of faces ............ 0
| Number of kernels .......... 0
| Number of primitives ....... 100
| Number of nodes ............ 0
| Number of areas ............ 0
| Number of islands .......... 0
| Number of holes ............ 0
| Number of volumes .......... 0
>>> newmap = vmap.get_new_instance("new@PERMANENT")
>>> isinstance(newmap, VectorDataset)
True
>>> newstvds = vmap.get_new_stds_instance("new@PERMANENT")
>>> isinstance(newstvds, SpaceTimeVectorDataset)
True
>>> vmap.get_type()
'vector'
>>> vmap.set_absolute_time(start_time=datetime(2001,1,1),
... end_time=datetime(2012,1,1))
True
>>> vmap.get_absolute_time()
(datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 0, 0))
>>> vmap.get_temporal_extent_as_tuple()
(datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2012, 1, 1, 0, 0))
>>> vmap.get_name()
'stvds_map_test_case'
>>> vmap.get_mapset() == mapset
True
>>> vmap.get_temporal_type()
'absolute'
>>> vmap.is_time_absolute()
True
>>> vmap.is_time_relative()
False
>>> grass.run_command("g.remove", flags="f", type="vector", name=name, quiet=True)
0
>>> grass.del_temp_region()
Return a new space time dataset instance in which maps are stored with the type of this class
Return True if this class is a space time dataset
Returns: | True if this class is a space time dataset, False otherwise |
---|
Load all info from an existing vector map into the internal structure
This method checks first if the map exists, in case it exists the metadata of the map is put into this object and True is returned
Returns: | True is the map exists and the metadata was filled successfully and getting the data was successfull, False otherwise |
---|
Return True in case the map exists in the grass spatial database
Returns: | True if map exists, False otherwise |
---|
Read the timestamp of this map from the map metadata in the grass file system based spatial database and set the internal time stamp that should be insert/updated in the temporal database.
Remove the timestamp from the grass file system based spatial database
Internally the libgis API functions are used for removal
Return the two dimensional union as spatial_extent object.
Parameters: | dataset – The abstract dataset to create a union with |
---|---|
Returns: | The union spatial extent |
Return the two dimensional intersection as spatial_extent object or None in case no intersection was found.
Parameters: | dataset – The abstract dataset to intersect with |
---|---|
Returns: | The intersection spatial extent or None |
Spatial extents classes for map layer and space time datasets
Usage:
>>> import grass.temporal as tgis
>>> tgis.init()
>>> extent = tgis.RasterSpatialExtent(
... ident="raster@PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
>>> extent = tgis.Raster3DSpatialExtent(
... ident="raster3d@PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
>>> extent = tgis.VectorSpatialExtent(
... ident="vector@PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
>>> extent = tgis.STRDSSpatialExtent(
... ident="strds@PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
>>> extent = tgis.STR3DSSpatialExtent(
... ident="str3ds@PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
>>> extent = tgis.STVDSSpatialExtent(
... ident="stvds@PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: temporal.base.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:
>>> init()
>>> extent = SpatialExtent(table="raster_spatial_extent",
... ident="soil@PERMANENT", north=90, south=90, east=180, west=180,
... top=100, bottom=-20)
>>> extent.id
'soil@PERMANENT'
>>> extent.north
90.0
>>> extent.south
90.0
>>> extent.east
180.0
>>> extent.west
180.0
>>> extent.top
100.0
>>> extent.bottom
-20.0
>>> extent.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 90.0
| South:...................... 90.0
| East:.. .................... 180.0
| West:....................... 180.0
| Top:........................ 100.0
| Bottom:..................... -20.0
>>> extent.print_shell_info()
north=90.0
south=90.0
east=180.0
west=180.0
top=100.0
bottom=-20.0
Get the bottom edge of the map :return: None if not found
Return True if this extent (A) contains the provided spatial extent (B) in three dimensions.
Usage:
>>> A = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
>>> B = SpatialExtent(north=79, south=21, east=59, west=11,
... bottom=-49, top=49)
>>> A.contain(B)
True
>>> B.contain(A)
False
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent (A) contains the provided spatial extent (B) in two dimensions.
Usage:
>>> 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
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent covers the provided spatial extent in three dimensions.
The following cases are excluded:
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent (A) covers the provided spatial extent (B) in two dimensions.
_____ _____ _____ _____
|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
The following cases are excluded:
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent is covered by the provided spatial extent in three dimensions.
The following cases are excluded:
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent is covered by the provided spatial extent in two dimensions.
The following cases are excluded:
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent is disjoint with the provided spatial extent in three dimensions.
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent (A) is disjoint with the provided spatial extent (B) in three dimensions.
_____
| A |
|_____|
_______
| B |
|_______|
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return the three dimensional union as spatial_extent .
Usage:
>>> 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)
>>> C = A.disjoint_union(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 20.0
| East:.. .................... 60.0
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=10,
... bottom=-50, top=50)
>>> C = A.disjoint_union(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 20.0
| East:.. .................... 60.0
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-50, top=50)
>>> C = A.disjoint_union(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 20.0
| East:.. .................... 60.0
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=50)
>>> C = A.disjoint_union(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 20.0
| East:.. .................... 60.0
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=30)
>>> C = A.disjoint_union(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 20.0
| East:.. .................... 60.0
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> A = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
>>> B = SpatialExtent(north=90, south=80, east=70, west=20,
... bottom=-30, top=60)
>>> C = A.disjoint_union(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 90.0
| South:...................... 20.0
| East:.. .................... 70.0
| West:....................... 10.0
| Top:........................ 60.0
| Bottom:..................... -50.0
:param extent: The spatial extent to create a disjoint union with
:return: The union spatial extent
Return the two dimensional union as spatial_extent.
Parameters: | extent – The spatial extent to create a union with |
---|---|
Returns: | The union spatial extent |
Get the eastern edge of the map :return: None if not found
Return True if this extent (A) is equal to the provided spatial extent (B) in three dimensions.
Usage:
>>> 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.equivalent(B)
True
>>> B.equivalent(A)
True
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent (A) is equal to the provided spatial extent (B) in two dimensions.
Usage:
>>> 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
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Convenient method to get the unique identifier (primary key) :return: None if not found
Return a tuple (north, south, east, west, top, bottom) of the spatial extent
Return a tuple (north, south, east, west,) of the 2d spatial extent
Compute the volume of the extent, in case z is zero (top == bottom or top - bottom = 1) the area is returned
Convenient method to get the unique identifier (primary key) :return: None if not found
Return the three dimensional intersection as spatial_extent object or None in case no intersection was found.
Usage:
>>> 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)
>>> C = A.intersect(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 80.0
| South:...................... 20.0
| East:.. .................... 60.0
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=10,
... bottom=-50, top=50)
>>> C = A.intersect(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 40.0
| South:...................... 30.0
| East:.. .................... 60.0
| West:....................... 10.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-50, top=50)
>>> C = A.intersect(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 40.0
| South:...................... 30.0
| East:.. .................... 60.0
| West:....................... 30.0
| Top:........................ 50.0
| Bottom:..................... -50.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=50)
>>> C = A.intersect(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 40.0
| South:...................... 30.0
| East:.. .................... 60.0
| West:....................... 30.0
| Top:........................ 50.0
| Bottom:..................... -30.0
>>> B = SpatialExtent(north=40, south=30, east=60, west=30,
... bottom=-30, top=30)
>>> C = A.intersect(B)
>>> C.print_info()
+-------------------- Spatial extent ----------------------------------------+
| North:...................... 40.0
| South:...................... 30.0
| East:.. .................... 60.0
| West:....................... 30.0
| Top:........................ 30.0
| Bottom:..................... -30.0
:param extent: The spatial extent to intersect with
:return: The intersection spatial extent
Parameters: | extent – The spatial extent to intersect with |
---|---|
Returns: | The intersection spatial extent |
Return True if this extent (A) is located in the provided spatial extent (B) in three dimensions.
Usage:
>>> A = SpatialExtent(north=79, south=21, east=59, west=11,
... bottom=-49, top=49)
>>> B = SpatialExtent(north=80, south=20, east=60, west=10,
... bottom=-50, top=50)
>>> A.is_in(B)
True
>>> B.is_in(A)
False
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent (A) is located in the provided spatial extent (B) in two dimensions.
_____
|A _ |
| |_| |
|_____|B
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent meets with the provided spatial extent in three dimensions.
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this extent (A) meets with the provided spatial extent (B) in two dimensions.
_____ _____
| A | B |
|_____| |
|_____|
_____ _____
| B | A |
| | |
|_____|_____|
___
| A |
| |
|___|
| B |
| |
|_____|
_____
| B |
| |
|_____|_
| A |
| |
|_____|
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Get the northern edge of the map :return: None if not found
Return True if this extent overlaps with the provided spatial extent in three dimensions.
The following cases are excluded:
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
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
_____
|A __|__
| | | B|
|__|__| |
|_____|
The following cases are excluded:
Parameters: | extent – The spatial extent |
---|---|
Returns: | True or False |
Return True if this (A) and the provided spatial extent (B) overlaps in three dimensional space.
Overlapping includes the spatial relations:
Usage:
>>> 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
Parameters: | extent – The spatial extent to check overlapping with |
---|---|
Returns: | True or False |
Return True if this (A) and the provided spatial extent (B) overlaps in two dimensional space. Code is lend from wind_overlap.c in lib/gis
Overlapping includes the spatial relations:
>>> 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
Parameters: | extent – The spatial extent to check overlapping with |
---|---|
Returns: | True or False |
Set the projection of the spatial extent it should be XY or LL. As default the projection is XY
Set the three dimensional spatial extent
Parameters: | spatial_extent – An object of type SpatialExtent or its subclasses |
---|
Set the three dimensional spatial extent
Parameters: | spatial_extent – An object of type SpatialExtent or its subclasses |
---|
Set the three dimensional spatial extent
Parameters: |
|
---|
Set the two dimensional spatial extent from values
Parameters: |
|
---|
Get the southern edge of the map :return: None if not found
Returns the two dimensional spatial relation between this extent and the provided spatial extent in three dimensions.
Spatial relations are:
Usage:
>>> 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)
'equivalent'
>>> B.spatial_relation(A)
'equivalent'
>>> B = SpatialExtent(north=70, south=20, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'cover'
>>> A.spatial_relation(B)
'cover'
>>> B = SpatialExtent(north=70, south=30, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'cover'
>>> A.spatial_relation(B)
'cover'
>>> B.spatial_relation_2d(A)
'covered'
>>> B.spatial_relation(A)
'covered'
>>> B = SpatialExtent(north=70, south=30, east=50, west=10, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'cover'
>>> B.spatial_relation_2d(A)
'covered'
>>> A.spatial_relation(B)
'cover'
>>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-50, top=50)
>>> B.spatial_relation(A)
'covered'
>>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'contain'
>>> A.spatial_relation(B)
'cover'
>>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-40, top=50)
>>> A.spatial_relation(B)
'cover'
>>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-40, top=40)
>>> A.spatial_relation(B)
'contain'
>>> B.spatial_relation(A)
'in'
>>> B = SpatialExtent(north=90, south=30, east=50, west=20, bottom=-40, top=40)
>>> A.spatial_relation_2d(B)
'overlap'
>>> A.spatial_relation(B)
'overlap'
>>> B = SpatialExtent(north=90, south=5, east=70, west=5, bottom=-40, top=40)
>>> A.spatial_relation_2d(B)
'in'
>>> A.spatial_relation(B)
'overlap'
>>> B = SpatialExtent(north=90, south=5, east=70, west=5, bottom=-40, top=60)
>>> A.spatial_relation(B)
'overlap'
>>> B = SpatialExtent(north=90, south=5, east=70, west=5, bottom=-60, top=60)
>>> A.spatial_relation(B)
'in'
>>> A = SpatialExtent(north=80, south=60, east=60, west=10, bottom=-50, top=50)
>>> B = SpatialExtent(north=60, south=20, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'meet'
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=60, south=40, east=60, west=10, bottom=-50, top=50)
>>> B = SpatialExtent(north=80, south=60, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'meet'
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=40, bottom=-50, top=50)
>>> B = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'meet'
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
>>> B = SpatialExtent(north=90, south=30, east=60, west=40, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'meet'
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
>>> B = SpatialExtent(north=70, south=50, east=60, west=40, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'meet'
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
>>> B = SpatialExtent(north=60, south=20, east=60, west=40, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'meet'
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
>>> B = SpatialExtent(north=40, south=20, east=60, west=40, bottom=-50, top=50)
>>> A.spatial_relation_2d(B)
'disjoint'
>>> A.spatial_relation(B)
'disjoint'
>>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
>>> B = SpatialExtent(north=60, south=20, east=60, west=40, bottom=-60, top=60)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
>>> B = SpatialExtent(north=90, south=30, east=60, west=40, bottom=-40, top=40)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
>>> B = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
>>> B = SpatialExtent(north=80, south=50, east=60, west=30, bottom=-50, top=0)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
>>> B = SpatialExtent(north=70, south=50, east=50, west=30, bottom=-50, top=0)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
>>> B = SpatialExtent(north=90, south=30, east=70, west=10, bottom=-50, top=0)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
>>> B = SpatialExtent(north=70, south=30, east=50, west=10, bottom=-50, top=0)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
>>> B = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
>>> B = SpatialExtent(north=80, south=50, east=60, west=30, bottom=0, top=50)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
>>> B = SpatialExtent(north=70, south=50, east=50, west=30, bottom=0, top=50)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
>>> B = SpatialExtent(north=90, south=30, east=70, west=10, bottom=0, top=50)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
>>> B = SpatialExtent(north=70, south=30, east=50, west=10, bottom=0, top=50)
>>> A.spatial_relation(B)
'meet'
>>> A = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
>>> B = SpatialExtent(north=90, south=81, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation(B)
'disjoint'
>>> A = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
>>> B = SpatialExtent(north=90, south=80, east=60, west=10, bottom=-50, top=50)
>>> A.spatial_relation(B)
'meet'
Returns the two dimensional spatial relation between this extent and the provided spatial extent in two dimensions.
Spatial relations are:
Usage: see self.spatial_relation()
Get the top edge of the map :return: None if not found
Parameters: | extent – The spatial extent to create a union with |
---|---|
Returns: | The union spatial extent |
Parameters: | extent – The spatial extent to create a union with |
---|---|
Returns: | The union spatial extent |
Get the western edge of the map :return: None if not found
Spatial topology connector class
Usage:
>>> import grass.temporal as tgis
>>> tmr = tgis.SpatialTopologyDatasetConnector()
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: object
This class implements a spatial topology access structure to connect spatial related datasets
This object will be set up by spatial topology creation method provided by the SpatioTemporalTopologyBuilder.
The following spatial relations with access methods are supported:
Usage:
>>> import grass.temporal as tgis >>> tgis.init() >>> map = tgis.RasterDataset("a@P") >>> tmr = tgis.SpatialTopologyDatasetConnector() >>> tmr.append_equivalent(map) >>> tmr.append_overlap(map) >>> tmr.append_in(map) >>> tmr.append_contain(map) >>> tmr.append_meet(map) >>> tmr.append_cover(map) >>> tmr.append_covered(map) >>> tmr.print_spatial_topology_info() +-------------------- Spatial Topology --------------------------------------+ | Equivalent: ................ a@P | Cover: ..................... a@P | Covered: ................... a@P | Overlap: ................... a@P | In: ........................ a@P | Contain: ................... a@P | Meet: ...................... a@P >>> tmr.print_spatial_topology_shell_info() equivalent=a@P cover=a@P covered=a@P overlap=a@P in=a@P contain=a@P meet=a@P >>> rlist = tmr.get_spatial_relations() >>> if "COVER" in rlist.keys(): ... print rlist["COVER"][0].get_id() a@P
Append a map that this map spatially contains
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that spatially cover this map
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that is spatially covered by this map
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map with equivalent spatial extent as this map
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this is spatial in this map
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that spatially meet with this map
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this spatial overlap with this map
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Return a list of map objects that this map contains
Returns: | A list of map objects or None |
---|
Return a list of map objects that spatially cover this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that are spatially covered by this map
Returns: | A list of map objects or None |
---|
Return a list of map objects with equivalent spatial extent as this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map contains
Returns: | A list of map objects or None |
---|
Return a list of map objects that spatially cover this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that are spatially covered by this map
Returns: | A list of map objects or None |
---|
Return a list of map objects with equivalent spatial extent as this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that are spatial in this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that spatially meet with this map
Returns: | A list of map objects or None |
---|
Return a dictionary in which the keys are the relation names and the value are the number of relations.
The following relations are available:
To access topological information the spatial topology must be build first using the SpatialTopologyBuilder.
Returns: | the dictionary with relations as keys and number as values or None in case the topology wasn’t build |
---|
Return a list of map objects that this map spatial overlap with
Returns: | A list of map objects or None |
---|
Return the dictionary of spatial relationships
Keys are the spatial relationships in upper case, values are abstract map objects.
Returns: | The spatial relations dictionary |
---|
Return a list of map objects that are spatial in this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that spatially meet with this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map spatial overlap with
Returns: | A list of map objects or None |
---|
Class to build the spatio-temporal topology between map lists
Usage:
import grass.temporal as tgis
tgis.print_temporal_relations(maps)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: object
This class is designed to build the spatio-temporal topology of spatio-temporally related abstract dataset objects.
The abstract dataset objects must be provided as a single list, or in two lists.
Example:
# We have a space time raster dataset and build a map list # from all registered maps ordered by start time maps = strds.get_registered_maps_as_objects() # Now lets build the temporal topology of the maps in the list tb = SpatioTemporalTopologyBuilder() tb.build(maps) dbif, connected = init_dbif(None) for map in tb: map.select(dbif) map.print_info() # Same can be done with the existing map list # But be aware that this is might not be temporally ordered for map in maps: map.select(dbf) map.print_info() # Using the next and previous methods, we can iterate over the # topological related maps in this way first = tb.get_first() while first: first.print_topology_info() first = first.next() # Dictionary like accessed map = tb["name@mapset"] >>> # Example with two lists of maps >>> import grass.temporal as tgis >>> import datetime >>> # Create two list of maps with equal time stamps >>> mapsA = [] >>> mapsB = [] >>> for i in range(4): ... idA = "a%i@B"%(i) ... mapA = tgis.RasterDataset(idA) ... idB = "b%i@B"%(i) ... mapB = tgis.RasterDataset(idB) ... check = mapA.set_relative_time(i, i + 1, "months") ... check = mapB.set_relative_time(i, i + 1, "months") ... mapsA.append(mapA) ... mapsB.append(mapB) >>> # Build the topology between the two map lists >>> tb = SpatioTemporalTopologyBuilder() >>> tb.build(mapsA, mapsB, None) >>> # Check relations of mapsA >>> for map in mapsA: ... if map.get_equal(): ... relations = map.get_equal() ... print "Map %s has equal relation to map %s"%(map.get_name(), ... relations[0].get_name()) Map a0 has equal relation to map b0 Map a1 has equal relation to map b1 Map a2 has equal relation to map b2 Map a3 has equal relation to map b3 >>> # Check relations of mapsB >>> for map in mapsB: ... if map.get_equal(): ... relations = map.get_equal() ... print "Map %s has equal relation to map %s"%(map.get_name(), ... relations[0].get_name()) Map b0 has equal relation to map a0 Map b1 has equal relation to map a1 Map b2 has equal relation to map a2 Map b3 has equal relation to map a3 >>> mapsA = [] >>> mapsB = [] >>> for i in range(4): ... idA = "a%i@B"%(i) ... mapA = tgis.RasterDataset(idA) ... idB = "b%i@B"%(i) ... mapB = tgis.RasterDataset(idB) ... check = mapA.set_relative_time(i, i + 1, "months") ... check = mapB.set_relative_time(i + 1, i + 2, "months") ... mapsA.append(mapA) ... mapsB.append(mapB) >>> # Build the topology between the two map lists >>> tb = SpatioTemporalTopologyBuilder() >>> tb.build(mapsA, mapsB, None) >>> # Check relations of mapsA >>> for map in mapsA: ... print(map.get_temporal_extent_as_tuple()) ... m = map.get_temporal_relations() ... for key in m.keys(): ... if key not in ["NEXT", "PREV"]: ... print(key, m[key][0].get_temporal_extent_as_tuple()) (0, 1) ('PRECEDES', (1, 2)) (1, 2) ('PRECEDES', (2, 3)) ('EQUAL', (1, 2)) (2, 3) ('FOLLOWS', (1, 2)) ('PRECEDES', (3, 4)) ('EQUAL', (2, 3)) (3, 4) ('FOLLOWS', (2, 3)) ('EQUAL', (3, 4)) ('PRECEDES', (4, 5)) >>> mapsA = [] >>> mapsB = [] >>> for i in range(4): ... idA = "a%i@B"%(i) ... mapA = tgis.RasterDataset(idA) ... idB = "b%i@B"%(i) ... mapB = tgis.RasterDataset(idB) ... start = datetime.datetime(2000 + i, 1, 1) ... end = datetime.datetime(2000 + i + 1, 1, 1) ... check = mapA.set_absolute_time(start, end) ... start = datetime.datetime(2000 + i + 1, 1, 1) ... end = datetime.datetime(2000 + i + 2, 1, 1) ... check = mapB.set_absolute_time(start, end) ... mapsA.append(mapA) ... mapsB.append(mapB) >>> # Build the topology between the two map lists >>> tb = SpatioTemporalTopologyBuilder() >>> tb.build(mapsA, mapsB, None) >>> # Check relations of mapsA >>> for map in mapsA: ... print(map.get_temporal_extent_as_tuple()) ... m = map.get_temporal_relations() ... for key in m.keys(): ... if key not in ["NEXT", "PREV"]: ... print(key, m[key][0].get_temporal_extent_as_tuple()) (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0)) ('PRECEDES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0))) (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0)) ('PRECEDES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('EQUAL', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0))) (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)) ('FOLLOWS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0))) ('PRECEDES', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('EQUAL', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)) ('FOLLOWS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('EQUAL', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('PRECEDES', (datetime.datetime(2004, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) >>> mapsA = [] >>> mapsB = [] >>> for i in range(4): ... idA = "a%i@B"%(i) ... mapA = tgis.RasterDataset(idA) ... idB = "b%i@B"%(i) ... mapB = tgis.RasterDataset(idB) ... start = datetime.datetime(2000 + i, 1, 1) ... end = datetime.datetime(2000 + i + 1, 1, 1) ... check = mapA.set_absolute_time(start, end) ... start = datetime.datetime(2000 + i, 1, 1) ... end = datetime.datetime(2000 + i + 3, 1, 1) ... check = mapB.set_absolute_time(start, end) ... mapsA.append(mapA) ... mapsB.append(mapB) >>> # Build the topology between the two map lists >>> tb = SpatioTemporalTopologyBuilder() >>> tb.build(mapsA, mapsB, None) >>> # Check relations of mapsA >>> for map in mapsA: ... print(map.get_temporal_extent_as_tuple()) ... m = map.get_temporal_relations() ... for key in m.keys(): ... if key not in ["NEXT", "PREV"]: ... print(key, m[key][0].get_temporal_extent_as_tuple()) (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0)) ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('PRECEDES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0)) ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('PRECEDES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)) ('PRECEDES', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0))) ('FINISHES', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)) ('FOLLOWS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('DURING', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('FINISHES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0))) >>> mapsA = [] >>> mapsB = [] >>> for i in range(4): ... idA = "a%i@B"%(i) ... mapA = tgis.RasterDataset(idA) ... idB = "b%i@B"%(i) ... mapB = tgis.RasterDataset(idB) ... start = datetime.datetime(2000 + i, 1, 1) ... end = datetime.datetime(2000 + i + 2, 1, 1) ... check = mapA.set_absolute_time(start, end) ... start = datetime.datetime(2000 + i, 1, 1) ... end = datetime.datetime(2000 + i + 3, 1, 1) ... check = mapB.set_absolute_time(start, end) ... mapsA.append(mapA) ... mapsB.append(mapB) >>> # Build the topology between the two map lists >>> tb = SpatioTemporalTopologyBuilder() >>> tb.build(mapsA, mapsB, None) >>> # Check relations of mapsA >>> for map in mapsA: ... print(map.get_temporal_extent_as_tuple()) ... m = map.get_temporal_relations() ... for key in m.keys(): ... if key not in ["NEXT", "PREV"]: ... print(key, m[key][0].get_temporal_extent_as_tuple()) (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0)) ('OVERLAPS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('PRECEDES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)) ('OVERLAPS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) ('PRECEDES', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0))) ('FINISHES', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)) ('OVERLAPS', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0))) ('OVERLAPPED', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) ('FINISHES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('DURING', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)) ('OVERLAPPED', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))) ('DURING', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) ('FINISHES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))) ('STARTS', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0))) ('FOLLOWS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))) >>> mapsA = [] >>> mapsB = [] >>> for i in range(4): ... idA = "a%i@B"%(i) ... mapA = tgis.RasterDataset(idA) ... idB = "b%i@B"%(i) ... mapB = tgis.RasterDataset(idB) ... start = datetime.datetime(2000, 1, 1, 0, 0, i) ... end = datetime.datetime(2000, 1, 1, 0, 0, i + 2) ... check = mapA.set_absolute_time(start, end) ... start = datetime.datetime(2000, 1, 1, 0, 0, i + 1) ... end = datetime.datetime(2000, 1, 1, 0, 0, i + 3) ... check = mapB.set_absolute_time(start, end) ... mapsA.append(mapA) ... mapsB.append(mapB) >>> # Build the topology between the two map lists >>> tb = SpatioTemporalTopologyBuilder() >>> tb.build(mapsA, mapsB, None) >>> # Check relations of mapsA >>> for map in mapsA: ... print(map.get_temporal_extent_as_tuple()) ... m = map.get_temporal_relations() ... for key in m.keys(): ... if key not in ["NEXT", "PREV"]: ... print(key, m[key][0].get_temporal_extent_as_tuple()) (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2000, 1, 1, 0, 0, 2)) ('OVERLAPS', (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3))) ('PRECEDES', (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4))) (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3)) ('OVERLAPS', (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4))) ('PRECEDES', (datetime.datetime(2000, 1, 1, 0, 0, 3), datetime.datetime(2000, 1, 1, 0, 0, 5))) ('EQUAL', (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3))) (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4)) ('OVERLAPS', (datetime.datetime(2000, 1, 1, 0, 0, 3), datetime.datetime(2000, 1, 1, 0, 0, 5))) ('OVERLAPPED', (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3))) ('PRECEDES', (datetime.datetime(2000, 1, 1, 0, 0, 4), datetime.datetime(2000, 1, 1, 0, 0, 6))) ('EQUAL', (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4))) (datetime.datetime(2000, 1, 1, 0, 0, 3), datetime.datetime(2000, 1, 1, 0, 0, 5)) ('OVERLAPS', (datetime.datetime(2000, 1, 1, 0, 0, 4), datetime.datetime(2000, 1, 1, 0, 0, 6))) ('FOLLOWS', (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3))) ('OVERLAPPED', (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4))) ('EQUAL', (datetime.datetime(2000, 1, 1, 0, 0, 3), datetime.datetime(2000, 1, 1, 0, 0, 5))) >>> mapsA = [] >>> for i in range(4): ... idA = "a%i@B"%(i) ... mapA = tgis.RasterDataset(idA) ... start = datetime.datetime(2000, 1, 1, 0, 0, i) ... end = datetime.datetime(2000, 1, 1, 0, 0, i + 2) ... check = mapA.set_absolute_time(start, end) ... mapsA.append(mapA) >>> tb = SpatioTemporalTopologyBuilder() >>> tb.build(mapsA) >>> # Check relations of mapsA >>> for map in mapsA: ... print(map.get_temporal_extent_as_tuple()) ... m = map.get_temporal_relations() ... for key in m.keys(): ... if key not in ["NEXT", "PREV"]: ... print(key, m[key][0].get_temporal_extent_as_tuple()) (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2000, 1, 1, 0, 0, 2)) ('OVERLAPS', (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3))) ('PRECEDES', (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4))) (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3)) ('OVERLAPS', (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4))) ('OVERLAPPED', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2000, 1, 1, 0, 0, 2))) ('PRECEDES', (datetime.datetime(2000, 1, 1, 0, 0, 3), datetime.datetime(2000, 1, 1, 0, 0, 5))) (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4)) ('OVERLAPS', (datetime.datetime(2000, 1, 1, 0, 0, 3), datetime.datetime(2000, 1, 1, 0, 0, 5))) ('FOLLOWS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2000, 1, 1, 0, 0, 2))) ('OVERLAPPED', (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3))) (datetime.datetime(2000, 1, 1, 0, 0, 3), datetime.datetime(2000, 1, 1, 0, 0, 5)) ('FOLLOWS', (datetime.datetime(2000, 1, 1, 0, 0, 1), datetime.datetime(2000, 1, 1, 0, 0, 3))) ('OVERLAPPED', (datetime.datetime(2000, 1, 1, 0, 0, 2), datetime.datetime(2000, 1, 1, 0, 0, 4)))
Build the spatio-temporal topology structure between one or two unordered lists of abstract dataset objects
This method builds the temporal or spatio-temporal topology from mapsA to mapsB and vice verse. The spatio-temporal topology structure of each map will be reseted and rebuild for mapsA and mapsB.
After building the temporal or spatio-temporal topology the modified map objects of mapsA can be accessed in the same way as a dictionary using there id. The implemented iterator assures the chronological iteration over the mapsA.
Parameters: |
|
---|
Count the temporal relations of a single list of maps or between two lists of maps
param maps1: A list of abstract_dataset objects with initiated temporal extent param maps2: A list of abstract_dataset objects with initiated temporal extent param dbif: The database interface to be used return: A dictionary with counted temporal relationships
Create a SQL WHERE statement for temporal relation selection of maps in space time datasets
param start: The start time
param end: The end time
param use_start: Select maps of which the start time is located in the selection granule
map : s granule: s-----------------e map : s--------------------e granule: s-----------------e map : s--------e granule: s-----------------eparam use_during: Select maps which are temporal during the selection granule
map : s-----------e granule: s-----------------eparam use_overlap: Select maps which temporal overlap the selection granule
map : s-----------e granule: s-----------------e map : s-----------e granule: s----------eparam use_contain: Select maps which temporally contain the selection granule
map : s-----------------e granule: s-----------eparam use_equal: Select maps which temporally equal to the selection granule
map : s-----------e granule: s-----------eparam use_follows: Select maps which temporally follow the selection granule
map : s-----------e granule: s-----------eparam use_precedes: Select maps which temporally precedes the selection granule
map : s-----------e granule: s-----------eUsage:
>>> # Relative time >>> start = 1 >>> end = 2 >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False) >>> create_temporal_relation_sql_where_statement(start, end) '((start_time >= 1 and start_time < 2) )' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=True) '((start_time >= 1 and start_time < 2) )' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_during=True) '(((start_time > 1 and end_time < 2) OR (start_time >= 1 and end_time < 2) OR (start_time > 1 and end_time <= 2)))' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_overlap=True) '(((start_time < 1 and end_time > 1 and end_time < 2) OR (start_time < 2 and start_time > 1 and end_time > 2)))' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_contain=True) '(((start_time < 1 and end_time > 2) OR (start_time <= 1 and end_time > 2) OR (start_time < 1 and end_time >= 2)))' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_equal=True) '((start_time = 1 and end_time = 2))' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_follows=True) '((start_time = 2))' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_precedes=True) '((end_time = 1))' >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=True, use_during=True, use_overlap=True, use_contain=True, ... use_equal=True, use_follows=True, use_precedes=True) '((start_time >= 1 and start_time < 2) OR ((start_time > 1 and end_time < 2) OR (start_time >= 1 and end_time < 2) OR (start_time > 1 and end_time <= 2)) OR ((start_time < 1 and end_time > 1 and end_time < 2) OR (start_time < 2 and start_time > 1 and end_time > 2)) OR ((start_time < 1 and end_time > 2) OR (start_time <= 1 and end_time > 2) OR (start_time < 1 and end_time >= 2)) OR (start_time = 1 and end_time = 2) OR (start_time = 2) OR (end_time = 1))' >>> # Absolute time >>> start = datetime(2001, 1, 1, 12, 30) >>> end = datetime(2001, 3, 31, 14, 30) >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False) >>> create_temporal_relation_sql_where_statement(start, end) "((start_time >= '2001-01-01 12:30:00' and start_time < '2001-03-31 14:30:00') )" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=True) "((start_time >= '2001-01-01 12:30:00' and start_time < '2001-03-31 14:30:00') )" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_during=True) "(((start_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time >= '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time > '2001-01-01 12:30:00' and end_time <= '2001-03-31 14:30:00')))" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_overlap=True) "(((start_time < '2001-01-01 12:30:00' and end_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time < '2001-03-31 14:30:00' and start_time > '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00')))" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_contain=True) "(((start_time < '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time <= '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time < '2001-01-01 12:30:00' and end_time >= '2001-03-31 14:30:00')))" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_equal=True) "((start_time = '2001-01-01 12:30:00' and end_time = '2001-03-31 14:30:00'))" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_follows=True) "((start_time = '2001-03-31 14:30:00'))" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=False, use_precedes=True) "((end_time = '2001-01-01 12:30:00'))" >>> create_temporal_relation_sql_where_statement(start, end, ... use_start=True, use_during=True, use_overlap=True, use_contain=True, ... use_equal=True, use_follows=True, use_precedes=True) "((start_time >= '2001-01-01 12:30:00' and start_time < '2001-03-31 14:30:00') OR ((start_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time >= '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time > '2001-01-01 12:30:00' and end_time <= '2001-03-31 14:30:00')) OR ((start_time < '2001-01-01 12:30:00' and end_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time < '2001-03-31 14:30:00' and start_time > '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00')) OR ((start_time < '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time <= '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time < '2001-01-01 12:30:00' and end_time >= '2001-03-31 14:30:00')) OR (start_time = '2001-01-01 12:30:00' and end_time = '2001-03-31 14:30:00') OR (start_time = '2001-03-31 14:30:00') OR (end_time = '2001-01-01 12:30:00'))"
Print the temporal relationships of the map lists maps1 and maps2 to stdout.
param maps1: A list of abstract_dataset objects with initiated temporal extent param maps2: An optional list of abstract_dataset objects with initiated temporal extent param spatial: The dimension of the spatial extent to be used: “2D” using west, east, south, north or “3D” using west, east, south, north, bottom, top param dbif: The database interface to be used
Print the temporal relationships of the map lists maps1 and maps2 to stdout.
param maps1: A list of abstract_dataset objects with initiated temporal extent param maps2: An optional list of abstract_dataset objects with initiated temporal extent param dbif: The database interface to be used
Export functions for space time datasets
Usage:
import grass.temporal as tgis
input="temp_1950_2012@PERMANENT"
output="/tmp/temp_1950_2012.tar.gz"
compression="gzip"
directory="/tmp"
where=None
format_="GTiff"
type_="strds"
tgis.export_stds(input, output, compression, directory, where, format_, type_)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Export space time datasets as tar archive with optional compression
This method should be used to export space time datasets of type raster and vector as tar archive that can be reimported with the method import_stds().
Parameters: |
|
---|
Space time dataset import functions
Usage:
import grass.temporal as tgis
input="/tmp/temp_1950_2012.tar.gz"
output="temp_1950_2012"
directory="/tmp"
title="My new dataset"
descr="May new shiny dataset"
location=None
link=True
exp=True
overr=False
create=False
tgis.import_stds(input, output, directory, title, descr, location,
link, exp, overr, create, "strds")
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Import space time datasets of type raster and vector
Parameters: |
|
---|
@package grass.temporal
Temporal algebra parser class
(C) 2014 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Thomas Leppelt and Soeren Gebbert |
---|
>>> import grass.temporal as tgis
>>> tgis.init(True)
>>> p = tgis.TemporalAlgebraLexer()
>>> p.build()
>>> p.debug = True
>>> expression = "C = A : B"
>>> p.test(expression)
C = A : B
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'A',1,4)
LexToken(T_SELECT,':',1,6)
LexToken(NAME,'B',1,8)
>>> expression = "C = test1 !: test2"
>>> p.test(expression)
C = test1 !: test2
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(T_NOT_SELECT,'!:',1,10)
LexToken(NAME,'test2',1,13)
>>> expression = "C = test1 {:,equal} test2"
>>> p.test(expression)
C = test1 {:,equal} test2
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(T_SELECT_OPERATOR,'{:,equal}',1,10)
LexToken(NAME,'test2',1,20)
>>> expression = "C = test1 {!:,equal} test2"
>>> p.test(expression)
C = test1 {!:,equal} test2
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(T_SELECT_OPERATOR,'{!:,equal}',1,10)
LexToken(NAME,'test2',1,21)
>>> expression = "C = test1 # test2"
>>> p.test(expression)
C = test1 # test2
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(HASH,'#',1,10)
LexToken(NAME,'test2',1,12)
>>> expression = "C = test1 {#} test2"
>>> p.test(expression)
C = test1 {#} test2
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(T_HASH_OPERATOR,'{#}',1,10)
LexToken(NAME,'test2',1,14)
>>> expression = "C = test1 {#,equal} test2"
>>> p.test(expression)
C = test1 {#,equal} test2
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(T_HASH_OPERATOR,'{#,equal}',1,10)
LexToken(NAME,'test2',1,20)
>>> expression = "C = test1 {#,equal|during} test2"
>>> p.test(expression)
C = test1 {#,equal|during} test2
LexToken(NAME,'C',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(T_HASH_OPERATOR,'{#,equal|during}',1,10)
LexToken(NAME,'test2',1,27)
>>> expression = "E = test1 : test2 !: test1"
>>> p.test(expression)
E = test1 : test2 !: test1
LexToken(NAME,'E',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'test1',1,4)
LexToken(T_SELECT,':',1,10)
LexToken(NAME,'test2',1,12)
LexToken(T_NOT_SELECT,'!:',1,18)
LexToken(NAME,'test1',1,21)
>>> expression = 'D = buff_t(test1,"10 months")'
>>> p.test(expression)
D = buff_t(test1,"10 months")
LexToken(NAME,'D',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(BUFF_T,'buff_t',1,4)
LexToken(LPAREN,'(',1,10)
LexToken(NAME,'test1',1,11)
LexToken(COMMA,',',1,16)
LexToken(QUOTE,'"',1,17)
LexToken(INT,10,1,18)
LexToken(NAME,'months',1,21)
LexToken(QUOTE,'"',1,27)
LexToken(RPAREN,')',1,28)
>>> expression = 'H = tsnap(test1)'
>>> p.test(expression)
H = tsnap(test1)
LexToken(NAME,'H',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(TSNAP,'tsnap',1,4)
LexToken(LPAREN,'(',1,9)
LexToken(NAME,'test1',1,10)
LexToken(RPAREN,')',1,15)
>>> expression = 'H = tsnap(test2 {:,during} buff_t(test1, "1 days"))'
>>> p.test(expression)
H = tsnap(test2 {:,during} buff_t(test1, "1 days"))
LexToken(NAME,'H',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(TSNAP,'tsnap',1,4)
LexToken(LPAREN,'(',1,9)
LexToken(NAME,'test2',1,10)
LexToken(T_SELECT_OPERATOR,'{:,during}',1,16)
LexToken(BUFF_T,'buff_t',1,27)
LexToken(LPAREN,'(',1,33)
LexToken(NAME,'test1',1,34)
LexToken(COMMA,',',1,39)
LexToken(QUOTE,'"',1,41)
LexToken(INT,1,1,42)
LexToken(NAME,'days',1,44)
LexToken(QUOTE,'"',1,48)
LexToken(RPAREN,')',1,49)
LexToken(RPAREN,')',1,50)
>>> expression = 'H = tshift(test2 {:,during} buff_t(test1, "1 days"), "1 months")'
>>> p.test(expression)
H = tshift(test2 {:,during} buff_t(test1, "1 days"), "1 months")
LexToken(NAME,'H',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(TSHIFT,'tshift',1,4)
LexToken(LPAREN,'(',1,10)
LexToken(NAME,'test2',1,11)
LexToken(T_SELECT_OPERATOR,'{:,during}',1,17)
LexToken(BUFF_T,'buff_t',1,28)
LexToken(LPAREN,'(',1,34)
LexToken(NAME,'test1',1,35)
LexToken(COMMA,',',1,40)
LexToken(QUOTE,'"',1,42)
LexToken(INT,1,1,43)
LexToken(NAME,'days',1,45)
LexToken(QUOTE,'"',1,49)
LexToken(RPAREN,')',1,50)
LexToken(COMMA,',',1,51)
LexToken(QUOTE,'"',1,53)
LexToken(INT,1,1,54)
LexToken(NAME,'months',1,56)
LexToken(QUOTE,'"',1,62)
LexToken(RPAREN,')',1,63)
>>> expression = 'H = tshift(A , 10)'
>>> p.test(expression)
H = tshift(A , 10)
LexToken(NAME,'H',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(TSHIFT,'tshift',1,4)
LexToken(LPAREN,'(',1,10)
LexToken(NAME,'A',1,11)
LexToken(COMMA,',',1,13)
LexToken(INT,10,1,15)
LexToken(RPAREN,')',1,17)
>>> expression = 'H = if(td(A) > 10, A)'
>>> p.test(expression)
H = if(td(A) > 10, A)
LexToken(NAME,'H',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(TD,'td',1,7)
LexToken(LPAREN,'(',1,9)
LexToken(NAME,'A',1,10)
LexToken(RPAREN,')',1,11)
LexToken(GREATER,'>',1,13)
LexToken(INT,10,1,15)
LexToken(COMMA,',',1,17)
LexToken(NAME,'A',1,19)
LexToken(RPAREN,')',1,20)
>>> expression = 'H = if(td(A) > 10, A, B)'
>>> p.test(expression)
H = if(td(A) > 10, A, B)
LexToken(NAME,'H',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(TD,'td',1,7)
LexToken(LPAREN,'(',1,9)
LexToken(NAME,'A',1,10)
LexToken(RPAREN,')',1,11)
LexToken(GREATER,'>',1,13)
LexToken(INT,10,1,15)
LexToken(COMMA,',',1,17)
LexToken(NAME,'A',1,19)
LexToken(COMMA,',',1,20)
LexToken(NAME,'B',1,22)
LexToken(RPAREN,')',1,23)
>>> expression = 'I = if(equals,td(A) > 10 {||,equals} td(B) < 10, A)'
>>> p.test(expression)
I = if(equals,td(A) > 10 {||,equals} td(B) < 10, A)
LexToken(NAME,'I',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(NAME,'equals',1,7)
LexToken(COMMA,',',1,13)
LexToken(TD,'td',1,14)
LexToken(LPAREN,'(',1,16)
LexToken(NAME,'A',1,17)
LexToken(RPAREN,')',1,18)
LexToken(GREATER,'>',1,20)
LexToken(INT,10,1,22)
LexToken(T_COMP_OPERATOR,'{||,equals}',1,25)
LexToken(TD,'td',1,37)
LexToken(LPAREN,'(',1,39)
LexToken(NAME,'B',1,40)
LexToken(RPAREN,')',1,41)
LexToken(LOWER,'<',1,43)
LexToken(INT,10,1,45)
LexToken(COMMA,',',1,47)
LexToken(NAME,'A',1,49)
LexToken(RPAREN,')',1,50)
>>> expression = 'I = if(equals,td(A) > 10 || start_day() < 10, A)'
>>> p.test(expression)
I = if(equals,td(A) > 10 || start_day() < 10, A)
LexToken(NAME,'I',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(NAME,'equals',1,7)
LexToken(COMMA,',',1,13)
LexToken(TD,'td',1,14)
LexToken(LPAREN,'(',1,16)
LexToken(NAME,'A',1,17)
LexToken(RPAREN,')',1,18)
LexToken(GREATER,'>',1,20)
LexToken(INT,10,1,22)
LexToken(OR,'|',1,25)
LexToken(OR,'|',1,26)
LexToken(START_DAY,'start_day',1,28)
LexToken(LPAREN,'(',1,37)
LexToken(RPAREN,')',1,38)
LexToken(LOWER,'<',1,40)
LexToken(INT,10,1,42)
LexToken(COMMA,',',1,44)
LexToken(NAME,'A',1,46)
LexToken(RPAREN,')',1,47)
>>> expression = 'E = if({equals},td(A) >= 4 {&&,contain} td(B) == 2, C : D)'
>>> p.test(expression)
E = if({equals},td(A) >= 4 {&&,contain} td(B) == 2, C : D)
LexToken(NAME,'E',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(T_REL_OPERATOR,'{equals}',1,7)
LexToken(COMMA,',',1,15)
LexToken(TD,'td',1,16)
LexToken(LPAREN,'(',1,18)
LexToken(NAME,'A',1,19)
LexToken(RPAREN,')',1,20)
LexToken(GREATER_EQUALS,'>=',1,22)
LexToken(INT,4,1,25)
LexToken(T_COMP_OPERATOR,'{&&,contain}',1,27)
LexToken(TD,'td',1,40)
LexToken(LPAREN,'(',1,42)
LexToken(NAME,'B',1,43)
LexToken(RPAREN,')',1,44)
LexToken(CEQUALS,'==',1,46)
LexToken(INT,2,1,49)
LexToken(COMMA,',',1,50)
LexToken(NAME,'C',1,52)
LexToken(T_SELECT,':',1,54)
LexToken(NAME,'D',1,56)
LexToken(RPAREN,')',1,57)
>>> expression = 'F = if({equals},A {#,equal}, B, C : D)'
>>> p.test(expression)
F = if({equals},A {#,equal}, B, C : D)
LexToken(NAME,'F',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(T_REL_OPERATOR,'{equals}',1,7)
LexToken(COMMA,',',1,15)
LexToken(NAME,'A',1,16)
LexToken(T_HASH_OPERATOR,'{#,equal}',1,18)
LexToken(COMMA,',',1,27)
LexToken(NAME,'B',1,29)
LexToken(COMMA,',',1,30)
LexToken(NAME,'C',1,32)
LexToken(T_SELECT,':',1,34)
LexToken(NAME,'D',1,36)
LexToken(RPAREN,')',1,37)
>>> p = tgis.TemporalAlgebraParser()
>>> p.run = False
>>> p.debug = True
>>> expression = "D = A {!:} B {:,during} C"
>>> print(expression)
D = A {!:} B {:,during} C
>>> p.parse(expression)
A* = A {!:} B
A** = A* {:,during} C
D = A**
>>> expression = "D = A {:} B {!:,during} C"
>>> print(expression)
D = A {:} B {!:,during} C
>>> p.parse(expression)
A* = A {:} B
A** = A* {!:,during} C
D = A**
>>> p.run = False
>>> p.debug = False
>>> expression = "C = test1 : test2"
>>> print(expression)
C = test1 : test2
>>> p.parse(expression, 'stvds')
>>> expression = 'D = buff_t(test1,"10 months")'
>>> print(expression)
D = buff_t(test1,"10 months")
>>> p.parse(expression, 'stvds')
>>> expression = 'E = test2 {:,during} buff_t(test1,"1 days")'
>>> print(expression)
E = test2 {:,during} buff_t(test1,"1 days")
>>> p.parse(expression, 'stvds')
>>> expression = 'F = test2 {:,equal} buff_t(test1,"1 days")'
>>> print(expression)
F = test2 {:,equal} buff_t(test1,"1 days")
>>> p.parse(expression, 'stvds')
>>> p.debug = True
>>> expression = 'H = tsnap(test2 {:,during} buff_t(test1, "1 days"))'
>>> p.parse(expression, 'stvds')
test1* = buff_t( test1 , " 1 days " )
test2* = test2 {:,during} test1*
test2** = tsnap( test2* )
H = test2**
>>> expression = 'H = tshift(test2 {:,during} test1, "1 days")'
>>> p.parse(expression, 'stvds')
test2* = test2 {:,during} test1
test2** = tshift( test2* , " 1 days " )
H = test2**
>>> expression = 'H = tshift(H, 3)'
>>> p.parse(expression, 'stvds')
H* = tshift( H , 3 )
H = H*
>>> expression = 'C = if(td(A) == 2, A)'
>>> p.parse(expression, 'stvds')
td(A)
td(A) == 2
A* = if condition None then A
C = A*
>>> expression = 'C = if(td(A) == 5, A, B)'
>>> p.parse(expression, 'stvds')
td(A)
td(A) == 5
A* = if condition None then A else B
C = A*
>>> expression = 'C = if(td(A) == 5 || start_date(A) > "2010-01-01", A, B)'
>>> p.parse(expression, 'stvds')
td(A)
td(A) == 5
start_date A > "2010-01-01"
None || None
A* = if condition None then A else B
C = A*
>>> p = tgis.TemporalAlgebraLexer()
>>> p.build()
>>> p.debug = True
>>> expression = "D = strds(A) : stvds(B) : str3ds(C)"
>>> p.test(expression)
D = strds(A) : stvds(B) : str3ds(C)
LexToken(NAME,'D',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(STRDS,'strds',1,4)
LexToken(LPAREN,'(',1,9)
LexToken(NAME,'A',1,10)
LexToken(RPAREN,')',1,11)
LexToken(T_SELECT,':',1,13)
LexToken(STVDS,'stvds',1,15)
LexToken(LPAREN,'(',1,20)
LexToken(NAME,'B',1,21)
LexToken(RPAREN,')',1,22)
LexToken(T_SELECT,':',1,24)
LexToken(STR3DS,'str3ds',1,26)
LexToken(LPAREN,'(',1,32)
LexToken(NAME,'C',1,33)
LexToken(RPAREN,')',1,34)
>>> p = tgis.TemporalAlgebraLexer()
>>> p.build()
>>> p.debug = True
>>> expression = "R = if(A {#,during} stvds(C) == 1, A)"
>>> p.test(expression)
R = if(A {#,during} stvds(C) == 1, A)
LexToken(NAME,'R',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(NAME,'A',1,7)
LexToken(T_HASH_OPERATOR,'{#,during}',1,9)
LexToken(STVDS,'stvds',1,20)
LexToken(LPAREN,'(',1,25)
LexToken(NAME,'C',1,26)
LexToken(RPAREN,')',1,27)
LexToken(CEQUALS,'==',1,29)
LexToken(INT,1,1,32)
LexToken(COMMA,',',1,33)
LexToken(NAME,'A',1,35)
LexToken(RPAREN,')',1,36)
>>> p = tgis.TemporalAlgebraLexer()
>>> p.build()
>>> p.debug = True
>>> expression = "R = if({during}, stvds(C) {#,contains} A == 2, A)"
>>> p.test(expression)
R = if({during}, stvds(C) {#,contains} A == 2, A)
LexToken(NAME,'R',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(IF,'if',1,4)
LexToken(LPAREN,'(',1,6)
LexToken(T_REL_OPERATOR,'{during}',1,7)
LexToken(COMMA,',',1,15)
LexToken(STVDS,'stvds',1,17)
LexToken(LPAREN,'(',1,22)
LexToken(NAME,'C',1,23)
LexToken(RPAREN,')',1,24)
LexToken(T_HASH_OPERATOR,'{#,contains}',1,26)
LexToken(NAME,'A',1,39)
LexToken(CEQUALS,'==',1,41)
LexToken(INT,2,1,44)
LexToken(COMMA,',',1,45)
LexToken(NAME,'A',1,47)
LexToken(RPAREN,')',1,48)
Bases: exceptions.Exception
Bases: object
This class handles global temporal variable conditional expressions, like start_doy() == 3. The three parts of the statement are stored separately in tfunc (START_DOY), compop (==) and value (3). But also boolean values, time differences and relation operators for comparison in if-statements can be stored in this class.
Bases: object
Lexical analyzer for the GRASS GIS temporal algebra
“dddd-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[ T](0[0-9]|1(0-9)|2[0-4]):(0[0-9]|[1-5][0-9]|60):(0[0-9]|[1-5][0-9]|60)”
Bases: object
The temporal algebra class
Parameters: |
|
---|---|
Returns: | Map object with conditional value that has been assigned by relation maps that fulfil the topological relationships to maplistB specified in topolist. |
This function evaluates temporal variable expressions of a conditional expression in two steps. At first it combines stepwise the single conditions by their relations with LALR. In this prossess sub condition map lists will be created which will include information of the underlying single conditions. Important: The temporal relations between conditions are evaluated by implicit aggregation. In the second step the aggregated condition map list will be compared with the map list of conclusion statements by the given temporal relation.
The result is writen as ‘condition_value’ attribute to the resulting map objects. These attribute consists of boolean expressions and operators which can be evaluated with the eval_condition_list function. [True, ‘||’, False, ‘&&’, True]
Parameters: |
|
---|---|
Returns: | Map list with conditional values for all temporal expressions. |
Check if input space time dataset exist in database and return its map list.
Parameters: |
|
---|---|
Returns: | List of maps. |
Parameters: |
|
---|---|
Returns: | Map object with conditional value that has been evaluated by comparison operators. |
This function evaluates conditional values of a map list. A recursive function is used to evaluate comparison statements from left to right in the given conditional list.
For example:
- [True, ‘||’, False, ‘&&’, True] -> True
- [True, ‘||’, False, ‘&&’, False] -> False
- [True, ‘&&’, False, ‘&&’, True] -> False
- [False, ‘||’, True, ‘||’, False] -> True
- [False, ‘&&’, True, ‘&&’, True] -> False
- [True, ‘&&’, True, ‘&&’, True] -> True
- [True, ‘&&’, True] -> True
- [True, ‘&&’, False] -> False
- [False, ‘||’, True] -> True
Parameters: | tvarexpr – List of GlobalTemporalVar objects and map lists. The list is constructed by the TemporalAlgebraParser in order of expression evaluation in the parser. |
---|---|
Returns: | Map list with conditional values for all temporal expressions. |
Parameters: |
|
---|---|
Returns: | List of maps from maplist with added conditional boolean values. |
Parameters: |
|
---|---|
Returns: | List of maps from thenlist with added conditional boolean values. |
This function evaluates a string containing temporal operations.
param operator: String of temporal operations, e.g. {!=,equal|during,l}. param optype: String to define operator type.
- :return :List of temporal relations (equal, during), the given function
- (!:) and the interval/instances (l).
>>> import grass.temporal as tgis
>>> tgis.init()
>>> p = tgis.TemporalOperatorParser()
>>> operator = "{+, during}"
>>> p.parse(operator, optype = 'raster')
>>> print(p.relations, p.temporal, p.function)
(['during'], 'l', '+')
Generate an unique map name and register it in the objects map list
The map names are unique between processes. Do not use the same object for map name generation in multiple threads.
Generate a new map using the spatio-temporal extent of the base map
Parameters: |
|
||
---|---|---|---|
Returns: | Map object |
Parameters: | map – Map object with time stamps. |
---|---|
Returns: | Dictionary with temporal functions for given input map. |
>>> import grass.temporal as tgis
>>> import datetime
>>> tgis.init()
>>> l = tgis.TemporalAlgebraParser()
>>> # Example with one list of maps
>>> # Create one list of maps with equal time stamps
>>> for i in range(1):
... idA = "a%i@B"%(i)
... mapA = tgis.RasterDataset(idA)
... mapA.uid = idA
... check = mapA.set_absolute_time(datetime.datetime(2000,1,1),
... datetime.datetime(2000,10,1))
... tfuncdict = l.get_temporal_func_dict(mapA)
>>> print(tfuncdict["START_YEAR"])
2000
>>> print(tfuncdict["START_TIME"])
00:00:00
>>> print(tfuncdict["START_DATE"])
2000-01-01
>>> print(tfuncdict["START_DATETIME"])
2000-01-01 00:00:00
Build temporal topology for two space time data sets, copy map objects for given relation into map list.
Parameters: |
|
---|---|
Returns: | List of maps from maplistA that fulfil the topological relationships to maplistB specified in topolist. |
# Example with two lists of maps
>>> import grass.temporal as tgis
>>> tgis.init(True)
>>> l = tgis.TemporalAlgebraParser()
>>> # Create two list of maps with equal time stamps
>>> mapsA = []
>>> mapsB = []
>>> for i in range(10):
... idA = "a%i@B"%(i)
... mapA = tgis.RasterDataset(idA)
... mapA.uid = idA
... idB = "b%i@B"%(i)
... mapB = tgis.RasterDataset(idB)
... mapB.uid = idB
... check = mapA.set_relative_time(i, i + 1, "months")
... check = mapB.set_relative_time(i, i + 1, "months")
... mapsA.append(mapA)
... mapsB.append(mapB)
>>> resultlist = l.get_temporal_topo_list(mapsA, mapsB, ['EQUAL'])
>>> for map in resultlist:
... if map.get_equal():
... relations = map.get_equal()
... print "Map %s has equal relation to map %s"%(map.get_name(),
... relations[0].get_name())
Map a0 has equal relation to map b0
Map a1 has equal relation to map b1
Map a2 has equal relation to map b2
Map a3 has equal relation to map b3
Map a4 has equal relation to map b4
Map a5 has equal relation to map b5
Map a6 has equal relation to map b6
Map a7 has equal relation to map b7
Map a8 has equal relation to map b8
Map a9 has equal relation to map b9
>>> resultlist = l.get_temporal_topo_list(mapsA, mapsB, ['DURING'])
>>> print(resultlist)
[]
>>> # Create two list of maps with equal time stamps
>>> mapsA = []
>>> mapsB = []
>>> for i in range(10):
... idA = "a%i@B"%(i)
... mapA = tgis.RasterDataset(idA)
... mapA.uid = idA
... idB = "b%i@B"%(i)
... mapB = tgis.RasterDataset(idB)
... mapB.uid = idB
... check = mapA.set_relative_time(i, i + 1, "months")
... check = mapB.set_relative_time(i, i + 2, "months")
... mapsA.append(mapA)
... mapsB.append(mapB)
>>> resultlist = l.get_temporal_topo_list(mapsA, mapsB, ['starts','during'])
>>> for map in resultlist:
... if map.get_starts():
... relations = map.get_starts()
... print "Map %s has start relation to map %s"%(map.get_name(),
... relations[0].get_name())
Map a0 has start relation to map b0
Map a1 has start relation to map b1
Map a2 has start relation to map b2
Map a3 has start relation to map b3
Map a4 has start relation to map b4
Map a5 has start relation to map b5
Map a6 has start relation to map b6
Map a7 has start relation to map b7
Map a8 has start relation to map b8
Map a9 has start relation to map b9
>>> for map in resultlist:
... if map.get_during():
... relations = map.get_during()
... print "Map %s has during relation to map %s"%(map.get_name(),
... relations[0].get_name())
Map a0 has during relation to map b0
Map a1 has during relation to map b0
Map a2 has during relation to map b1
Map a3 has during relation to map b2
Map a4 has during relation to map b3
Map a5 has during relation to map b4
Map a6 has during relation to map b5
Map a7 has during relation to map b6
Map a8 has during relation to map b7
Map a9 has during relation to map b8
>>> # Create two list of maps with equal time stamps and map_value method.
>>> mapsA = []
>>> mapsB = []
>>> for i in range(10):
... idA = "a%i@B"%(i)
... mapA = tgis.RasterDataset(idA)
... mapA.uid = idA
... idB = "b%i@B"%(i)
... mapB = tgis.RasterDataset(idB)
... mapB.uid = idB
... check = mapA.set_relative_time(i, i + 1, "months")
... check = mapB.set_relative_time(i, i + 1, "months")
... mapB.map_value = True
... mapsA.append(mapA)
... mapsB.append(mapB)
>>> # Create two list of maps with equal time stamps
>>> mapsA = []
>>> mapsB = []
>>> for i in range(10):
... idA = "a%i@B"%(i)
... mapA = tgis.RasterDataset(idA)
... mapA.uid = idA
... mapA.map_value = True
... idB = "b%i@B"%(i)
... mapB = tgis.RasterDataset(idB)
... mapB.uid = idB
... mapB.map_value = False
... check = mapA.set_absolute_time(datetime(2000,1,i+1),
... datetime(2000,1,i + 2))
... check = mapB.set_absolute_time(datetime(2000,1,i+6),
... datetime(2000,1,i + 7))
... mapsA.append(mapA)
... mapsB.append(mapB)
>>> resultlist = l.get_temporal_topo_list(mapsA, mapsB)
>>> for map in resultlist:
... print(map.get_id())
a5@B
a6@B
a7@B
a8@B
a9@B
>>> resultlist = l.get_temporal_topo_list(mapsA, mapsB, ['during'])
>>> for map in resultlist:
... print(map.get_id())
Compute the spatio-temporal extent of two topological related maps
Parameters: |
|
---|---|
Returns: | 0 if there is no overlay |
This function performs temporal selection operation.
Parameters: |
|
---|---|
Returns: | List of selected maps from maplistA. |
>>> import grass.temporal as tgis
>>> tgis.init()
>>> l = tgis.TemporalAlgebraParser()
>>> # Example with two lists of maps
>>> # Create two list of maps with equal time stamps
>>> mapsA = []
>>> mapsB = []
>>> for i in range(10):
... idA = "a%i@B"%(i)
... mapA = tgis.RasterDataset(idA)
... mapA.uid = idA
... idB = "b%i@B"%(i)
... mapB = tgis.RasterDataset(idB)
... mapB.uid = idB
... check = mapA.set_relative_time(i, i + 1, "months")
... check = mapB.set_relative_time(i + 5, i + 6, "months")
... mapsA.append(mapA)
... mapsB.append(mapB)
>>> resultlist = l.perform_temporal_selection(mapsA, mapsB, ['EQUAL'],
... False)
>>> for map in resultlist:
... if map.get_equal():
... relations = map.get_equal()
... print "Map %s has equal relation to map %s"%(map.get_name(),
... relations[0].get_name())
Map a5 has equal relation to map b0
Map a6 has equal relation to map b1
Map a7 has equal relation to map b2
Map a8 has equal relation to map b3
Map a9 has equal relation to map b4
>>> resultlist = l.perform_temporal_selection(mapsA, mapsB, ['EQUAL'],
... True)
>>> for map in resultlist:
... if not map.get_equal():
... print "Map %s has no equal relation to mapset mapsB"%(map.get_name())
Map a0 has no equal relation to mapset mapsB
Map a1 has no equal relation to mapset mapsB
Map a2 has no equal relation to mapset mapsB
Map a3 has no equal relation to mapset mapsB
Map a4 has no equal relation to mapset mapsB
Parameters: |
|
---|---|
Returns: | List of maps with the new temporal extends. |
>>> import grass.temporal as tgis
>>> tgis.init()
>>> p = tgis.TemporalAlgebraParser()
>>> # Create two list of maps with equal time stamps
>>> mapsA = []
>>> mapsB = []
>>> for i in range(10):
... idA = "a%i@B"%(i)
... mapA = tgis.RasterDataset(idA)
... mapA.uid = idA
... idB = "b%i@B"%(i)
... mapB = tgis.RasterDataset(idB)
... mapB.uid = idB
... check = mapA.set_relative_time(i, i + 1, "months")
... check = mapB.set_relative_time(i*2, i*2 + 2, "months")
... mapsA.append(mapA)
... mapsB.append(mapB)
>>> resultlist = p.set_granularity(mapsA, mapsB, toperator = "u", topolist = ["during"])
>>> for map in resultlist:
... start,end,unit = map.get_relative_time()
... print(map.get_id() + ' - start: ' + str(start) + ' end: ' + str(end))
a1@B - start: 0 end: 2
a0@B - start: 0 end: 2
a3@B - start: 2 end: 4
a2@B - start: 2 end: 4
a5@B - start: 4 end: 6
a4@B - start: 4 end: 6
a7@B - start: 6 end: 8
a6@B - start: 6 end: 8
a9@B - start: 8 end: 10
a8@B - start: 8 end: 10
Parameters: |
|
---|---|
Returns: | Map list with specified temporal extent. |
Configure the temporal algebra to use the common granularity of all space time datasets in the expression to generate the map lists.
This function will analyze the expression to detect space time datasets and computes the common granularity from all granularities.
This granularity is then be used to generate the map lists. Hence, all maps from all STDS will have equidistant temporal extents. The only meaningful temporal relation is “equal”.
Parameters: |
|
---|---|
Returns: | True if successful, False otherwise |
Temporal extent classes
Usage:
>>> import grass.temporal as tgis
>>> from datetime import datetime
>>> tgis.init()
>>> t = tgis.RasterRelativeTime()
>>> t = tgis.RasterAbsoluteTime()
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: temporal.temporal_extent.TemporalExtent
This is the absolute time class for all maps and spacetime datasets
start_time and end_time must be of type datetime
Bases: temporal.temporal_extent.TemporalExtent
This is the relative time class for all maps and space time datasets
start_time and end_time must be of type integer
Usage:
>>> init()
>>> A = RelativeTemporalExtent(table="raster_relative_time",
... ident="soil@PERMANENT", start_time=0, end_time=1, unit="years")
>>> A.id
'soil@PERMANENT'
>>> A.start_time
0
>>> A.end_time
1
>>> A.unit
'years'
>>> A.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 0
| End time:................... 1
| Relative time unit:......... years
>>> A.print_shell_info()
start_time=0
end_time=1
unit=years
Set the unit of the relative time. Valid units are:
Returns the temporal relation between temporal objects Temporal relationships are implemented after [Allen and Ferguson 1994 Actions and Events in Interval Temporal Logic]
Get the unit of the relative time :return: None if not found
Bases: temporal.temporal_extent.AbsoluteTemporalExtent
This class implements the absolute time extent for space time dataset
In addition to the existing functionality the granularity and the map_time are added.
Usage:
>>> init()
>>> A = STDSAbsoluteTime(table="strds_absolute_time",
... ident="strds@PERMANENT", start_time=datetime(2001, 01, 01),
... end_time=datetime(2005,01,01), granularity="1 days",
... map_time="interval")
>>> A.id
'strds@PERMANENT'
>>> A.start_time
datetime.datetime(2001, 1, 1, 0, 0)
>>> A.end_time
datetime.datetime(2005, 1, 1, 0, 0)
>>> A.granularity
'1 days'
>>> A.map_time
'interval'
>>> A.print_info()
+-------------------- Absolute time -----------------------------------------+
| Start time:................. 2001-01-01 00:00:00
| End time:................... 2005-01-01 00:00:00
| Granularity:................ 1 days
| Temporal type of maps:...... interval
>>> A.print_shell_info()
start_time=2001-01-01 00:00:00
end_time=2005-01-01 00:00:00
granularity=1 days
map_time=interval
Get the type of the map time
Registered maps may have different types of time:
This variable will be set automatically when maps are registered.
Get the granularity of the space time dataset :return: None if not found
Get the type of the map time
Registered maps may have different types of time:
This variable will be set automatically when maps are registered.
Bases: temporal.temporal_extent.RelativeTemporalExtent
This is the relative time class for all maps and space time datasets
start_time and end_time must be of type integer
Usage:
>>> init()
>>> A = STDSRelativeTime(table="strds_relative_time",
... ident="strds@PERMANENT", start_time=0, end_time=1, unit="years",
... granularity=5, map_time="interval")
>>> A.id
'strds@PERMANENT'
>>> A.start_time
0
>>> A.end_time
1
>>> A.unit
'years'
>>> A.granularity
5
>>> A.map_time
'interval'
>>> A.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 0
| End time:................... 1
| Relative time unit:......... years
| Granularity:................ 5
| Temporal type of maps:...... interval
>>> A.print_shell_info()
start_time=0
end_time=1
unit=years
granularity=5
map_time=interval
Get the type of the map time
Registered maps may have different types of time:
This variable will be set automatically when maps are registered.
Get the granularity of the space time dataset :return: None if not found
Get the type of the map time
Registered maps may have different types of time:
This variable will be set automatically when maps are registered.
Bases: temporal.base.SQLDatabaseInterface
This is the abstract time base class for relative and absolute time objects.
It abstract class implements the interface to absolute and relative time. Absolute time is represented by datetime time stamps, relative time is represented by a unit an integer value.
This class implements temporal topology relationships computation after [Allen and Ferguson 1994 Actions and Events in Interval Temporal Logic].
Usage:
>>> init()
>>> A = TemporalExtent(table="raster_absolute_time",
... ident="soil@PERMANENT", start_time=datetime(2001, 01, 01),
... end_time=datetime(2005,01,01) )
>>> A.id
'soil@PERMANENT'
>>> A.start_time
datetime.datetime(2001, 1, 1, 0, 0)
>>> A.end_time
datetime.datetime(2005, 1, 1, 0, 0)
>>> A.print_info()
| Start time:................. 2001-01-01 00:00:00
| End time:................... 2005-01-01 00:00:00
>>> A.print_shell_info()
start_time=2001-01-01 00:00:00
end_time=2005-01-01 00:00:00
>>> # relative time
>>> A = TemporalExtent(table="raster_absolute_time",
... ident="soil@PERMANENT", start_time=0, end_time=1 )
>>> A.id
'soil@PERMANENT'
>>> A.start_time
0
>>> A.end_time
1
>>> A.print_info()
| Start time:................. 0
| End time:................... 1
>>> A.print_shell_info()
start_time=0
end_time=1
Return True if this temporal extent (A) is a meeting neighbor the provided temporal extent (B)
A |---------|
B |---------|
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is a meeting neighbor of this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=7, end_time=9 )
>>> A.adjacent(B)
True
>>> B.adjacent(A)
True
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=3, end_time=5 )
>>> A.adjacent(B)
True
>>> B.adjacent(A)
True
Return True if this temporal extent (A) is located after the provided temporal extent (B)
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is located before this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=8, end_time=9 )
>>> B = TemporalExtent(start_time=6, end_time=7 )
>>> A.after(B)
True
>>> B.after(A)
False
Return True if this temporal extent (A) is located before the provided temporal extent (B)
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is located after this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=6, end_time=7 )
>>> B = TemporalExtent(start_time=8, end_time=9 )
>>> A.before(B)
True
>>> B.before(A)
False
Return True if this temporal extent (A) contains the provided temporal extent (B)
A |---------|
B |-------|
Parameters: | extent – The temporal extent object that is located during this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=4, end_time=9 )
>>> B = TemporalExtent(start_time=5, end_time=8 )
>>> A.contains(B)
True
>>> B.contains(A)
False
Creates a disjoint union with this temporal extent and the provided one. Return a new temporal extent with the new start and end time.
Parameters: | extent – The temporal extent to create a union with |
---|---|
Returns: | The new temporal extent with start and end time |
Usage:
>>> A = TemporalExtent(start_time=5, end_time=6 )
>>> inter = A.intersect(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> A = TemporalExtent(start_time=5, end_time=6 )
>>> B = TemporalExtent(start_time=5, end_time=7 )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 7
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 7
>>> A = TemporalExtent(start_time=3, end_time=6 )
>>> B = TemporalExtent(start_time=5, end_time=7 )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 7
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 7
>>> A = TemporalExtent(start_time=3, end_time=8 )
>>> B = TemporalExtent(start_time=5, end_time=6 )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=6 )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> A = TemporalExtent(start_time=5, end_time=None )
>>> B = TemporalExtent(start_time=3, end_time=6 )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 6
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 6
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=4 )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=None )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> A = TemporalExtent(start_time=5, end_time=None )
>>> B = TemporalExtent(start_time=3, end_time=8 )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 8
>>> A = TemporalExtent(start_time=5, end_time=None )
>>> B = TemporalExtent(start_time=3, end_time=None )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 5
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
| Start time:................. 3
| End time:................... 5
>>> A = RelativeTemporalExtent(start_time=5, end_time=None, unit="years" )
>>> B = RelativeTemporalExtent(start_time=3, end_time=None, unit="years" )
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 3
| End time:................... 5
| Relative time unit:......... years
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
+-------------------- Relative time -----------------------------------------+
| Start time:................. 3
| End time:................... 5
| Relative time unit:......... years
>>> from datetime import datetime as dt
>>> A = AbsoluteTemporalExtent(start_time=dt(2001,1,10), end_time=dt(2003,1,1))
>>> B = AbsoluteTemporalExtent(start_time=dt(2005,1,10), end_time=dt(2008,1,1))
>>> inter = A.disjoint_union(B)
>>> inter.print_info()
+-------------------- Absolute time -----------------------------------------+
| Start time:................. 2001-01-10 00:00:00
| End time:................... 2008-01-01 00:00:00
>>> inter = B.disjoint_union(A)
>>> inter.print_info()
+-------------------- Absolute time -----------------------------------------+
| Start time:................. 2001-01-10 00:00:00
| End time:................... 2008-01-01 00:00:00
Return True if this temporal extent (A) is located during the provided temporal extent (B)
A |-------|
B |---------|
Parameters: | extent – The temporal extent object that contains this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=4, end_time=9 )
>>> A.during(B)
True
>>> B.during(A)
False
Get the valid end time of the extent :return: None if not found
Return True if this temporal extent (A) is equal to the provided temporal extent (B)
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is equal during this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=6 )
>>> B = TemporalExtent(start_time=5, end_time=6 )
>>> A.equal(B)
True
>>> B.equal(A)
True
Return True if this temporal extent (A) starts before the start of the provided temporal extent (B) and finishes with it
A |---------|
B |-----|
Parameters: | extent – The temporal extent object with which this extent finishes |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=6, end_time=7 )
>>> A.finished(B)
True
>>> B.finished(A)
False
Return True if this temporal extent (A) starts after the start of the provided temporal extent (B) and finishes with it
A |-----|
B |---------|
Parameters: | extent – The temporal extent object with which this extent finishes |
---|
Usage:
>>> A = TemporalExtent(start_time=6, end_time=7 )
>>> B = TemporalExtent(start_time=5, end_time=7 )
>>> A.finishes(B)
True
>>> B.finishes(A)
False
Return True if this temporal extent (A) follows the provided temporal extent (B)
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is the predecessor of this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=3, end_time=5 )
>>> A.follows(B)
True
>>> B.follows(A)
False
Convenient method to get the unique identifier (primary key) :return: None if not found
Convenient method to get the unique identifier (primary key) :return: None if not found
Intersect this temporal extent with the provided temporal extent and return a new temporal extent with the new start and end time
Parameters: | extent – The temporal extent to intersect with |
---|---|
Returns: | The new temporal extent with start and end time, or None in case of no intersection |
Usage:
>>> A = TemporalExtent(start_time=5, end_time=6 )
>>> inter = A.intersect(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> A = TemporalExtent(start_time=5, end_time=6 )
>>> B = TemporalExtent(start_time=5, end_time=7 )
>>> inter = A.intersect(B)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> inter = B.intersect(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> A = TemporalExtent(start_time=3, end_time=6 )
>>> B = TemporalExtent(start_time=5, end_time=7 )
>>> inter = A.intersect(B)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> inter = B.intersect(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> A = TemporalExtent(start_time=3, end_time=8 )
>>> B = TemporalExtent(start_time=5, end_time=6 )
>>> inter = A.intersect(B)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> inter = B.intersect(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=6 )
>>> inter = A.intersect(B)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> inter = B.intersect(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... 6
>>> A = TemporalExtent(start_time=5, end_time=None )
>>> B = TemporalExtent(start_time=3, end_time=6 )
>>> inter = A.intersect(B)
>>> inter.print_info()
| Start time:................. 5
| End time:................... None
>>> inter = B.intersect(A)
>>> inter.print_info()
| Start time:................. 5
| End time:................... None
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=4 )
>>> inter = A.intersect(B)
>>> print inter
None
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=None )
>>> inter = A.intersect(B)
>>> print inter
None
Return True if this temporal extent (A) overlapps the provided temporal extent (B)
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is overlapped this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=6, end_time=8 )
>>> B = TemporalExtent(start_time=5, end_time=7 )
>>> A.overlapped(B)
True
>>> B.overlapped(A)
False
>>> A = TemporalExtent(start_time=6, end_time=8 )
>>> B = TemporalExtent(start_time=5, end_time=6 )
>>> A.overlapped(B)
False
>>> B.overlapped(A)
False
Return True if this temporal extent (A) overlapped the provided temporal extent (B)
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is overlaps this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=6, end_time=8 )
>>> A.overlaps(B)
True
>>> B.overlaps(A)
False
>>> A = TemporalExtent(start_time=5, end_time=6 )
>>> B = TemporalExtent(start_time=6, end_time=8 )
>>> A.overlaps(B)
False
>>> B.overlaps(A)
False
Return True if this temporal extent (A) precedes the provided temporal extent (B)
A |---------|
B |---------|
Parameters: | extent – The temporal extent object that is the successor of this extent |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=7, end_time=9 )
>>> A.precedes(B)
True
>>> B.precedes(A)
False
Get the valid start time of the extent :return: None if not found
Return True if this temporal extent (A) started at the start of the provided temporal extent (B) and finishes after it
A |---------|
B |-----|
Parameters: | extent – The temporal extent object with which this extent started |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=7 )
>>> B = TemporalExtent(start_time=5, end_time=6 )
>>> A.started(B)
True
>>> B.started(A)
False
Return True if this temporal extent (A) starts at the start of the provided temporal extent (B) and finishes within it
A |-----|
B |---------|
Parameters: | extent – The temporal extent object with which this extent starts |
---|
Usage:
>>> A = TemporalExtent(start_time=5, end_time=6 )
>>> B = TemporalExtent(start_time=5, end_time=7 )
>>> A.starts(B)
True
>>> B.starts(A)
False
Returns the temporal relation between temporal objects Temporal relationships are implemented after [Allen and Ferguson 1994 Actions and Events in Interval Temporal Logic]
The following temporal relationships are supported:
- equal
- during
- contains
- overlaps
- overlapped
- after
- before
- starts
- finishes
- started
- finished
- follows
- precedes
Parameters: | extent – The temporal extent |
---|---|
Returns: | The name of the temporal relation or None if no relation found |
Creates a union with this temporal extent and the provided one. Return a new temporal extent with the new start and end time.
Parameters: | extent – The temporal extent to create a union with |
---|---|
Returns: | The new temporal extent with start and end time, or None in case the temporal extents are unrelated (before or after) |
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=4 )
>>> inter = A.intersect(B)
>>> print inter
None
>>> A = TemporalExtent(start_time=5, end_time=8 )
>>> B = TemporalExtent(start_time=3, end_time=None )
>>> inter = A.intersect(B)
>>> print inter
None
Functions to compute the temporal granularity of a map list
Usage:
import grass.temporal as tgis
tgis.compute_relative_time_granularity(maps)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Check if the granularity string is valid
Parameters: |
|
---|---|
Returns: | True if valid, False if invalid |
>>> check_granularity_string("1 year", "absolute")
True
>>> check_granularity_string("1 month", "absolute")
True
>>> check_granularity_string("1 day", "absolute")
True
>>> check_granularity_string("1 minute", "absolute")
True
>>> check_granularity_string("1 hour", "absolute")
True
>>> check_granularity_string("1 second", "absolute")
True
>>> check_granularity_string("5 months", "absolute")
True
>>> check_granularity_string("5 days", "absolute")
True
>>> check_granularity_string("5 minutes", "absolute")
True
>>> check_granularity_string("5 years", "absolute")
True
>>> check_granularity_string("5 hours", "absolute")
True
>>> check_granularity_string("2 seconds", "absolute")
True
>>> check_granularity_string("1 secondo", "absolute")
False
>>> check_granularity_string("bla second", "absolute")
False
>>> check_granularity_string("bla", "absolute")
False
>>> check_granularity_string(1, "relative")
True
>>> check_granularity_string("bla", "relative")
False
Compute the absolute time granularity
Attention: The computation of the granularity is only correct in case of not overlapping intervals. Hence a correct temporal topology is required for computation.
The computed granularity is returned as number of seconds or minutes or hours or days or months or years.
Parameters: | maps – a ordered by start_time list of map objects |
---|---|
Returns: | The temporal topology as string “integer unit” |
>>> import grass.temporal as tgis
>>> import datetime
>>> dt = datetime.datetime
>>> tgis.init()
>>> maps = []
>>> count = 0
>>> timelist = ((dt(2000,01,01),None), (dt(2000,02,01),None))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_absolute_time(t[0],t[1])
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_absolute_time_granularity(maps)
'1 month'
>>> maps = []
>>> count = 0
>>> timelist = ((dt(2000,01,01),None), (dt(2000,01,02),None), (dt(2000,01,03),None))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_absolute_time(t[0],t[1])
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_absolute_time_granularity(maps)
'1 day'
>>> maps = []
>>> count = 0
>>> timelist = ((dt(2000,01,01),None), (dt(2000,01,02),None), (dt(2000,05,04,0,5,30),None))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_absolute_time(t[0],t[1])
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_absolute_time_granularity(maps)
'30 seconds'
>>> maps = []
>>> count = 0
>>> timelist = ((dt(2000,01,01),dt(2000,05,02)), (dt(2000,05,04,2),None))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_absolute_time(t[0],t[1])
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_absolute_time_granularity(maps)
'2 hours'
>>> maps = []
>>> count = 0
>>> timelist = ((dt(2000,01,01),dt(2000,02,01)), (dt(2005,05,04,12),dt(2007,05,20,6)))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_absolute_time(t[0],t[1])
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_absolute_time_granularity(maps)
'6 hours'
Compute the greatest common granule from a list of absolute time granules
>>> import grass.temporal as tgis
>>> tgis.init()
>>> grans = ["1 second", "2 seconds", "30 seconds"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'1 seconds'
>>> grans = ["3 second", "6 seconds", "30 seconds"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'3 seconds'
>>> grans = ["12 second", "18 seconds", "30 seconds", "10 minutes"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'6 seconds'
>>> grans = ["20 second", "10 minutes", "2 hours"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'20 seconds'
>>> grans = ["7200 second", "240 minutes", "1 year"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'7200 seconds'
>>> grans = ["7200 second", "89 minutes", "1 year"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'60 seconds'
>>> grans = ["10 minutes", "20 minutes", "30 minutes", "40 minutes", "2 hours"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'10 minutes'
>>> grans = ["120 minutes", "2 hours"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'120 minutes'
>>> grans = ["360 minutes", "3 hours"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'180 minutes'
>>> grans = ["2 hours", "4 hours", "8 hours"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'2 hours'
>>> grans = ["8 hours", "2 days"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'8 hours'
>>> grans = ["48 hours", "1 month"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'24 hours'
>>> grans = ["48 hours", "1 year"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'24 hours'
>>> grans = ["2 months", "4 months", "1 year"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'2 months'
>>> grans = ["120 months", "360 months", "4 years"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'24 months'
>>> grans = ["120 months", "361 months", "4 years"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'1 months'
>>> grans = ["2 years", "3 years", "4 years"]
>>> tgis.compute_common_absolute_time_granularity(grans)
'1 years'
Compute the greatest common granule from a list of relative time granules
>>> import grass.temporal as tgis
>>> tgis.init()
>>> grans = [1,2,30]
>>> tgis.compute_common_relative_time_granularity(grans)
1
>>> import grass.temporal as tgis
>>> tgis.init()
>>> grans = [10,20,30]
>>> tgis.compute_common_relative_time_granularity(grans)
10
Compute the relative time granularity
Attention: The computation of the granularity is only correct in case of not overlapping intervals. Hence a correct temporal topology is required for computation.
Parameters: | maps – a ordered by start_time list of map objects |
---|---|
Returns: | An integer |
>>> import grass.temporal as tgis
>>> tgis.init()
>>> maps = []
>>> for i in range(5):
... map = tgis.RasterDataset("a%i@P"%i)
... check = map.set_relative_time(i,i + 1,"seconds")
... if check:
... maps.append(map)
>>> tgis.compute_relative_time_granularity(maps)
1
>>> maps = []
>>> count = 0
>>> timelist = ((0,3), (3,6), (6,9))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_relative_time(t[0],t[1],"years")
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_relative_time_granularity(maps)
3
>>> maps = []
>>> count = 0
>>> timelist = ((0,3), (4,6), (8,11))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_relative_time(t[0],t[1],"years")
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_relative_time_granularity(maps)
1
>>> maps = []
>>> count = 0
>>> timelist = ((0,8), (2,6), (5,9))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_relative_time(t[0],t[1],"months")
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_relative_time_granularity(maps)
4
>>> maps = []
>>> count = 0
>>> timelist = ((0,8), (8,12), (12,18))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_relative_time(t[0],t[1],"days")
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_relative_time_granularity(maps)
2
>>> maps = []
>>> count = 0
>>> timelist = ((0,None), (8,None), (12,None), (24,None))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_relative_time(t[0],t[1],"minutes")
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_relative_time_granularity(maps)
4
>>> maps = []
>>> count = 0
>>> timelist = ((0,None), (8,14), (18,None), (24,None))
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_relative_time(t[0],t[1],"hours")
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_relative_time_granularity(maps)
2
>>> maps = []
>>> count = 0
>>> timelist = ((0,21),)
>>> for t in timelist:
... map = tgis.RasterDataset("a%i@P"%count)
... check = map.set_relative_time(t[0],t[1],"hours")
... if check:
... maps.append(map)
... count += 1
>>> tgis.compute_relative_time_granularity(maps)
21
@package grass.temporal
Temporal operator evaluation with PLY
(C) 2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Thomas Leppelt and Soeren Gebbert |
---|
>>> p = TemporalOperatorParser()
>>> expression = "{equal| during}"
>>> p.parse(expression, optype = 'relation')
>>> print(p.relations, p.temporal, p.function)
(['equal', 'during'], None, None)
>>> p = TemporalOperatorParser()
>>> expression = "{contains | starts}"
>>> p.parse(expression)
>>> print(p.relations, p.temporal, p.function)
(['contains', 'starts'], None, None)
>>> p = TemporalOperatorParser()
>>> expression = "{&&, during}"
>>> p.parse(expression, optype = 'boolean')
>>> print(p.relations, p.temporal, p.function,p.aggregate)
(['during'], 'l', '&&', '&')
>>> p = TemporalOperatorParser()
>>> expression = "{||, equal | during}"
>>> p.parse(expression, optype = 'boolean')
>>> print(p.relations, p.temporal, p.function,p.aggregate)
(['equal', 'during'], 'l', '||', '|')
>>> p = TemporalOperatorParser()
>>> expression = "{||, equal | during, &}"
>>> p.parse(expression, optype = 'boolean')
>>> print(p.relations, p.temporal, p.function,p.aggregate)
(['equal', 'during'], 'l', '||', '&')
>>> p = TemporalOperatorParser()
>>> expression = "{&&, during, |}"
>>> p.parse(expression, optype = 'boolean')
>>> print(p.relations, p.temporal, p.function,p.aggregate)
(['during'], 'l', '&&', '|')
>>> p = TemporalOperatorParser()
>>> expression = "{&&, during, |, r}"
>>> p.parse(expression, optype = 'boolean')
>>> print(p.relations, p.temporal, p.function,p.aggregate)
(['during'], 'r', '&&', '|')
>>> p = TemporalOperatorParser()
>>> expression = "{&&, during, u}"
>>> p.parse(expression, optype = 'boolean')
>>> print(p.relations, p.temporal, p.function,p.aggregate)
(['during'], 'u', '&&', '&')
>>> p = TemporalOperatorParser()
>>> expression = "{:, during, r}"
>>> p.parse(expression, optype = 'select')
>>> print(p.relations, p.temporal, p.function)
(['during'], 'r', ':')
>>> p = TemporalOperatorParser()
>>> expression = "{!:, equal | contains, d}"
>>> p.parse(expression, optype = 'select')
>>> print(p.relations, p.temporal, p.function)
(['equal', 'contains'], 'd', '!:')
>>> p = TemporalOperatorParser()
>>> expression = "{#, during, r}"
>>> p.parse(expression, optype = 'hash')
>>> print(p.relations, p.temporal, p.function)
(['during'], 'r', '#')
>>> p = TemporalOperatorParser()
>>> expression = "{#, equal | contains}"
>>> p.parse(expression, optype = 'hash')
>>> print(p.relations, p.temporal, p.function)
(['equal', 'contains'], 'l', '#')
>>> p = TemporalOperatorParser()
>>> expression = "{+, during, r}"
>>> p.parse(expression, optype = 'raster')
>>> print(p.relations, p.temporal, p.function)
(['during'], 'r', '+')
>>> p = TemporalOperatorParser()
>>> expression = "{/, equal | contains}"
>>> p.parse(expression, optype = 'raster')
>>> print(p.relations, p.temporal, p.function)
(['equal', 'contains'], 'l', '/')
>>> p = TemporalOperatorParser()
>>> expression = "{+, equal | contains,intersect}"
>>> p.parse(expression, optype = 'raster')
>>> print(p.relations, p.temporal, p.function)
(['equal', 'contains'], 'i', '+')
>>> p = TemporalOperatorParser()
>>> expression = "{*, contains,disjoint}"
>>> p.parse(expression, optype = 'raster')
>>> print(p.relations, p.temporal, p.function)
(['contains'], 'd', '*')
>>> p = TemporalOperatorParser()
>>> expression = "{~, equal,left}"
>>> p.parse(expression, optype = 'overlay')
>>> print(p.relations, p.temporal, p.function)
(['equal'], 'l', '~')
>>> p = TemporalOperatorParser()
>>> expression = "{^, over,right}"
>>> p.parse(expression, optype = 'overlay')
>>> print(p.relations, p.temporal, p.function)
(['overlaps', 'overlapped'], 'r', '^')
Bases: object
Lexical analyzer for the GRASS GIS temporal operator
Bases: object
The temporal operator class
!@package grass.temporal
Temporal raster algebra
(C) 2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Thomas Leppelt and Soeren Gebbert |
---|
Bases: temporal.temporal_raster_base_algebra.TemporalRasterBaseAlgebraParser
The temporal raster algebra class
!@package grass.temporal
Temporal raster algebra
(C) 2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Thomas Leppelt and Soeren Gebbert |
---|
>>> p = TemporalRasterAlgebraLexer()
>>> p.build()
>>> p.debug = True
>>> expression = 'R = A[0,1,0] / B[0,0,1] * 20 + C[0,1,1] - 2.45'
>>> p.test(expression)
R = A[0,1,0] / B[0,0,1] * 20 + C[0,1,1] - 2.45
LexToken(NAME,'R',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'A',1,4)
LexToken(L_SPAREN,'[',1,5)
LexToken(INT,0,1,6)
LexToken(COMMA,',',1,7)
LexToken(INT,1,1,8)
LexToken(COMMA,',',1,9)
LexToken(INT,0,1,10)
LexToken(R_SPAREN,']',1,11)
LexToken(DIV,'/',1,13)
LexToken(NAME,'B',1,15)
LexToken(L_SPAREN,'[',1,16)
LexToken(INT,0,1,17)
LexToken(COMMA,',',1,18)
LexToken(INT,0,1,19)
LexToken(COMMA,',',1,20)
LexToken(INT,1,1,21)
LexToken(R_SPAREN,']',1,22)
LexToken(MULT,'*',1,24)
LexToken(INT,20,1,26)
LexToken(ADD,'+',1,29)
LexToken(NAME,'C',1,31)
LexToken(L_SPAREN,'[',1,32)
LexToken(INT,0,1,33)
LexToken(COMMA,',',1,34)
LexToken(INT,1,1,35)
LexToken(COMMA,',',1,36)
LexToken(INT,1,1,37)
LexToken(R_SPAREN,']',1,38)
LexToken(SUB,'-',1,40)
LexToken(FLOAT,2.45,1,42)
Bases: temporal.temporal_raster_base_algebra.TemporalRasterBaseAlgebraParser
The temporal raster algebra class
@package grass.temporal
Temporal raster algebra
(C) 2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Thomas Leppelt and Soeren Gebbert |
---|
>>> p = TemporalRasterAlgebraLexer()
>>> p.build()
>>> p.debug = True
>>> expression = 'R = A {+,equal,l} B '
>>> p.test(expression)
R = A {+,equal,l} B
LexToken(NAME,'R',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'A',1,4)
LexToken(T_ARITH2_OPERATOR,'{+,equal,l}',1,6)
LexToken(NAME,'B',1,18)
>>> expression = 'R = A {*,equal|during,r} B '
>>> p.test(expression)
R = A {*,equal|during,r} B
LexToken(NAME,'R',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'A',1,4)
LexToken(T_ARITH1_OPERATOR,'{*,equal|during,r}',1,6)
LexToken(NAME,'B',1,25)
>>> expression = 'R = A {+,equal|during} B '
>>> p.test(expression)
R = A {+,equal|during} B
LexToken(NAME,'R',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'A',1,4)
LexToken(T_ARITH2_OPERATOR,'{+,equal|during}',1,6)
LexToken(NAME,'B',1,23)
Bases: temporal.temporal_algebra.TemporalAlgebraLexer
Lexical analyzer for the GRASS GIS temporal algebra
Bases: temporal.temporal_algebra.TemporalAlgebraParser
The temporal algebra class
This function build the r.mapcalc command string for conditionals, spatial variable combinations and boolean comparisons.
For Example: ‘if(a1 == 1, b1, c2)’ or ‘exist(a1) && sin(b1)’
Parameters: |
|
---|---|
Returns: | the resulting command string for conditionals or spatial variable combinations |
This function build the r.mapcalc command strings for spatial conditionals. For Example: ‘if(a1 == 1, b1, c2)’
Parameters: |
|
---|---|
Returns: | map list with resulting command string for given condition type. |
Function to evaluate two map lists with boolean values by boolean comparison operator. Extended temporal algebra version with command list builder for temporal raster algebra.
Parameters: |
|
---|---|
Returns: | Map object with conditional value that has been evaluated by comparison operators. |
Build temporal topology for two space time data sets, copy map objects for given relation into map list.
Parameters: |
|
---|---|
Returns: | List of maps from maplistA that fulfil the topological relationships to maplistB specified in topolist. |
Function to evaluate two map lists by given arithmetic operator.
Parameters: |
|
---|---|
Returns: | Map object with command list with operators that has been evaluated by implicit aggregration. |
Parameters: |
|
---|---|
Returns: | Map list with specified temporal extent and optional command string. |
Temporal topology dataset connector class
Usage:
>>> import grass.temporal as tgis
>>> tmr = tgis.TemporalTopologyDatasetConnector()
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Bases: object
This class implements a temporal topology access structure to connect temporal related datasets
This object will be set up by temporal topology creation method provided by the SpatioTemporalTopologyBuilder.
If correctly initialize the calls next() and prev() let the user walk temporally forward and backward in time.
The following temporal relations with access methods are supported:
# We have build the temporal topology and we know the first map
start = first
while start:
# Print all maps this map temporally contains
dlist = start.get_contains()
for map in dlist:
map.print_info()
start = start.next()
>>> import grass.temporal as tgis
>>> tgis.init()
>>> map = tgis.RasterDataset("a@P")
>>> tmr = tgis.TemporalTopologyDatasetConnector()
>>> tmr.set_next(map)
>>> tmr.set_prev(map)
>>> tmr.append_equal(map)
>>> tmr.append_follows(map)
>>> tmr.append_precedes(map)
>>> tmr.append_overlapped(map)
>>> tmr.append_overlaps(map)
>>> tmr.append_during(map)
>>> tmr.append_contains(map)
>>> tmr.append_starts(map)
>>> tmr.append_started(map)
>>> tmr.append_finishes(map)
>>> tmr.append_finished(map)
>>> tmr.print_temporal_topology_info()
+-------------------- Temporal Topology -------------------------------------+
| Next: ...................... a@P
| Previous: .................. a@P
| Equal:...................... a@P
| Follows: ................... a@P
| Precedes: .................. a@P
| Overlaps: .................. a@P
| Overlapped: ................ a@P
| During: .................... a@P
| Contains: .................. a@P
| Starts:.. .................. a@P
| Started:. .................. a@P
| Finishes:................... a@P
| Finished:................... a@P
>>> tmr.print_temporal_topology_shell_info()
next=a@P
prev=a@P
equal=a@P
follows=a@P
precedes=a@P
overlaps=a@P
overlapped=a@P
during=a@P
contains=a@P
starts=a@P
started=a@P
finishes=a@P
finished=a@P
>>> rlist = tmr.get_temporal_relations()
>>> if "FINISHED" in rlist.keys():
... print rlist["FINISHED"][0].get_id()
a@P
Append a map that this map temporally contains This includes temporal relationships started and finished
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map is temporally located during This includes temporal relationships starts and finishes
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map with equivalent temporal extent as this map
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally finished with
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally finishes with
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally follows
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally overlapped
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally overlaps
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally precedes
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally started with
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Append a map that this map temporally starts with
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Return a list of map objects that this map temporally contains This includes temporal relationships started and finished
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map is temporally located during This includes temporally relationships starts and finishes
Returns: | A list of map objects or None |
---|
Return a list of map objects with equivalent temporal extent as this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally finished with
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally finishes with
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally follows
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally contains This includes temporal relationships started and finished
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map is temporally located during This includes temporally relationships starts and finishes
Returns: | A list of map objects or None |
---|
Return a list of map objects with equivalent temporal extent as this map
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally finished with
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally finishes with
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally follows
Returns: | A list of map objects or None |
---|
Return a dictionary in which the keys are the relation names and the value are the number of relations.
The following relations are available:
To access topological information the temporal topology must be build first using the SpatioTemporalTopologyBuilder.
Returns: | the dictionary with relations as keys and number as values or None in case the topology wasn’t build |
---|
Return a list of map objects that this map temporally overlapped
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally overlaps
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally precedes
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally started with
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally starts with
Returns: | A list of map objects or None |
---|
Return the dictionary of temporal relationships
Keys are the temporal relationships in upper case, values are abstract map objects.
Returns: | The temporal relations dictionary |
---|
Return the map with a start time temporally located after the start time of this map, but temporal closer than other maps
Returns: | A map object or None |
---|
Return a list of map objects that this map temporally overlapped
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally overlaps
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally precedes
Returns: | A list of map objects or None |
---|
Return the map with a start time temporally located before the start time of this map, but temporal closer than other maps
Returns: | A map object or None |
---|
Set the map that is temporally as closest located after this map.
Temporally located means that the start time of the “next” map is temporally located AFTER the start time of this map, but temporally near than other maps of the same dataset.
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Set the map that is temporally as closest located before this map.
Temporally located means that the start time of the “previous” map is temporally located BEFORE the start time of this map, but temporally near than other maps of the same dataset.
Parameters: | map – This object should be of type AbstractMapDataset or derived classes |
---|
Return a list of map objects that this map temporally started with
Returns: | A list of map objects or None |
---|
Return a list of map objects that this map temporally starts with
Returns: | A list of map objects or None |
---|
@package grass.temporal
Temporal vector algebra
(C) 2014 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Thomas Leppelt and Soeren Gebbert |
---|
>>> import grass.temporal as tgis
>>> tgis.init(True)
>>> p = tgis.TemporalVectorAlgebraLexer()
>>> p.build()
>>> p.debug = True
>>> expression = 'E = A : B ^ C : D'
>>> p.test(expression)
E = A : B ^ C : D
LexToken(NAME,'E',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(NAME,'A',1,4)
LexToken(T_SELECT,':',1,6)
LexToken(NAME,'B',1,8)
LexToken(XOR,'^',1,10)
LexToken(NAME,'C',1,12)
LexToken(T_SELECT,':',1,14)
LexToken(NAME,'D',1,16)
>>> expression = 'E = buff_a(A, 10)'
>>> p.test(expression)
E = buff_a(A, 10)
LexToken(NAME,'E',1,0)
LexToken(EQUALS,'=',1,2)
LexToken(BUFF_AREA,'buff_a',1,4)
LexToken(LPAREN,'(',1,10)
LexToken(NAME,'A',1,11)
LexToken(COMMA,',',1,12)
LexToken(INT,10,1,14)
LexToken(RPAREN,')',1,16)
Bases: temporal.temporal_algebra.TemporalAlgebraLexer
Lexical analyzer for the GRASS GIS temporal vector algebra
Bases: temporal.temporal_algebra.TemporalAlgebraParser
The temporal algebra class
Build temporal topology for two space time data sets, copy map objects for given relation into map list.
Parameters: |
|
---|---|
Returns: | List of maps from maplistA that fulfil the topological relationships to maplistB specified in topolist. |
Function to evaluate two map lists by given overlay operator.
Parameters: |
|
---|---|
Returns: | Map object with command list with operators that has been evaluated by implicit aggregration. |
Parameters: |
|
---|---|
Returns: | Map list with specified temporal extent. |
Depricazed unittests
(C) 2008-2011 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Univariate statistic function for space time datasets
Usage:
import grass.temporal as tgis
tgis.print_gridded_dataset_univar_statistics(type, input, output, where, extended, no_header, fs, rast_region)
(C) 2012-2013 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
authors: | Soeren Gebbert |
---|
Print univariate statistics for a space time raster or raster3d dataset
Parameters: |
|
---|
Print univariate statistics for a space time vector dataset
Parameters: |
|
---|
Note: A new GRASS GIS stable version has been released: GRASS GIS 7.4. Go directly to the new manual page here
Help Index | Topics Index | Keywords Index | Full Index
© 2003-2018 GRASS Development Team, GRASS GIS 7.0.7svn Reference Manual