grass.temporal package

Submodules

grass.temporal.abstract_dataset module

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

class grass.temporal.abstract_dataset.AbstractDataset[source]

Bases: grass.temporal.spatial_topology_dataset_connector.SpatialTopologyDatasetConnector, grass.temporal.temporal_topology_dataset_connector.TemporalTopologyDatasetConnector

This is the base class for all datasets (raster, vector, raster3d, strds, stvds, str3ds)

check_relative_time_unit(unit)[source]

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

abstract delete()[source]

Delete dataset from database if it exists

get_absolute_time()[source]

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)

get_id()[source]

Return the unique identifier of the dataset :return: The id of the dataset “name(:layer)@mapset” as string

get_mapset()[source]

Return the mapset :return: The mapset in which the dataset was created as string

get_name()[source]

Return the name :return: The name of the dataset as string

abstract get_new_instance(ident)[source]

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

get_number_of_relations()[source]

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

get_relative_time()[source]

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)

get_relative_time_unit()[source]

Returns the relative time unit :return: The relative time unit as string, None if not present

get_spatial_extent()[source]

Return the spatial extent

get_spatial_extent_as_tuple()[source]

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)

get_temporal_extent()[source]

Return the temporal extent of the correct internal type

get_temporal_extent_as_tuple()[source]

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)

get_temporal_type()[source]

Return the temporal type of this dataset

The temporal type can be absolute or relative

Returns

The temporal type of the dataset as string

abstract get_type()[source]

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(dbif=None, execute=True)[source]

Insert dataset into database

Parameters
  • dbif – The database interface to be used

  • execute – If True the SQL statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL insert statement in case execute=False, or an empty string otherwise

is_in_db(dbif=None, mapset=None)[source]

Check if the dataset is registered in the database

Parameters
  • dbif – The database interface to be used

  • mapset – The dbif connection to be used

Returns

True if the dataset is registered in the database

abstract is_stds()[source]

Return True if this class is a space time dataset

Returns

True if this class is a space time dataset, False otherwise

is_time_absolute()[source]

Return True in case the temporal type is absolute

Returns

True if temporal type is absolute, False otherwise

is_time_relative()[source]

Return True in case the temporal type is relative

Returns

True if temporal type is relative, False otherwise

is_topology_build()[source]

Check if the spatial and temporal topology was build

Returns

A dictionary with “spatial” and “temporal” as keys that have boolean values

abstract print_info()[source]

Print information about this class in human readable style

abstract print_self()[source]

Print the content of the internal structure to stdout

abstract print_shell_info()[source]

Print information about this class in shell style

print_topology_info()[source]
print_topology_shell_info()[source]
abstract reset(ident)[source]

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”

reset_topology()[source]

Reset any information about temporal topology

select(dbif=None, mapset=None)[source]

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

  • mapset – The dbif connection to be used

set_id(ident)[source]

Set the identifier of the dataset

set_topology_build_false()[source]

Use this method when the spatio-temporal topology was not build

set_topology_build_true()[source]

Use this method when the spatio-temporal topology was build

abstract spatial_disjoint_union(dataset)[source]

Return the spatial union as spatial_extent object.

Parameters

dataset – The abstract dataset to create a union with

Returns

The union spatial extent

abstract spatial_intersection(dataset)[source]

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

abstract spatial_overlapping(dataset)[source]

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

abstract spatial_relation(dataset)[source]

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

abstract spatial_union(dataset)[source]

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

temporal_disjoint_union(dataset)[source]

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

property temporal_extent

Return the temporal extent of the correct internal type

temporal_intersection(dataset)[source]

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

temporal_relation(dataset)[source]

Return the temporal relation of self and the provided dataset

Returns

The temporal relation as string

temporal_union(dataset)[source]

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(dbif=None, execute=True, ident=None)[source]

Update the dataset entry in the database from the internal structure excluding None variables

Parameters
  • dbif – The database interface to be used

  • execute – If True the SQL statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

  • ident – The identifier to be updated, useful for renaming

Returns

The SQL update statement in case execute=False, or an empty string otherwise

update_all(dbif=None, execute=True, ident=None)[source]

Update the dataset entry in the database from the internal structure and include None variables.

Parameters
  • dbif – The database interface to be used

  • execute – If True the SQL statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

  • ident – The identifier to be updated, useful for renaming

Returns

The SQL update statement in case execute=False, or an empty string otherwise

class grass.temporal.abstract_dataset.AbstractDatasetComparisonKeyEndTime(obj, *args)[source]

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)
class grass.temporal.abstract_dataset.AbstractDatasetComparisonKeyStartTime(obj, *args)[source]

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)

grass.temporal.abstract_map_dataset module

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

class grass.temporal.abstract_map_dataset.AbstractMapDataset[source]

Bases: grass.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:

  • insert() to register the map and therefore its spatio-temporal extent and metadata in the temporal database

  • update() to update the map spatio-temporal extent and metadata in the temporal database

  • unregister() to unregister the map from each space time dataset in which this map is registered

  • delete() to remove the map from the temporal database

  • Methods to set relative and absolute time stamps

  • Abstract methods that must be implemented in the map specific subclasses

add_stds_to_register(stds_id, dbif=None, execute=True)[source]

Add a new space time dataset to the register

Parameters
  • stds_id – The id of the space time dataset to be registered

  • dbif – The database interface to be used

  • execute – If True the SQL INSERT table statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL statements if execute=False, else an empty string

static build_id(name, mapset, layer=None)[source]

Convenient method to build the unique identifier

Existing layer and mapset definitions in the name string will be reused

Parameters
  • name – The name of the map

  • mapset – The mapset in which the map is located

  • layer – The layer of the vector map, use None in case no layer exists

Returns

the id of the map as “name(:layer)@mapset” where layer is optional

static build_id_from_search_path(name, element)[source]

Convenient method to build the unique identifier while checking the current seach path for the correct mapset.

Existing mapset definitions in the name string will be reused.

If an element type is given and the mapset is not specified in the name, the function will try to get the correct mapset by searching for a map with the given name and of the given element type on the current search path. If the combination is not found on the current search path, it will fail and throw an error.

Parameters
  • name – The name of the map

  • element – A mapset element type to be passed to g.findfile, e.g. “cell”, “vector”, “raster3d”

Returns

the id of the map as “name(:layer)@mapset” where layer is optional

check_for_correct_time()[source]

Check for correct time

Returns

True in case of success, False otherwise

check_resolution_with_current_region()[source]

Check if the raster or voxel resolution is finer than the current resolution

  • Return “finer” in case the raster/voxel resolution is finer than the current region

  • Return “coarser” in case the raster/voxel resolution is coarser than the current region

Vector maps have no resolution, since they store the coordinates directly.

Returns

“finer” or “coarser”

delete(dbif=None, update=True, execute=True)[source]

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
  • dbif – The database interface to be used

  • update – Call for each unregister statement the update from registered maps of the space time dataset. This can slow down the un-registration process significantly.

  • execute – If True the SQL DELETE and DROP table statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL statements if execute=False, else an empty string, None in case of a failure

get_layer()[source]

Return the layer of the map

Returns

the layer of the map or None in case no layer is defined

get_map_id()[source]

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

abstract get_new_stds_instance(ident)[source]

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

get_registered_stds(dbif=None, mapset=None)[source]

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

abstract has_grass_timestamp()[source]

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(dbif=None, execute=True)[source]

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
  • dbif – The database interface to be used

  • execute – If True the SQL statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL insert statement in case execute=False, or an empty string otherwise

abstract load()[source]

Load the content of this object from the grass file system based database

abstract map_exists()[source]

Return True in case the map exists in the grass spatial database

Returns

True if map exists, False otherwise

print_info()[source]

Print information about this object in human readable style

print_self()[source]

Print the content of the internal structure to stdout

print_shell_info()[source]

Print information about this object in shell style

read_semantic_label_from_grass()[source]

Read the band identifier of this map from the map metadata in the GRASS file system based spatial database and set the internal band identifier that should be insert/updated in the temporal database.

Currently only implemented in RasterDataset. Otherwise silently pass.

abstract read_timestamp_from_grass()[source]

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_stds_from_register(stds_id, dbif=None, execute=True)[source]

Remove a space time dataset from the register

Parameters
  • stds_id – The id of the space time dataset to removed from the registered

  • dbif – The database interface to be used

  • execute – If True the SQL INSERT table statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL statements if execute=False, else an empty string

abstract remove_timestamp_from_grass()[source]

Remove the timestamp from the grass file system based spatial database

set_absolute_time(start_time, end_time=None)[source]

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
  • start_time – A datetime object specifying the start time of the map

  • end_time – A datetime object specifying the end time of the map, None in case or time instance

Returns

True for success and False otherwise

set_relative_time(start_time, end_time, unit)[source]

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
  • start_time – An integer value

  • end_time – An integer value, None in case or time instance

  • unit – The unit of the relative time. Supported units: year(s), month(s), day(s), hour(s), minute(s), second(s)

Returns

True for success and False otherwise

set_semantic_label(semantic_label)[source]

Set semantic label identifier

Currently only implemented in RasterDataset. Otherwise report a warning.

set_spatial_extent(spatial_extent)[source]

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_spatial_extent_from_values(north, south, east, west, top=0, bottom=0)[source]

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
  • north – The northern edge

  • south – The southern edge

  • east – The eastern edge

  • west – The western edge

  • top – The top edge

  • bottom – The bottom edge

set_temporal_extent(extent)[source]

Convenient method to set the temporal extent from a temporal extent object

Parameters

extent – The temporal extent that should be set for this object

set_time_to_absolute()[source]

Set the temporal type to absolute

set_time_to_relative()[source]

Set the temporal type to relative

spatial_buffer(size, update=False, dbif=None)[source]

Buffer the spatial extent by a given size in all spatial directions.

Parameters
  • size – The buffer size, using the unit of the grass region

  • update – If True perform an immediate database update, otherwise only the internal variables are set

  • dbif – The database interface to be used

spatial_buffer_2d(size, update=False, dbif=None)[source]

Buffer the spatial extent by a given size in 2d spatial directions.

Parameters
  • size – The buffer size, using the unit of the grass region

  • update – If True perform an immediate database update, otherwise only the internal variables are set

  • dbif – The database interface to be used

static split_name(name, layer=None, mapset=None)[source]

Convenient method to split a map name into three potentially contained parts: map name, map layer and mapset. For the layer and mapset, default keyword arguments can be given if not present in the name. Layer and mapset present in the name will overwrite the keyword arguments.

Parameters
  • name – The name of the map

  • layer – The layer of the vector map, use None in case no layer exists

  • mapset – The mapset in which the map is located

Returns

tuple of three elements name, layer, mapset e(:layer)@mapset” while layer is optional

temporal_buffer(increment, update=False, dbif=None)[source]

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
  • increment – This is the increment, a string in case of absolute time or an integer in case of relative time

  • update – Perform an immediate database update to store the modified temporal extent, otherwise only this object will be modified

Usage:

unregister(dbif=None, update=True, execute=True)[source]

Remove the map entry in each space time dataset in which this map is registered

Parameters
  • dbif – The database interface to be used

  • update – Call for each unregister statement the update from registered maps of the space time dataset. This can slow down the un-registration process significantly.

  • execute – If True the SQL DELETE and DROP table statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL statements if execute=False, else an empty string

update(dbif=None, execute=True)[source]

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
  • dbif – The database interface to be used

  • execute – If True the SQL statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL insert statement in case execute=False, or an empty string otherwise

update_absolute_time(start_time, end_time=None, dbif=None)[source]

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
  • start_time – A datetime object specifying the start time of the map

  • end_time – A datetime object specifying the end time of the map, None in case or time instance

  • dbif – The database interface to be used

update_all(dbif=None, execute=True)[source]

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
  • dbif – The database interface to be used

  • execute – If True the SQL statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL insert statement in case execute=False, or an empty string otherwise

update_relative_time(start_time, end_time, unit, dbif=None)[source]

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
  • start_time – An integer value

  • end_time – An integer value, None in case or time instance

  • unit – The relative time unit

  • dbif – The database interface to be used

abstract write_timestamp_to_grass()[source]

Write the timestamp of this map into the map metadata in the grass file system based spatial database.

grass.temporal.abstract_space_time_dataset module

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

class grass.temporal.abstract_space_time_dataset.AbstractSpaceTimeDataset(ident)[source]

Bases: grass.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_temporal_topology(maps=None, dbif=None)[source]

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:

  • after -> allowed

  • precedes -> allowed

  • follows -> allowed

  • precedes -> allowed

  • equal -> not allowed

  • during -> not allowed

  • contains -> not allowed

  • overlaps -> not allowed

  • overlapped -> not allowed

  • starts -> not allowed

  • finishes -> not allowed

  • started -> not allowed

  • finished -> not allowed

Parameters
  • maps – An optional list of AbstractDataset objects, in case of None all maps of the space time dataset are checked

  • dbif – The database interface to be used

Returns

True if topology is correct

count_gaps(maps=None, dbif=None)[source]

Count the number of gaps between temporal neighbors

Parameters
  • maps – A sorted (start_time) list of AbstractDataset objects

  • dbif – The database interface to be used

Returns

The numbers of gaps between temporal neighbors

count_temporal_relations(maps=None, dbif=None)[source]

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
  • maps – A sorted (start_time) list of AbstractDataset objects

  • dbif – The database interface to be used

Returns

A dictionary with counted temporal relationships

count_temporal_types(maps=None, dbif=None)[source]

Return the temporal type of the registered maps as dictionary

The map list must be ordered by start time

The temporal type can be:

  • point -> only the start time is present

  • interval -> start and end time

  • invalid -> No valid time point or interval found

Parameters
  • maps – A sorted (start_time) list of AbstractDataset objects

  • dbif – The database interface to be used

create_command_string()[source]

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_map_register_name()[source]

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(dbif=None, execute=True)[source]

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
  • dbif – The database interface to be used

  • execute – If True the SQL DELETE and DROP table statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL statements if execute == False, else an empty string

get_granularity()[source]

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, minutes, seconds). In case of relative time an integer value is expected.

Returns

The granularity

get_initial_values()[source]

Return the initial values: temporal_type, semantic_type, title, description

abstract get_map_register()[source]

Return the name of the map register table :return: The map register table name

get_map_time()[source]

Return the type of the map time, interval, point, mixed or invalid

get_name(semantic_label=True)[source]

Get dataset name including semantic label filter if enabled.

Parameters

semantic_label (bool) – True to return dataset name

including semantic label filter if defined (eg. “landsat.L8_1”) otherwise dataset name is returned only (eg. “landsat”).

Return str

dataset name

abstract get_new_map_instance(ident=None)[source]

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

get_registered_maps(columns=None, where=None, order=None, dbif=None, spatial_extent=None, spatial_relation=None)[source]

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
  • columns – Columns to be selected as SQL compliant string

  • where – The SQL where statement to select a subset of the registered maps without “WHERE”

  • order – The SQL order statement to be used to order the objects in the list without “ORDER BY”

  • dbif – The database interface to be used

  • spatial_extent – Return only maps with the provided spatial relation to the given spatial extent (requires spatial_relation parameter)

  • spatial_relation – Return only maps with the given spatial relation to the provided spatial extent (requires spatial_extent parameter)

Returns

SQL rows of all registered maps, In case nothing found None is returned

get_registered_maps_as_objects(where=None, order='start_time', dbif=None, spatial_extent=None, spatial_relation=None)[source]

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
  • where – The SQL where statement to select a subset of the registered maps without “WHERE”

  • order – The SQL order statement to be used to order the objects in the list without “ORDER BY”

  • dbif – The database interface to be used

  • spatial_extent – Return only maps with the provided spatial relation to the given spatial extent (requires spatial_relation parameter)

  • spatial_relation – Return only maps with the given spatial relation to the provided spatial extent (requires spatial_extent parameter)

Returns

The ordered map object list, In case nothing found None is returned

get_registered_maps_as_objects_by_granularity(gran=None, dbif=None)[source]

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
  • gran – The granularity string to be used, if None the granularity of the space time dataset is used. Absolute time has the format “number unit”, relative time has the format “number”. The unit in case of absolute time can be one of “second, seconds, minute, minutes, hour, hours, day, days, week, weeks, month, months, year, years”. The unit of the relative time granule is always the space time dataset unit and can not be changed.

  • dbif – The database interface to be used

Returns

ordered list of map lists. Each list represents a single granule, or None in case nothing found

get_registered_maps_as_objects_with_gaps(where=None, dbif=None, spatial_extent=None, spatial_relation=None)[source]

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
  • where – The SQL where statement to select a subset of the registered maps without “WHERE”

  • dbif – The database interface to be used

  • spatial_extent – Return only maps with the provided spatial relation to the given spatial extent (requires spatial_relation parameter)

  • spatial_relation – Return only maps with the given spatial relation to the provided spatial extent (requires spatial_extent parameter)

Returns

ordered object list, in case nothing found None is returned

get_registered_maps_as_objects_with_temporal_topology(where=None, order='start_time', dbif=None, spatial_extent=None, spatial_relation=None)[source]

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
  • where – The SQL where statement to select a subset of the registered maps without “WHERE”

  • order – The SQL order statement to be used to order the objects in the list without “ORDER BY”

  • dbif – The database interface to be used

  • spatial_extent – Return only maps with the provided spatial relation to the given spatial extent (requires spatial_relation parameter)

  • spatial_relation – Return only maps with the given spatial relation to the provided spatial extent (requires spatial_extent parameter)

Returns

The ordered map object list, In case nothing found None is returned

get_semantic_type()[source]

Return the semantic type of this dataset :return: The semantic type

insert(dbif=None, execute=True)[source]

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
  • dbif – The database interface to be used

  • execute – If True the SQL statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL insert statement in case execute=False, or an empty string otherwise

is_map_registered(map_id, dbif=None)[source]

Check if a map is registered in the space time dataset

Parameters
  • map_id – The map id

  • dbif – The database interface to be used

Returns

True if success, False otherwise

print_history()[source]

Print history information about this class in human readable shell style

print_info()[source]

Print information about this class in human readable style

print_self()[source]

Print the content of the internal structure to stdout

print_shell_info()[source]

Print information about this class in shell style

print_spatio_temporal_relationships(maps=None, spatial=None, dbif=None)[source]

Print the spatio-temporal relationships for each map of the space time dataset or for each map of the optional list of maps

Parameters
  • maps – a ordered by start_time list of map objects, if None the registered maps of the space time dataset are used

  • spatial – This indicates if the spatial topology is created as well: spatial can be None (no spatial topology), “2D” using west, east, south, north or “3D” using west, east, south, north, bottom, top

  • dbif – The database interface to be used

register_map(map, dbif=None)[source]

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
  • map – The AbstractMapDataset object that should be registered

  • dbif – The database interface to be used

Returns

True if success, False otherwise

rename(ident, dbif=None)[source]

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
  • ident – The new identifier “name@mapset

  • dbif – The database interface to be used

static resample_maplist_by_granularity(maps, start, end, gran)[source]

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:

  1. Maps that are equal to the actual granule are used

  2. If no euqal found then maps that contain the actual granule are used

  3. If no maps are found that contain the actual granule then maps are used that overlaps the actual granule

  4. If no overlaps maps found then overlapped maps are used

  5. If no overlapped maps are found then maps are used that are durin the actual granule

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
  • maps – An ordered list (by start time) of AbstractMapDatasets objects. All maps must have the same temporal type and the same unit in case of relative time.

  • start – The start time of the provided map list

  • end – The end time of the provided map list

  • gran – The granularity string to be used, if None the granularity of the space time dataset is used. Absolute time has the format “number unit”, relative time has the format “number”. The unit in case of absolute time can be one of “second, seconds, minute, minutes, hour, hours, day, days, week, weeks, month, months, year, years”. The unit of the relative time granule is always the space time dataset unit and can not be changed.

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 range(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_by_dataset(stds, method=None, spatial=False, dbif=None)[source]

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
  • stds – The space time dataset to be used for temporal sampling

  • method

    This option specifies what sample method should be

    used. In case the registered maps are of temporal point type, only the start time is used for sampling. In case of mixed of interval data the user can chose between:

    • Example [“start”, “during”, “equals”]

    • 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-----------------e
      
    • contains: Select maps which are temporal

      during the selection granule:

      map    :     s-----------e
      granule:  s-----------------e
      
    • overlap: Select maps which temporal overlap the selection granule, this includes overlaps and overlapped:

      map    :     s-----------e
      granule:        s-----------------e
      
      map    :     s-----------e
      granule:  s----------e
      
    • during: Select maps which temporally contains the selection granule:

      map    :  s-----------------e
      granule:     s-----------e
      
    • equals: Select maps which temporally equal to the selection granule:

      map    :  s-----------e
      granule:  s-----------e
      
    • follows: Select maps which temporally follow the selection granule:

      map    :              s-----------e
      granule:  s-----------e
      
    • precedes: Select maps which temporally precedes the selection granule:

      map    :  s-----------e
      granule:              s-----------e
      

    All these methods can be combined. Method must be of type tuple including the identification strings.

  • spatial – If set True additional the 2d spatial overlapping is used for selection -> spatio-temporal relation. The returned map objects will have temporal and spatial extents

  • dbif – The database interface to be used

Returns

A list of lists of map objects or None in case nothing was found None

sample_by_dataset_sql(stds, method=None, spatial=False, dbif=None)[source]

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
  • stds – The space time dataset to be used for temporal sampling

  • method

    This option specifies what sample method should be

    used. In case the registered maps are of temporal point type, only the start time is used for sampling. In case of mixed of interval data the user can chose between:

    • Example [“start”, “during”, “equals”]

    • 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-----------------e
      
    • contains: Select maps which are temporal during the selection granule:

      map    :     s-----------e
      granule:  s-----------------e
      
    • overlap: Select maps which temporal overlap the selection granule, this includes overlaps and overlapped:

      map    :     s-----------e
      granule:        s-----------------e
      
      map    :     s-----------e
      granule:  s----------e
      
    • during: Select maps which temporally contains the selection granule:

      map    :  s-----------------e
      granule:     s-----------e
      
    • equals: Select maps which temporally equal to the selection granule:

      map    :  s-----------e
      granule:  s-----------e
      
    • follows: Select maps which temporally follow the selection granule:

      map    :              s-----------e
      granule:  s-----------e
      
    • precedes: Select maps which temporally precedes the selection granule:

      map    :  s-----------e
      granule:              s-----------e
      

    All these methods can be combined. Method must be of type tuple including the identification strings.

  • spatial – If set True additional the 2d spatial overlapping is used for selection -> spatio-temporal relation. The returned map objects will have temporal and spatial extents

  • dbif – The database interface to be used

Returns

A list of lists of map objects or None in case nothing was found None

set_aggregation_type(aggregation_type)[source]

Set the aggregation type of the space time dataset

Parameters

aggregation_type – The aggregation type of the space time dataset

set_granularity(granularity)[source]

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, minutes, 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_initial_values(temporal_type, semantic_type=None, title=None, description=None)[source]

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
  • temporal_type – The temporal type of this space time dataset (absolute or relative)

  • semantic_type – The semantic type of this dataset

  • title – The title

  • description – The description of this dataset

abstract set_map_register(name)[source]

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_relative_time_unit(unit)[source]

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

shift(gran, dbif=None)[source]

Temporally shift each registered map with the provided granularity

Parameters
  • gran – The granularity to be used for shifting

  • dbif – The database interface to be used

Returns

True something to shift, False if nothing to shift or wrong granularity

static shift_map_list(maps, gran)[source]

Temporally shift each map in the list with the provided granularity

This method does not perform any temporal database operations.

Parameters
  • maps – A list of maps with initialized temporal extent

  • gran – The granularity to be used for shifting

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
snap(dbif=None)[source]

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

static snap_map_list(maps)[source]

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_map(map, dbif=None, execute=True)[source]

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
  • map – The map object to unregister

  • dbif – The database interface to be used

  • execute – If True the SQL DELETE and DROP table statements will be executed. If False the prepared SQL statements are returned and must be executed by the caller.

Returns

The SQL statements if execute == False, else an empty string, None in case of a failure

update_command_string(dbif=None)[source]

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

update_from_registered_maps(dbif=None)[source]

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

grass.temporal.aggregation module

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

grass.temporal.aggregation.aggregate_by_topology(granularity_list, granularity, map_list, topo_list, basename, time_suffix, offset=0, method='average', nprocs=1, spatial=None, dbif=None, overwrite=False, file_limit=1000)[source]

Aggregate a list of raster input maps with r.series

Parameters
  • granularity_list – A list of AbstractMapDataset objects. The temporal extents of the objects are used to build the spatio-temporal topology with the map list objects

  • granularity – The granularity of the granularity list

  • map_list – A list of RasterDataset objects that contain the raster maps that should be aggregated

  • topo_list – A list of strings of topological relations that are used to select the raster maps for aggregation

  • basename – The basename of the new generated raster maps

  • time_suffix – Use the granularity truncated start time of the actual granule to create the suffix for the basename

  • offset – Use a numerical offset for suffix generation (overwritten by time_suffix)

  • method – The aggregation method of r.series (average,min,max, …)

  • nprocs – The number of processes used for parallel computation

  • spatial – This indicates if the spatial topology is created as well: spatial can be None (no spatial topology), “2D” using west, east, south, north or “3D” using west, east, south, north, bottom, top

  • dbif – The database interface to be used

  • overwrite – Overwrite existing raster maps

  • file_limit – The maximum number of raster map layers that should be opened at once by r.series

Returns

A list of RasterDataset objects that contain the new map names and the temporal extent for map registration

grass.temporal.aggregation.aggregate_raster_maps(inputs, base, start, end, count, method, register_null, dbif, offset=0)[source]

Aggregate a list of raster input maps with r.series

Parameters
  • inputs – The names of the raster maps to be aggregated

  • base – The basename of the new created raster maps

  • start – The start time of the sample interval, may be relative or absolute

  • end – The end time of the sample interval, may be relative or absolute

  • count – The number to be attached to the basename of the new created raster map

  • method – The aggregation method to be used by r.series

  • register_null – If true null maps will be registered in the space time raster dataset, if false not

  • dbif – The temporal database interface to use

  • offset – Offset to be added to the map counter to create the map ids

grass.temporal.aggregation.collect_map_names(sp, dbif, start, end, sampling)[source]

Gather all maps from dataset using a specific sample method

Parameters
  • sp – The space time raster dataset to select aps from

  • dbif – The temporal database interface to use

  • start – The start time of the sample interval, may be relative or absolute

  • end – The end time of the sample interval, may be relative or absolute

  • sampling – The sampling methods to use

grass.temporal.base module

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

class grass.temporal.base.AbstractSTDSRegister(table=None, ident=None, registered_stds=None)[source]

Bases: grass.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'

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • stds – A comma separated list of space time dataset ids

get_id()[source]

Convenient method to get the unique identifier (primary key)

Returns

None if not found

get_registered_stds()[source]

Get the comma separated list of space time datasets ids in which this map is registered

Returns

None if not found

property id

Convenient method to get the unique identifier (primary key)

Returns

None if not found

property registered_stds

Get the comma separated list of space time datasets ids in which this map is registered

Returns

None if not found

set_id(ident)[source]

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”

set_registered_stds(registered_stds)[source]

Get the comma separated list of space time datasets ids in which this map is registered

Parameters

registered_stds – A comma separated list of space time dataset ids in which this map is registered

class grass.temporal.base.DatasetBase(table=None, ident=None, name=None, mapset=None, creator=None, ctime=None, ttype=None)[source]

Bases: grass.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'

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

property creator

Get the creator of the dataset :return: None if not found

property ctime

Get the creation time of the dataset, datatype is datetime :return: None if not found

get_creator()[source]

Get the creator of the dataset :return: None if not found

get_ctime()[source]

Get the creation time of the dataset, datatype is datetime :return: None if not found

get_id()[source]

Convenient method to get the unique identifier (primary key)

Returns

None if not found

get_layer()[source]

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

get_map_id()[source]

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_mapset()[source]

Get the name of mapset of this dataset :return: None if not found

get_name()[source]

Get the name of the dataset :return: None if not found

get_ttype()[source]

Get the temporal type of the map :return: None if not found

property id

Convenient method to get the unique identifier (primary key)

Returns

None if not found

property map_id

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

property mapset

Get the name of mapset of this dataset :return: None if not found

property name

Get the name of the dataset :return: None if not found

print_info()[source]

Print information about this class in human readable style

print_shell_info()[source]

Print information about this class in shell style

set_creator(creator)[source]

Set the creator of the dataset

Parameters

creator – The name of the creator

set_ctime(ctime=None)[source]

Set the creation time of the dataset, if nothing set the current time is used

Parameters

ctime – The current time of type datetime

set_id(ident)[source]

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”

set_layer(layer)[source]

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_mapset(mapset)[source]

Set the mapset of the dataset

Parameters

mapset – The name of the mapset in which this dataset is stored

set_name(name)[source]

Set the name of the dataset

Parameters

name – The name of the dataset

set_ttype(ttype)[source]

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”

property ttype

Get the temporal type of the map :return: None if not found

class grass.temporal.base.DictSQLSerializer[source]

Bases: object

clear()[source]

Initialize the internal storage

deserialize(row)[source]

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

print_self()[source]

Print the content of the internal dictionary to stdout

serialize(type, table, where=None)[source]

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
class grass.temporal.base.Raster3DBase(ident=None, name=None, mapset=None, creator=None, creation_time=None, temporal_type=None)[source]

Bases: grass.temporal.base.DatasetBase

Time stamped 3D raster map base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

class grass.temporal.base.Raster3DSTDSRegister(ident=None, registered_stds=None)[source]

Bases: grass.temporal.base.AbstractSTDSRegister

Time stamped 3D raster map base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • stds – A comma separated list of space time dataset ids

class grass.temporal.base.RasterBase(ident=None, name=None, mapset=None, creator=None, creation_time=None, temporal_type=None)[source]

Bases: grass.temporal.base.DatasetBase

Time stamped raster map base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

class grass.temporal.base.RasterSTDSRegister(ident=None, registered_stds=None)[source]

Bases: grass.temporal.base.AbstractSTDSRegister

Time stamped raster map base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • stds – A comma separated list of space time dataset ids

class grass.temporal.base.SQLDatabaseInterface(table=None, ident=None)[source]

Bases: grass.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:

  • Identification information (base)

  • Spatial extent

  • Temporal extent

  • Metadata

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"

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

delete(dbif=None)[source]

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

get_delete_statement()[source]

Return the delete string :return: The DELETE string

get_insert_statement()[source]

Return the sql statement and the argument list in database specific style :return: The INSERT string

get_insert_statement_mogrified(dbif=None)[source]

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

get_is_in_db_statement()[source]

Return the selection string that checks if this object is registered in the temporal database :return: The SELECT string

get_select_statement()[source]

Return the sql statement and the argument list in database specific style :return: The SELECT string

get_select_statement_mogrified(dbif=None)[source]

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

get_table_name()[source]

Return the name of the table in which the internal data are inserted, updated or selected :return: The name of the table

get_update_all_statement(ident=None)[source]

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

get_update_all_statement_mogrified(dbif=None, ident=None)[source]

Return the update all statement as mogrified string

Parameters
  • dbif – The database interface to be used, if None a temporary connection will be established

  • ident – The identifier to be updated, useful for renaming

Returns

The UPDATE string

get_update_statement(ident=None)[source]

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

get_update_statement_mogrified(dbif=None, ident=None)[source]

Return the update statement as mogrified string

Parameters
  • dbif – The database interface to be used, if None a temporary connection will be established

  • ident – The identifier to be updated, useful for renaming

Returns

The UPDATE string

insert(dbif=None)[source]

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

is_in_db(dbif=None, mapset=None)[source]

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

  • mapset – The mapset with a temporal database to be used The mapset of the database can be different from the mapset of the map

Returns

True if this object is present in the temporal database, False otherwise

select(dbif=None, mapset=None)[source]

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

update(dbif=None, ident=None)[source]

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
  • dbif – The database interface to be used, if None a temporary connection will be established

  • ident – The identifier to be updated, useful for renaming

update_all(dbif=None, ident=None)[source]

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

class grass.temporal.base.STDSBase(table=None, ident=None, name=None, mapset=None, semantic_type=None, creator=None, ctime=None, ttype=None, mtime=None)[source]

Bases: grass.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

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

get_mtime()[source]

Get the modification time of the space time dataset, datatype is datetime

Returns

None if not found

get_semantic_type()[source]

Get the semantic type of the space time dataset :return: None if not found

print_info()[source]

Print information about this class in human readable style

print_shell_info()[source]

Print information about this class in shell style

property semantic_type

Get the semantic type of the space time dataset :return: None if not found

set_mtime(mtime=None)[source]

Set the modification time of the space time dataset, if nothing set the current time is used

set_semantic_type(semantic_type)[source]

Set the semantic type of the space time dataset

class grass.temporal.base.STR3DSBase(ident=None, name=None, mapset=None, semantic_type=None, creator=None, ctime=None, ttype=None)[source]

Bases: grass.temporal.base.STDSBase

Space time 3D raster dataset base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

class grass.temporal.base.STRDSBase(ident=None, name=None, mapset=None, semantic_type=None, creator=None, ctime=None, ttype=None)[source]

Bases: grass.temporal.base.STDSBase

Space time raster dataset base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

class grass.temporal.base.STVDSBase(ident=None, name=None, mapset=None, semantic_type=None, creator=None, ctime=None, ttype=None)[source]

Bases: grass.temporal.base.STDSBase

Space time vector dataset base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

class grass.temporal.base.VectorBase(ident=None, name=None, mapset=None, layer=None, creator=None, creation_time=None, temporal_type=None)[source]

Bases: grass.temporal.base.DatasetBase

Time stamped vector map base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • name – The name of the map or dataset

  • mapset – The name of the mapset

  • creator – The name of the creator

  • ctime – The creation datetime object

  • ttype

    The temporal type

    • ”absolute” Identifier for absolute time

    • ”relative” Identifier for relative time

class grass.temporal.base.VectorSTDSRegister(ident=None, registered_stds=None)[source]

Bases: grass.temporal.base.AbstractSTDSRegister

Time stamped vector map base information class

Constructor

Parameters
  • table – The name of the temporal database table that should be used to store the values

  • ident – The unique identifier must be a combination of the dataset name, layer name and the mapset “name@mapset” or “name:layer@mapset” used as as primary key in the temporal database

  • stds – A comma separated list of space time dataset ids

grass.temporal.c_libraries_interface module

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

class grass.temporal.c_libraries_interface.CLibrariesInterface[source]

Bases: grass.pygrass.rpc.base.RPCServerBase

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}

>>> info = ciface.read_raster_full_info("test", tgis.get_current_mapset())
>>> info           
{u'tbres': 1.0, ... 'keyword': 'generated by r.mapcalc',
 u'bottom': 0.0, 'end_time': None, 'title': 'test', u'south': 0.0}

>>> info["start_time"]
datetime.datetime(1995, 3, 12, 10, 34, 40)
>>> info["end_time"]

>>> 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())
>>> kvp['points']
10

>>> kvp = ciface.read_vector_full_info("test", tgis.get_current_mapset())
>>> print kvp['points']
10
>>> kvp['point']
10
>>> kvp['area']
0
>>> kvp['lines']
0
>>> kvp['line']
0
>>> 'columns' in kvp
False
>>> kvp["start_time"]
datetime.datetime(1995, 3, 12, 10, 34, 40)
>>> kvp["end_time"]

>>> 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()

>>> ciface.fatal_error() 
Traceback (most recent call last):
    raise FatalError("Exception raised: " + str(e) + " Message: " + message)
FatalError: Exception raised:  ...

>>> ciface.fatal_error() 
Traceback (most recent call last):
    raise FatalError("Exception raised: " + str(e) + " Message: " + message)
FatalError: Exception raised:  ...

>>> ciface.fatal_error() 
Traceback (most recent call last):
    raise FatalError("Exception raised: " + str(e) + " Message: " + message)
FatalError: Exception raised:  ...

>>> ciface.fatal_error() 
Traceback (most recent call last):
    raise FatalError("Exception raised: " + str(e) + " Message: " + message)
FatalError: Exception raised:  ...

>>> ciface.stop()

>>> gscript.del_temp_region()
available_mapsets()[source]

Return all available mapsets the user can access as a list of strings

Returns

Names of available mapsets as list of strings

fatal_error(mapset=None)[source]

Generate a fatal error in libgis.

This function is only for testing purpose.

get_database_name(mapset=None)[source]

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

get_driver_name(mapset=None)[source]

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

get_gisdbase()[source]

Return the gisdatabase

Returns

Name of the gisdatabase

get_location()[source]

Return the location

Returns

Name of the location

get_mapset()[source]

Return the current mapset

Returns

Name of the current mapset

has_raster3d_timestamp(name, mapset)[source]

Check if a file based 3D raster timestamp exists

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

True if exists, False if not

has_raster_timestamp(name, mapset)[source]

Check if a file based raster timestamp exists

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

True if exists, False if not

has_vector_timestamp(name, mapset, layer=None)[source]

Check if a file based vector timestamp exists

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

  • layer – The layer of the vector map

Returns

True if exists, False if not

raster3d_map_exists(name, mapset)[source]

Check if a 3D raster map exists in the spatial database

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

True if exists, False if not

raster_map_exists(name, mapset)[source]

Check if a raster map exists in the spatial database

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

True if exists, False if not

read_raster3d_info(name, mapset)[source]

Read the 3D raster map info from the file system and store the content into a dictionary

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The key value pairs of the map specific metadata, or None in case of an error

read_raster3d_timestamp(name, mapset)[source]

Read a file based 3D raster timestamp

Please have a look at the documentation G_read_raster3d_timestamp for the return values description.

The timestamps to be send are tuples of values:
  • relative time (start, end, unit), start and end are of type integer, unit is of type string.

  • absolute time (start, end), start and end are of type datetime

The end time may be None in case of a time instance.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The return value of G_read_raster3d_timestamp

read_raster_full_info(name, mapset)[source]

Read raster info, history and cats using PyGRASS RasterRow and return a dictionary. Colors should be supported in the future.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The key value pairs of the map specific metadata, or None in case of an error

read_raster_info(name, mapset)[source]

Read the raster map info from the file system and store the content into a dictionary

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The key value pairs of the map specific metadata, or None in case of an error

read_raster_semantic_label(name, mapset)[source]

Read a file based raster semantic label

Returns semantic label or None

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The return value of Rast_read_semantic_label

read_raster_timestamp(name, mapset)[source]

Read a file based raster timestamp

Please have a look at the documentation G_read_raster_timestamp for the return values description.

The timestamps to be send are tuples of values:
  • relative time (start, end, unit), start and end are of type integer, unit is of type string.

  • absolute time (start, end), start and end are of type datetime

The end time may be None in case of a time instance.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The return value of G_read_raster_timestamp

read_vector_full_info(name, mapset)[source]

Read vector info using PyGRASS VectorTopo and return a dictionary.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The key value pairs of the map specific metadata, or None in case of an error

read_vector_info(name, mapset)[source]

Read the vector map info from the file system and store the content into a dictionary

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The key value pairs of the map specific metadata, or None in case of an error

read_vector_timestamp(name, mapset, layer=None)[source]

Read a file based vector timestamp

Please have a look at the documentation G_read_vector_timestamp for the return values description.

The timestamps to be send are tuples of values:
  • relative time (start, end, unit), start and end are of type integer, unit is of type string.

  • absolute time (start, end), start and end are of type datetime

The end time may be None in case of a time instance.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

  • layer – The layer of the vector map

Returns

The return value ofG_read_vector_timestamp and the timestamps

remove_raster3d_timestamp(name, mapset)[source]

Remove a file based 3D raster timestamp

Please have a look at the documentation G_remove_raster3d_timestamp for the return values description.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The return value of G_remove_raster3d_timestamp

remove_raster_semantic_label(name, mapset)[source]

Remove a file based raster semantic label

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The return value of G_remove_misc

remove_raster_timestamp(name, mapset)[source]

Remove a file based raster timestamp

Please have a look at the documentation G_remove_raster_timestamp for the return values description.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

The return value of G_remove_raster_timestamp

remove_vector_timestamp(name, mapset, layer=None)[source]

Remove a file based vector timestamp

Please have a look at the documentation G_remove_vector_timestamp for the return values description.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

  • layer – The layer of the vector map

Returns

The return value of G_remove_vector_timestamp

start_server()[source]

This function must be re-implemented in the subclasses

vector_map_exists(name, mapset)[source]

Check if a vector map exists in the spatial database

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

Returns

True if exists, False if not

write_raster3d_timestamp(name, mapset, timestring)[source]

Write a file based 3D raster timestamp

Please have a look at the documentation G_write_raster3d_timestamp for the return values description.

Note:

Only timestamps of maps from the current mapset can written.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

  • timestring – A GRASS datetime C-library compatible string

Returns

The return value of G_write_raster3d_timestamp

write_raster_semantic_label(name, mapset, semantic_label)[source]

Write a file based raster semantic label

Note:

Only semantic labels of maps from the current mapset can be written.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

  • semantic_label – semantic label

Returns

always True

write_raster_timestamp(name, mapset, timestring)[source]

Write a file based raster timestamp

Please have a look at the documentation G_write_raster_timestamp for the return values description.

Note:

Only timestamps of maps from the current mapset can written.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

  • timestring – A GRASS datetime C-library compatible string

Returns

The return value of G_write_raster_timestamp

write_vector_timestamp(name, mapset, timestring, layer=None)[source]

Write a file based vector timestamp

Please have a look at the documentation G_write_vector_timestamp for the return values description.

Note:

Only timestamps pf maps from the current mapset can written.

Parameters
  • name – The name of the map

  • mapset – The mapset of the map

  • timestring – A GRASS datetime C-library compatible string

  • layer – The layer of the vector map

Returns

The return value of G_write_vector_timestamp

class grass.temporal.c_libraries_interface.RPCDefs[source]

Bases: object

AVAILABLE_MAPSETS = 8
GET_DATABASE_NAME = 10
GET_DRIVER_NAME = 9
G_FATAL_ERROR = 49
G_GISDBASE = 13
G_LOCATION = 12
G_MAPSET = 11
HAS_TIMESTAMP = 1
MAP_EXISTS = 6
READ_MAP_FULL_INFO = 14
READ_MAP_INFO = 7
READ_SEMANTIC_LABEL = 16
READ_TIMESTAMP = 3
REMOVE_SEMANTIC_LABEL = 17
REMOVE_TIMESTAMP = 4
STOP = 0
TYPE_RASTER = 0
TYPE_RASTER3D = 1
TYPE_VECTOR = 2
WRITE_SEMANTIC_LABEL = 15
WRITE_TIMESTAMP = 2
grass.temporal.c_libraries_interface.c_library_server(lock, conn)[source]

The GRASS C-libraries server function designed to be a target for multiprocessing.Process

Parameters
  • lock – A multiprocessing.Lock

  • conn – A multiprocessing.Pipe

grass.temporal.core module

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, connection_state_changed = 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

class grass.temporal.core.DBConnection(backend=None, dbstring=None)[source]

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

Constructor of a database connection

param backend:The database backend sqlite or pg param dbstring: The database connection string

check_table(table_name)[source]

Check if a table exists in the temporal database

Parameters
  • table_name – The name of the table to be checked for existence

  • mapset – The mapset of the abstract dataset or temporal database location, if None the current mapset will be used

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()[source]

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(dbstring=None)[source]

Connect to the DBMI to execute SQL statements

Supported backends are sqlite3 and postgresql

param dbstring: The database connection string

execute(statement, args=None)[source]

Execute a SQL statement

Parameters

statement – The executable SQL statement or SQL script

execute_transaction(statement, mapset=None)[source]

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

fetchall()[source]
fetchone()[source]
is_connected()[source]
mogrify_sql_statement(content)[source]

Return the SQL statement and arguments as executable SQL string

TODO: Use the mapset argument to identify the correct database driver

Parameters
  • content – The content as tuple with two entries, the first entry is the SQL statement with DBMI specific place holder (?), the second entry is the argument list that should substitute the place holder.

  • mapset – The mapset of the abstract dataset or temporal database location, if None the current mapset will be used

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'"
rollback()[source]

Roll back the last transaction. This must be called in case a new query should be performed after a db error.

This is only relevant for postgresql database.

class grass.temporal.core.SQLDatabaseInterfaceConnection[source]

Bases: object

check_table(table_name, mapset=None)[source]

Check if a table exists in the temporal database

Parameters
  • table_name – The name of the table to be checked for existence

  • mapset – The mapset of the abstract dataset or temporal database location, if None the current mapset will be used

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()[source]

Close the DBMI connection

There may be several temporal databases in a location, hence close all temporal databases that have been opened.

connect()[source]

Connect to the DBMI to execute SQL statements

Supported backends are sqlite3 and postgresql

execute(statement, args=None, mapset=None)[source]
Parameters

mapset – The mapset of the abstract dataset or temporal database location, if None the current mapset will be used

execute_transaction(statement, mapset=None)[source]

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

fetchall(mapset=None)[source]
fetchone(mapset=None)[source]
get_dbmi(mapset=None)[source]
is_connected()[source]
mogrify_sql_statement(content, mapset=None)[source]

Return the SQL statement and arguments as executable SQL string

Parameters
  • content – The content as tuple with two entries, the first entry is the SQL statement with DBMI specific place holder (?), the second entry is the argument list that should substitute the place holder.

  • mapset – The mapset of the abstract dataset or temporal database location, if None the current mapset will be used

rollback(mapset=None)[source]

Roll back the last transaction. This must be called in case a new query should be performed after a db error.

This is only relevant for postgresql database.

grass.temporal.core.create_temporal_database(dbif)[source]

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

grass.temporal.core.get_available_temporal_mapsets()[source]

Return a list of of mapset names with temporal database driver and names that are accessible from the current mapset.

Returns

A dictionary, mapset names are keys, the tuple (driver, database) are the values

grass.temporal.core.get_current_gisdbase()[source]

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.

grass.temporal.core.get_current_location()[source]

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.

grass.temporal.core.get_current_mapset()[source]

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.

grass.temporal.core.get_database_info_string()[source]
grass.temporal.core.get_enable_mapset_check()[source]

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.
grass.temporal.core.get_enable_timestamp_write()[source]

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.
grass.temporal.core.get_raise_on_error()[source]

Return True if a FatalError exception is raised instead of calling sys.exit(1) in case a fatal error was invoked with msgr.fatal()

grass.temporal.core.get_sql_template_path()[source]
grass.temporal.core.get_tgis_backend()[source]

Return the temporal GIS backend as string

Returns

either “sqlite” or “pg”

grass.temporal.core.get_tgis_c_library_interface()[source]

Return the C-library interface that provides a fast and exit safe interface to the C-library libgis, libraster, libraster3d and libvector functions

grass.temporal.core.get_tgis_database()[source]

Return the temporal database string specified with t.connect

grass.temporal.core.get_tgis_database_string()[source]

Return the preprocessed temporal database string

This string is the temporal database string set with t.connect that was processed to substitute location, gisdbase and mapset variables.

grass.temporal.core.get_tgis_db_version()[source]

Get the supported version of the temporal database :returns: The version number of the temporal database as integer

grass.temporal.core.get_tgis_db_version_from_metadata(metadata=None)[source]

Get the version number of the temporal database from metadata

Parameters

metadata (list) – list of metadata items or None

Returns

The version number of the temporal database as integer

grass.temporal.core.get_tgis_dbmi_paramstyle()[source]

Return the temporal database backend parameter style

Returns

“qmark” or “”

grass.temporal.core.get_tgis_message_interface()[source]

Return the temporal GIS message interface which is of type grass.pygrass.message.Messenger()

Use this message interface to print messages to stderr using the GRASS C-library messaging system.

grass.temporal.core.get_tgis_metadata(dbif=None)[source]

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

grass.temporal.core.get_tgis_version()[source]

Get the supported version of the temporal framework :returns: The version number of the temporal framework as integer

grass.temporal.core.init(raise_fatal_error=False, skip_db_version_check=False)[source]

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 exist.

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:

  • MAPSET

  • LOCATION_NAME

  • GISDBASE

  • TGIS_DISABLE_MAPSET_CHECK

  • TGIS_DISABLE_TIMESTAMP_WRITE

Re-run this function if the following t.connect variables change while the process runs:

  • temporal GIS driver (set by t.connect driver=)

  • temporal GIS database (set by t.connect database=)

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.

param skip_db_version_check

Set this True to skip mismatch temporal database version check. Recommended to be used only for upgrade_temporal_database().

grass.temporal.core.init_dbif(dbif)[source]

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 not connected, the connection will be established.

Returns

the tuple (dbif, connection_state_changed)

Usage code sample:

dbif, connection_state_changed = tgis.init_dbif(None)

sql = dbif.mogrify_sql_statement(["SELECT * FROM raster_base WHERE ? = ?"],
                                       ["id", "soil@PERMANENT"])
dbif.execute_transaction(sql)

if connection_state_changed:
    dbif.close()
grass.temporal.core.profile_function(func)[source]

Profiling function provided by the temporal framework

grass.temporal.core.set_raise_on_error(raise_exp=True)[source]

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!
Returns

current status

grass.temporal.core.stop_subprocesses()[source]

Stop the messenger and C-interface subprocesses that are started by tgis.init()

grass.temporal.core.upgrade_temporal_database(dbif)[source]

This function will upgrade the temporal database if needed.

It will update all tables and triggers that are requested by currently supported TGIS DB version.

Parameters

dbif – The database interface to be used

grass.temporal.datetime_math module

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

grass.temporal.datetime_math.adjust_datetime_to_granularity(mydate, granularity)[source]

Modify the datetime object to fit the given granularity

  • Years will start at the first of January

  • Months will start at the first day of the month

  • Days will start at the first Hour of the day

  • Hours will start at the first minute of an hour

  • Minutes will start at the first second of a minute

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)
grass.temporal.datetime_math.check_datetime_string(time_string, use_dateutil=True)[source]

Check if a string can be converted into a datetime object and return the object

In case datutil is not installed the supported ISO string formats are:

  • YYYY-mm-dd

  • YYYY-mm-dd HH:MM:SS

  • YYYY-mm-ddTHH:MM:SS

  • YYYY-mm-dd HH:MM:SS.s

  • YYYY-mm-ddTHH:MM:SS.s

Time zones are not supported

If dateutil is installed, all string formats of the dateutil module are supported, as well as time zones Time zones are not supported

Parameters
  • time_string – The time string to be checked for conversion

  • use_dateutil – Use dateutil if available for datetime string parsing

Returns

datetime: object or an error message string in case of an error

>>> s = "2000-01-01"
>>> check_datetime_string(s)
datetime.datetime(2000, 1, 1, 0, 0)
>>> s = "2000-01-01T10:00:00"
>>> check_datetime_string(s)
datetime.datetime(2000, 1, 1, 10, 0)
>>> s = "2000-01-01 10:00:00"
>>> check_datetime_string(s)
datetime.datetime(2000, 1, 1, 10, 0)
>>> s = "2000-01-01T10:00:00.000001"
>>> check_datetime_string(s)
datetime.datetime(2000, 1, 1, 10, 0, 0, 1)
>>> s = "2000-01-01 10:00:00.000001"
>>> check_datetime_string(s)
datetime.datetime(2000, 1, 1, 10, 0, 0, 1)

# using native implementation, ignoring dateutil >>> s = “2000-01-01” >>> check_datetime_string(s, False) datetime.datetime(2000, 1, 1, 0, 0) >>> s = “2000-01-01T10:00:00” >>> check_datetime_string(s, False) datetime.datetime(2000, 1, 1, 10, 0) >>> s = “2000-01-01 10:00:00” >>> check_datetime_string(s, False) datetime.datetime(2000, 1, 1, 10, 0) >>> s = “2000-01-01T10:00:00.000001” >>> check_datetime_string(s, False) datetime.datetime(2000, 1, 1, 10, 0, 0, 1) >>> s = “2000-01-01 10:00:00.000001” >>> check_datetime_string(s, False) datetime.datetime(2000, 1, 1, 10, 0, 0, 1)

grass.temporal.datetime_math.compute_datetime_delta(start, end)[source]

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()

grass.temporal.datetime_math.create_numeric_suffix(base, count, zeros)[source]

Create a string based on count and number of zeros decided by zeros

Parameters
  • base – the basename for new map

  • count – a number

  • zeros – a string containing the expected number, coming from suffix option like “%05”

grass.temporal.datetime_math.create_suffix_from_datetime(start_time, granularity)[source]

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
  • start_time – The datetime object

  • granularity – The granularity for example “1 month” or “100 seconds”

Returns

A string

grass.temporal.datetime_math.create_time_suffix(mapp, end=False)[source]

Create a datetime string based on a map datetime object

Parameters
  • mapp – a temporal map dataset

  • end – True if you want add also end time to the suffix

grass.temporal.datetime_math.datetime_to_grass_datetime_string(dt)[source]

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'
grass.temporal.datetime_math.decrement_datetime_by_string(mydate, increment, mult=1)[source]

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
  • mydate – A datetime object to incremented

  • increment – A string providing increment information: The string may include comma separated values of type seconds, minutes, hours, days, weeks, months and years Example: Increment the datetime 2001-01-01 00:00:00 with “60 seconds, 4 minutes, 12 hours, 10 days, 1 weeks, 5 months, 1 years” will result in the datetime 2003-02-18 12:05:00

  • mult – A multiplier, default is 1

Returns

The new datetime object or none in case of an error

grass.temporal.datetime_math.increment_datetime_by_string(mydate, increment, mult=1)[source]

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
  • mydate – A datetime object to incremented

  • increment – A string providing increment information: The string may include comma separated values of type seconds, minutes, hours, days, weeks, months and years Example: Increment the datetime 2001-01-01 00:00:00 with “60 seconds, 4 minutes, 12 hours, 10 days, 1 weeks, 5 months, 1 years” will result in the datetime 2003-02-18 12:05:00

  • mult – A multiplier, default is 1

Returns

The new datetime object or none in case of an error

grass.temporal.datetime_math.modify_datetime(mydate, years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0)[source]

Return a new datetime object incremented with the provided relative dates and times

grass.temporal.datetime_math.modify_datetime_by_string(mydate, increment, mult=1, sign=1)[source]

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
  • mydate – A datetime object to incremented

  • increment – A string providing increment information: The string may include comma separated values of type seconds, minutes, hours, days, weeks, months and years Example: Increment the datetime 2001-01-01 00:00:00 with “60 seconds, 4 minutes, 12 hours, 10 days, 1 weeks, 5 months, 1 years” will result in the datetime 2003-02-18 12:05:00

  • mult – A multiplier, default is 1

  • sign – Choose 1 for positive sign (incrementing) or -1 for negative sign (decrementing).

Returns

The new datetime object or none in case of an error

grass.temporal.datetime_math.relative_time_to_time_delta(value)[source]

Convert the double value representing days into a timedelta object.

grass.temporal.datetime_math.relative_time_to_time_delta_seconds(value)[source]

Convert the double value representing seconds into a timedelta object.

grass.temporal.datetime_math.string_to_datetime(time_string)[source]

Convert a string into a datetime object

In case datutil is not installed the supported ISO string formats are:

  • YYYY-mm-dd

  • YYYY-mm-dd HH:MM:SS

  • YYYY-mm-ddTHH:MM:SS

  • YYYY-mm-dd HH:MM:SS.s

  • YYYY-mm-ddTHH:MM:SS.s

Time zones are not supported

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

grass.temporal.datetime_math.time_delta_to_relative_time(delta)[source]

Convert the time delta into a double value, representing days.

grass.temporal.datetime_math.time_delta_to_relative_time_seconds(delta)[source]

Convert the time delta into a double value, representing seconds.

grass.temporal.extract module

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

grass.temporal.extract.extract_dataset(input, output, type, where, expression, base, time_suffix, nprocs=1, register_null=False, layer=1, vtype='point,line,boundary,centroid,area,face')[source]

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
  • input – The name of the input space time raster/raster3d dataset

  • output – The name of the extracted new space time raster/raster3d dataset

  • type – The type of the dataset: “raster”, “raster3d” or vector

  • where – The temporal SQL WHERE statement for subset extraction

  • expression – The r(3).mapcalc expression or the v.extract where statement

  • base – The base name of the new created maps in case a mapclac expression is provided

  • time_suffix – string to choose which suffix to use: gran, time, num%* (where * are digits)

  • nprocs – The number of parallel processes to be used for mapcalc processing

  • register_null – Set this number True to register empty maps (only raster and raster3d maps)

  • layer – The vector layer number to be used when no timestamped layer is present, default is 1

  • vtype – The feature type to be extracted for vector maps, default is point,line,boundary,centroid,area and face

grass.temporal.extract.run_mapcalc2d(expr)[source]

Helper function to run r.mapcalc in parallel

grass.temporal.extract.run_mapcalc3d(expr)[source]

Helper function to run r3.mapcalc in parallel

grass.temporal.extract.run_vector_extraction(input, output, layer, type, where)[source]

Helper function to run r.mapcalc in parallel

grass.temporal.factory module

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

grass.temporal.factory.dataset_factory(type, id)[source]

A factory functions to create space time or map datasets

Parameters
  • type – the dataset type: rast or raster; rast3d, raster3d or raster_3d; vect or vector; strds; str3ds; stvds

  • id – The id of the dataset (“name@mapset”)

grass.temporal.gui_support module

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

grass.temporal.gui_support.tlist(type, dbif=None)[source]

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

grass.temporal.gui_support.tlist_grouped(type, group_type=False, dbif=None)[source]

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:

>>> import grass.temporalas tgis
>>> tgis.tlist_grouped('strds')['PERMANENT']
['precipitation', 'temperature']
Parameters
  • type – element type (strds, str3ds, stvds)

  • group_type – TBD

Returns

directory of mapsets/elements

grass.temporal.list_stds module

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-2022 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

authors

Vaclav Petras

grass.temporal.list_stds.get_dataset_list(type, temporal_type, columns=None, where=None, order=None, dbif=None)[source]

Return a list of time stamped maps or space time datasets of a specific temporal type that are registered 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
  • type – The type of the datasets (strds, str3ds, stvds, raster, raster_3d, vector)

  • temporal_type – The temporal type of the datasets (absolute, relative)

  • columns – A comma separated list of columns that will be selected

  • where – A where statement for selected listing without “WHERE”

  • order – A comma separated list of columns to order the datasets by category

  • dbif – The database interface to be used

Returns

A dictionary with the rows of the SQL query for each available mapset

>>> import grass.temporal as tgis
>>> tgis.core.init()
>>> name = "list_stds_test"
>>> sp = tgis.open_stds.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.list_stds.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.list_stds.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()
grass.temporal.list_stds.list_maps_of_stds(type, input, columns, order, where, separator, method, no_header=False, gran=None, dbif=None, outpath=None, output_format=None)[source]

List the maps of a space time dataset using different methods

Parameters
  • type – The type of the maps raster, raster3d or vector

  • input – Name of a space time raster dataset

  • columns – A comma separated list of columns to be printed to stdout

  • order – A comma separated list of columns to order the maps by category

  • where – A where statement for selected listing without “WHERE” e.g: start_time < “2001-01-01” and end_time > “2001-01-01”

  • separator – The field separator character between the columns

  • method – String identifier to select a method out of cols, comma,delta or deltagaps

  • dbif

    The database interface to be used

    • ”cols” Print preselected columns specified by columns

    • ”comma” Print the map ids (“name@mapset”) as comma separated string

    • ”delta” Print the map ids (“name@mapset”) with start time,

      end time, relative length of intervals and the relative distance to the begin

    • ”deltagaps” Same as “delta” with additional listing of gaps.

      Gaps can be easily identified as the id is “None”

    • ”gran” List map using the granularity of the space time dataset,

      columns are identical to deltagaps

  • no_header – Suppress the printing of column names

  • gran – The user defined granule to be used if method=gran is set, in case gran=None the granule of the space time dataset is used

  • outpath – The path to file where to save output

grass.temporal.mapcalc module

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

grass.temporal.mapcalc.dataset_mapcalculator(inputs, output, type, expression, base, method, nprocs=1, register_null=False, spatial=False)[source]

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:

  • td() - the time delta of the current interval in days

    and fractions of days or the unit in case of relative time

  • start_time() - The start time of the interval from the begin of

    the time series in days and fractions of days or the unit in case of relative time

  • end_time() - The end time of the current interval from the begin of

    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]

  • start_dow() - Day of week (dow) from the start time [1 - 7],

    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]

  • end_dow() - Day of week (dow) from the end time [1 - 7],

    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
  • inputs – The names of the input space time raster/raster3d datasets

  • output – The name of the extracted new space time raster(3d) dataset

  • type – The type of the dataset: “raster” or “raster3d”

  • expression – The r(3).mapcalc expression

  • base – The base name of the new created maps in case a mapclac expression is provided

  • method – The method to be used for temporal sampling

  • nprocs – The number of parallel processes to be used for mapcalc processing

  • register_null – Set this number True to register empty maps

  • spatial – Check spatial overlap

grass.temporal.metadata module

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

class grass.temporal.metadata.Raster3DMetadata(ident=None, datatype=None, cols=None, rows=None, depths=None, number_of_cells=None, nsres=None, ewres=None, tbres=None, min=None, max=None)[source]

Bases: grass.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

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

property depths

Get number of depths :return: None if not found

get_depths()[source]

Get number of depths :return: None if not found

get_tbres()[source]

Get top-bottom resolution :return: None if not found

set_depths(depths)[source]

Set the number of depths

set_tbres(tbres)[source]

Set the top-bottom resolution

property tbres

Get top-bottom resolution :return: None if not found

class grass.temporal.metadata.RasterMetadata(ident=None, datatype=None, cols=None, rows=None, number_of_cells=None, nsres=None, ewres=None, min=None, max=None, semantic_label=None)[source]

Bases: grass.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

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

get_semantic_label()[source]

Get the semantic label identifier :return: None if not found

property semantic_label

Get the semantic label identifier :return: None if not found

set_semantic_label(semantic_label)[source]

Set the semantic label identifier

class grass.temporal.metadata.RasterMetadataBase(table=None, ident=None, datatype=None, cols=None, rows=None, number_of_cells=None, nsres=None, ewres=None, min=None, max=None)[source]

Bases: grass.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

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

property cols

Get number of cols :return: None if not found

property datatype

Get the map type :return: None if not found

property ewres

Get east-west resolution :return: None if not found

get_cols()[source]

Get number of cols :return: None if not found

get_datatype()[source]

Get the map type :return: None if not found

get_ewres()[source]

Get east-west resolution :return: None if not found

get_id()[source]

Convenient method to get the unique identifier (primary key) :return: None if not found

get_max()[source]

Get the maximum cell value :return: None if not found

get_min()[source]

Get the minimum cell value :return: None if not found

get_nsres()[source]

Get the north-south resolution :return: None if not found

get_number_of_cells()[source]

Get number of cells :return: None if not found

get_rows()[source]

Get number of rows :return: None if not found

property max

Get the maximum cell value :return: None if not found

property min

Get the minimum cell value :return: None if not found

property nsres

Get the north-south resolution :return: None if not found

property number_of_cells

Get number of cells :return: None if not found

property rows

Get number of rows :return: None if not found

set_cols(cols)[source]

Set the number of cols

set_datatype(datatype)[source]

Set the datatype

set_ewres(ewres)[source]

Set the east-west resolution

set_id(ident)[source]

Convenient method to set the unique identifier (primary key)

set_max(max)[source]

Set the maximum raster value

set_min(min)[source]

Set the minimum raster value

set_nsres(nsres)[source]

Set the north-south resolution

set_number_of_cells(number_of_cells)[source]

Set the number of cells

set_rows(rows)[source]

Set the number of rows

class grass.temporal.metadata.STDSMetadataBase(table=None, ident=None, title=None, description=None, command=None)[source]

Bases: grass.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

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

property description

Get description :return: None if not found

get_command()[source]

Get command :return: None if not found

get_description()[source]

Get description :return: None if not found

get_id()[source]

Convenient method to get the unique identifier (primary key) :return: None if not found

get_number_of_maps()[source]

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_title()[source]

Get the title :return: None if not found

property id

Convenient method to get the unique identifier (primary key) :return: None if not found

property number_of_maps

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

print_history()[source]

Print history information about this class in human readable shell style

print_info()[source]

Print information about this class in human readable style

print_shell_info()[source]

Print information about this class in shell style

set_command(command)[source]

Set the number of cols

set_description(description)[source]

Set the number of cols

set_id(ident)[source]

Convenient method to set the unique identifier (primary key)

set_title(title)[source]

Set the title

property title

Get the title :return: None if not found

class grass.temporal.metadata.STDSRasterMetadataBase(table=None, ident=None, title=None, description=None, aggregation_type=None)[source]

Bases: grass.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()
nsres_min=None
nsres_max=None
ewres_min=None
ewres_max=None
min_min=None
min_max=None
max_min=None
max_max=None
aggregation_type=None
number_of_maps=None

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

property aggregation_type

Get the aggregation type of the dataset (mean, min, max, …) :return: None if not found

property ewres_max

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

property ewres_min

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_aggregation_type()[source]

Get the aggregation type of the dataset (mean, min, max, …) :return: None if not found

get_ewres_max()[source]

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_ewres_min()[source]

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_max_max()[source]

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_max_min()[source]

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_min_max()[source]

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_min_min()[source]

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_nsres_max()[source]

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_nsres_min()[source]

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

property max_max

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

property max_min

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

property min_max

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

property min_min

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

property nsres_max

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

property nsres_min

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

set_aggregation_type(aggregation_type)[source]

Set the aggregation type of the dataset (mean, min, max, …)

class grass.temporal.metadata.STR3DSMetadata(ident=None, raster3d_register=None, title=None, description=None)[source]

Bases: grass.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()
raster3d_register=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
aggregation_type=None
number_of_maps=None

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

get_raster3d_register()[source]

Get the raster3d map register table name :return: None if not found

get_tbres_max()[source]

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_tbres_min()[source]

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

property raster3d_register

Get the raster3d map register table name :return: None if not found

set_raster3d_register(raster3d_register)[source]

Set the raster map register table name

property tbres_max

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

property tbres_min

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

class grass.temporal.metadata.STRDSMetadata(ident=None, raster_register=None, title=None, description=None)[source]

Bases: grass.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 semantic labels:.. None
 | Semantic labels:............ None
 | Number of registered maps:.. None
 |
 | Title:
 | Soils
 | Description:
 | Soils 1950 - 2010
 | Command history:
>>> meta.print_shell_info()
raster_register=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
aggregation_type=None
number_of_semantic_labels=None
semantic_labels=None
number_of_maps=None

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

get_number_of_semantic_labels()[source]

Get the number of registered semantic labels :return: None if not found

get_raster_register()[source]

Get the raster map register table name :return: None if not found

get_semantic_labels()[source]
Get the distinct semantic labels of registered maps

The distinct semantic labels are not stored in the metadata table and fetched on-the-fly

Returns

None if not found

property number_of_semantic_labels

Get the number of registered semantic labels :return: None if not found

property raster_register

Get the raster map register table name :return: None if not found

property semantic_labels
Get the distinct semantic labels of registered maps

The distinct semantic labels are not stored in the metadata table and fetched on-the-fly

Returns

None if not found

set_raster_register(raster_register)[source]

Set the raster map register table name

class grass.temporal.metadata.STVDSMetadata(ident=None, vector_register=None, title=None, description=None)[source]

Bases: grass.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()
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
number_of_maps=None

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

get_number_of_areas()[source]

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_number_of_boundaries()[source]

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_number_of_centroids()[source]

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_number_of_faces()[source]

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_number_of_holes()[source]

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_number_of_islands()[source]

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_number_of_kernels()[source]

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_number_of_lines()[source]

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_number_of_nodes()[source]

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_number_of_points()[source]

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_number_of_primitives()[source]

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_number_of_volumes()[source]

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_vector_register()[source]

Get the vector map register table name :return: None if not found

property number_of_areas

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

property number_of_boundaries

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

property number_of_centroids

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

property number_of_faces

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

property number_of_holes

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

property number_of_islands

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

property number_of_kernels

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

property number_of_lines

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

property number_of_nodes

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

property number_of_points

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

property number_of_primitives

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

property number_of_volumes

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

set_vector_register(vector_register)[source]

Set the vector map register table name

property vector_register

Get the vector map register table name :return: None if not found

class grass.temporal.metadata.VectorMetadata(ident=None, is_3d=False, 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)[source]

Bases: grass.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

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

get_3d_info()[source]

Return True if the map is three dimensional, False if not and None if not info was found

get_id()[source]

Convenient method to get the unique identifier (primary key) :return: None if not found

get_number_of_areas()[source]

Get the number of areas of the vector map :return: None if not found

get_number_of_boundaries()[source]

Get the number of boundaries of the vector map :return: None if not found

get_number_of_centroids()[source]

Get the number of centroids of the vector map :return: None if not found

get_number_of_faces()[source]

Get the number of faces of the vector map :return: None if not found

get_number_of_holes()[source]

Get the number of holes of the vector map :return: None if not found

get_number_of_islands()[source]

Get the number of islands of the vector map :return: None if not found

get_number_of_kernels()[source]

Get the number of kernels of the vector map :return: None if not found

get_number_of_lines()[source]

Get the number of lines of the vector map :return: None if not found

get_number_of_nodes()[source]

Get the number of nodes of the vector map :return: None if not found

get_number_of_points()[source]

Get the number of points of the vector map :return: None if not found

get_number_of_primitives()[source]

Get the number of primitives of the vector map :return: None if not found

get_number_of_volumes()[source]

Get the number of volumes of the vector map :return: None if not found

property id

Convenient method to get the unique identifier (primary key) :return: None if not found

property is_3d

Return True if the map is three dimensional, False if not and None if not info was found

property number_of_areas

Get the number of areas of the vector map :return: None if not found

property number_of_boundaries

Get the number of boundaries of the vector map :return: None if not found

property number_of_centroids

Get the number of centroids of the vector map :return: None if not found

property number_of_faces

Get the number of faces of the vector map :return: None if not found

property number_of_holes

Get the number of holes of the vector map :return: None if not found

property number_of_islands

Get the number of islands of the vector map :return: None if not found

property number_of_kernels

Get the number of kernels of the vector map :return: None if not found

property number_of_lines

Get the number of lines of the vector map :return: None if not found

property number_of_nodes

Get the number of nodes of the vector map :return: None if not found

property number_of_points

Get the number of points of the vector map :return: None if not found

property number_of_primitives

Get the number of primitives of the vector map :return: None if not found

property number_of_volumes

Get the number of volumes of the vector map :return: None if not found

set_3d_info(is_3d)[source]

Set True if the vector map is three dimensional

set_id(ident)[source]

Convenient method to set the unique identifier (primary key)

set_number_of_areas(number_of_areas)[source]

Set the number of areas of the vector map

set_number_of_boundaries(number_of_boundaries)[source]

Set the number of boundaries of the vector map

set_number_of_centroids(number_of_centroids)[source]

Set the number of centroids of the vector map

set_number_of_faces(number_of_faces)[source]

Set the number of faces of the vector map

set_number_of_holes(number_of_holes)[source]

Set the number of holes of the vector map

set_number_of_islands(number_of_islands)[source]

Set the number of islands of the vector map

set_number_of_kernels(number_of_kernels)[source]

Set the number of kernels of the vector map

set_number_of_lines(number_of_lines)[source]

Set the number of lines of the vector map

set_number_of_nodes(number_of_nodes)[source]

Set the number of nodes of the vector map

set_number_of_points(number_of_points)[source]

Set the number of points of the vector map

set_number_of_primitives(number_of_primitives)[source]

Set the number of primitives of the vector map

set_number_of_volumes(number_of_volumes)[source]

Set the number of volumes of the vector map

grass.temporal.open_stds module

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

grass.temporal.open_stds.check_new_map_dataset(name, layer=None, type='raster', overwrite=False, dbif=None)[source]
Check if a new map dataset of a specific type can be created in

the temporal database

Parameters
  • name – The name of the new map dataset

  • layer – The layer of the new map dataset

  • type – The type of the new map dataset (raster, vector, raster3d)

  • dbif – The temporal database interface to be used

  • overwrite – Flag to allow overwriting

Returns

A map dataset object

This function will raise a FatalError in case of an error.

grass.temporal.open_stds.check_new_stds(name, type, dbif=None, overwrite=False)[source]

Check if a new space time dataset of a specific type can be created

Parameters
  • name – The name of the new space time dataset

  • type – The type of the new space time dataset (strd, str3ds, stvds, raster, vector, raster3d)

  • dbif – The temporal database interface to be used

  • overwrite – Flag to allow overwriting

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.

grass.temporal.open_stds.open_new_map_dataset(name, layer=None, type='raster', temporal_extent=None, overwrite=False, dbif=None)[source]
Create a new map dataset object of a specific type that can be

registered in the temporal database

Parameters
  • name – The name of the new map dataset

  • layer – The layer of the new map dataset

  • type – The type of the new map dataset (raster, vector, raster3d)

  • dbif – The temporal database interface to be used

  • overwrite – Flag to allow overwriting

Returns

A map dataset object

grass.temporal.open_stds.open_new_stds(name, type, temporaltype, title, descr, semantic, dbif=None, overwrite=False)[source]

Create a new space time dataset of a specific type

Parameters
  • name – The name of the new space time dataset

  • type – The type of the new space time dataset (strd, str3ds, stvds, raster, vector, raster3d)

  • temporaltype – The temporal type (relative or absolute)

  • title – The title

  • descr – The dataset description

  • semantic – Semantical information

  • dbif – The temporal database interface to be used

  • overwrite – Flag to allow overwriting

Returns

The new created space time dataset

This function will raise a FatalError in case of an error.

grass.temporal.open_stds.open_old_stds(name, type, dbif=None)[source]

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
  • name – The name of the space time dataset, if the name does not contain the mapset (name@mapset) then the current mapset will be used to identifiy the space time dataset

  • type – The type of the space time dataset (strd, str3ds, stvds, raster, vector, raster3d)

  • dbif – The optional database interface to be used

Returns

New stds object

grass.temporal.register module

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

grass.temporal.register.assign_valid_time_to_map(ttype, map, start, end, unit, increment=None, mult=1, interval=False)[source]

Assign the valid time to a map dataset

Parameters
  • ttype – The temporal type which should be assigned and which the time format is of

  • map – A map dataset object derived from abstract_map_dataset

  • start – The start date and time of the first map (format absolute: “yyyy-mm-dd HH:MM:SS” or “yyyy-mm-dd”, format relative is integer 5)

  • end – The end date and time of the first map (format absolute: “yyyy-mm-dd HH:MM:SS” or “yyyy-mm-dd”, format relative is integer 5)

  • unit – The unit of the relative time: years, months, days, hours, minutes, seconds

  • increment – Time increment between maps for time stamp creation (format absolute: NNN seconds, minutes, hours, days, weeks, months, years; format relative is integer 1)

  • mult – A multiplier for the increment

  • interval – If True, time intervals are created in case the start time and an increment is provided

grass.temporal.register.register_map_object_list(type, map_list, output_stds, delete_empty=False, unit=None, dbif=None)[source]

Register a list of AbstractMapDataset objects in the temporal database and optional in a space time dataset.

Parameters
  • type – The type of the map layer (raster, raster_3d, vector)

  • map_list – List of AbstractMapDataset objects

  • output_stds – The output stds

  • delete_empty – Set True to delete empty map layer found in the map_list

  • unit – The temporal unit of the space time dataset

  • dbif – The database interface to be used

grass.temporal.register.register_maps_in_space_time_dataset(type, name, maps=None, file=None, start=None, end=None, unit=None, increment=None, dbif=None, interval=False, fs='|', update_cmd_list=True)[source]

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
  • type – The type of the maps raster, raster_3d or vector

  • name – The name of the space time dataset. Maps will be registered in the temporal database if the name was set to None

  • maps – A comma separated list of map names

  • file – Input file, one map per line map with start and optional end time, or the same as io object (with readline capability)

  • start – The start date and time of the first map (format absolute: “yyyy-mm-dd HH:MM:SS” or “yyyy-mm-dd”, format relative is integer 5)

  • end – The end date and time of the first map (format absolute: “yyyy-mm-dd HH:MM:SS” or “yyyy-mm-dd”, format relative is integer 5)

  • unit – The unit of the relative time: years, months, days, hours, minutes, seconds

  • increment – Time increment between maps for time stamp creation (format absolute: NNN seconds, minutes, hours, days, weeks, months, years; format relative: 1.0)

  • dbif – The database interface to be used

  • interval – If True, time intervals are created in case the start time and an increment is provided

  • fs – Field separator used in input file

  • update_cmd_list – If is True, the command that was invoking this process will be written to the process history

grass.temporal.sampling module

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

grass.temporal.sampling.sample_stds_by_stds_topology(intype, sampletype, inputs, sampler, header, separator, method, spatial=False, print_only=True)[source]

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

grass.temporal.space_time_datasets module

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

class grass.temporal.space_time_datasets.Raster3DDataset(ident)[source]

Bases: grass.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 gs
>>> init()
>>> gs.use_temp_region()
>>> gs.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
>>> gs.run_command("r3.mapcalc", overwrite=True, quiet=True,
...                expression="str3ds_map_test_case = 1")
0
>>> gs.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

>>> gs.run_command("r3.timestamp", map="str3ds_map_test_case",
...                date="2 years", quiet=True)
0
>>> r3map.read_timestamp_from_grass()
True
>>> r3map.get_temporal_extent_as_tuple()
(2, None)
>>> r3map.get_relative_time_unit()
'years'
>>> r3map.is_in_db()
False
>>> r3map.is_stds()
False

>>> 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
>>> gs.run_command("g.remove", flags="f", type="raster_3d", name=name, quiet=True)
0
>>> gs.del_temp_region()
get_new_instance(ident)[source]

Return a new instance with the type of this class

get_new_stds_instance(ident)[source]

Return a new space time dataset instance in which maps are stored with the type of this class

get_np_array()[source]

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.

get_type()[source]

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”

has_grass_timestamp()[source]

Check if a grass file bsased time stamp exists for this map.

Returns

True if success, False on error

is_stds()[source]

Return True if this class is a space time dataset

Returns

True if this class is a space time dataset, False otherwise

load()[source]

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 successful, False otherwise

map_exists()[source]

Return True in case the map exists in the grass spatial database

Returns

True if map exists, False otherwise

read_timestamp_from_grass()[source]

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_timestamp_from_grass()[source]

Remove the timestamp from the grass file system based spatial database

Returns

True if success, False on error

reset(ident)[source]

Reset the internal structure and set the identifier

spatial_disjoint_union(dataset)[source]

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

spatial_intersection(dataset)[source]

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

spatial_overlapping(dataset)[source]

Return True if the spatial extents overlap

spatial_relation(dataset)[source]

Return the two or three dimensional spatial relation

spatial_union(dataset)[source]

Return the three or two dimensional 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 or None

write_timestamp_to_grass()[source]

Write the timestamp of this map into the map metadata in the grass file system based spatial database.

Internally the libgis API functions are used for writing

return

True if success, False on error

class grass.temporal.space_time_datasets.RasterDataset(ident)[source]

Bases: grass.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 gs
>>> import grass.temporal as tgis
>>> init()
>>> gs.use_temp_region()
>>> gs.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
>>> gs.run_command("r.mapcalc", overwrite=True, quiet=True,
... expression="strds_map_test_case = 1")
0
>>> gs.run_command("r.timestamp", map="strds_map_test_case",
...                date="15 jan 1999", quiet=True)
0
>>> mapset = tgis.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

>>> gs.run_command("r.timestamp", map="strds_map_test_case",
...                date="2 years", quiet=True)
0
>>> rmap.read_timestamp_from_grass()
True
>>> rmap.get_temporal_extent_as_tuple()
(2, None)
>>> rmap.get_relative_time_unit()
'years'
>>> rmap.is_in_db()
False
>>> rmap.is_stds()
False

>>> 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

>>> gs.run_command("g.remove", flags="f", type="raster", name=name, quiet=True)
0
>>> gs.del_temp_region()
get_new_instance(ident)[source]

Return a new instance with the type of this class

get_new_stds_instance(ident)[source]

Return a new space time dataset instance in which maps are stored with the type of this class

get_np_array()[source]

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.

get_type()[source]

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”

has_grass_timestamp()[source]

Check if a grass file based time stamp exists for this map.

Returns

True if success, False on error

is_stds()[source]

Return True if this class is a space time dataset

Returns

True if this class is a space time dataset, False otherwise

load()[source]

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 successful, False otherwise

map_exists()[source]

Return True in case the map exists in the grass spatial database

Returns

True if map exists, False otherwise

read_semantic_label_from_grass()[source]

Read the semantic label of this map from the map metadata in the GRASS file system based spatial database and set the internal semantic label that should be insert/updated in the temporal database.

Returns

True if success, False if semantic labels could not be read (due to an error or because not being present)

read_timestamp_from_grass()[source]

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_timestamp_from_grass()[source]

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

reset(ident)[source]

Reset the internal structure and set the identifier

set_semantic_label(semantic_label)[source]

Set semantic label identifier

Metadata is updated in order to propagate semantic label into temporal DB.

File-based semantic label stored in GRASS data base.

Parameters

semantic_label (str) – semantic label (eg. S2_1)

spatial_disjoint_union(dataset)[source]

Return the two dimensional union as spatial_extent object.

Parameters

dataset – The abstract dataset to create a union with

Returns

The union spatial extent

spatial_intersection(dataset)[source]

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_overlapping(dataset)[source]

Return True if the spatial extents 2d overlap

spatial_relation(dataset)[source]

Return the two dimensional spatial relation

spatial_union(dataset)[source]

Return the two dimensional union as spatial_extent object or None in case the extents does not overlap or meet.

:param dataset :The abstract dataset to create a union with :return: The union spatial extent or None

write_semantic_label_to_grass()[source]

Write the semantic label of this map into the map metadata in the GRASS file system based spatial database.

Internally the libgis API functions are used for writing

Returns

True if success, False on error

write_timestamp_to_grass()[source]

Write the timestamp of this map into the map metadata in the grass file system based spatial database.

Internally the libgis API functions are used for writing

Returns

True if success, False on error

class grass.temporal.space_time_datasets.SpaceTimeRaster3DDataset(ident)[source]

Bases: grass.temporal.abstract_space_time_dataset.AbstractSpaceTimeDataset

Space time raster3d dataset class

>>> import grass.temporal as tgis
>>> tgis.init()
>>> mapset = tgis.get_current_mapset()
>>> str3ds = tgis.SpaceTimeRaster3DDataset("old@%s"%mapset)
>>> str3ds.is_in_db()
False
>>> str3ds.is_stds()
True
>>> str3ds.get_type()
'str3ds'
>>> newstrds = str3ds.get_new_instance("newstrds@%s"%mapset)
>>> isinstance(newstrds, SpaceTimeRaster3DDataset)
True
>>> newmap = str3ds.get_new_map_instance("newmap@%s"%mapset)
>>> isinstance(newmap, Raster3DDataset)
True
>>> str3ds.reset("new@%s"%mapset)
>>> str3ds.is_in_db()
False
>>> str3ds.reset(None)
>>> str3ds.is_in_db()
False
>>> str3ds.get_id()

get_map_register()[source]

Return the name of the map register table

get_new_instance(ident)[source]

Return a new instance with the type of this class

get_new_map_instance(ident)[source]

Return a new instance of a map dataset which is associated with the type of this class

get_type()[source]

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”

is_stds()[source]

Return True if this class is a space time dataset

Returns

True if this class is a space time dataset, False otherwise

reset(ident)[source]

Reset the internal structure and set the identifier

set_map_register(name)[source]

Set the name of the map register table

spatial_disjoint_union(dataset)[source]

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

spatial_intersection(dataset)[source]

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

spatial_overlapping(dataset)[source]

Return True if the spatial extents overlap

spatial_relation(dataset)[source]

Return the two or three dimensional spatial relation

spatial_union(dataset)[source]

Return the three or two dimensional 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 or None

class grass.temporal.space_time_datasets.SpaceTimeRasterDataset(ident)[source]

Bases: grass.temporal.abstract_space_time_dataset.AbstractSpaceTimeDataset

Space time raster dataset class

>>> import grass.temporal as tgis
>>> tgis.init()
>>> mapset = tgis.get_current_mapset()
>>> strds = tgis.SpaceTimeRasterDataset("old@%s"%mapset)
>>> strds.is_in_db()
False
>>> strds.is_stds()
True
>>> strds.get_type()
'strds'
>>> newstrds = strds.get_new_instance("newstrds@%s"%mapset)
>>> isinstance(newstrds, SpaceTimeRasterDataset)
True
>>> newmap = strds.get_new_map_instance("newmap@%s"%mapset)
>>> isinstance(newmap, RasterDataset)
True
>>> strds.reset("new@%s"%mapset)
>>> strds.is_in_db()
False
>>> strds.reset(None)
>>> strds.is_in_db()
False
>>> strds.get_id()

get_map_register()[source]

Return the name of the map register table

get_new_instance(ident)[source]

Return a new instance with the type of this class

get_new_map_instance(ident)[source]

Return a new instance of a map dataset which is associated ” “with the type of this class

get_type()[source]

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”

is_stds()[source]

Return True if this class is a space time dataset

Returns

True if this class is a space time dataset, False otherwise

reset(ident)[source]

Reset the internal structure and set the identifier

set_map_register(name)[source]

Set the name of the map register table

set_semantic_label(semantic_label)[source]

Set semantic label

Parameters

semantic_label (str) – semantic label (eg. S2_1)

spatial_disjoint_union(dataset)[source]

Return the two dimensional union as spatial_extent object.

Parameters

dataset – The abstract dataset to create a union with

Returns

The union spatial extent

spatial_intersection(dataset)[source]

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_overlapping(dataset)[source]

Return True if the spatial extents 2d overlap

spatial_relation(dataset)[source]

Return the two dimensional spatial relation

spatial_union(dataset)[source]

Return the two dimensional 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 or None

class grass.temporal.space_time_datasets.SpaceTimeVectorDataset(ident)[source]

Bases: grass.temporal.abstract_space_time_dataset.AbstractSpaceTimeDataset

Space time vector dataset class

>>> import grass.temporal as tgis
>>> tgis.init()
>>> mapset = tgis.get_current_mapset()
>>> stvds = tgis.SpaceTimeVectorDataset("old@%s"%mapset)
>>> stvds.is_in_db()
False
>>> stvds.is_stds()
True
>>> stvds.get_type()
'stvds'
>>> newstvds = stvds.get_new_instance("newstvds@%s"%mapset)
>>> isinstance(newstvds, SpaceTimeVectorDataset)
True
>>> newmap = stvds.get_new_map_instance("newmap@%s"%mapset)
>>> isinstance(newmap, VectorDataset)
True
>>> stvds.reset("new@%s"%mapset)
>>> stvds.is_in_db()
False
>>> stvds.reset(None)
>>> stvds.is_in_db()
False
>>> stvds.get_id()

get_map_register()[source]

Return the name of the map register table

get_new_instance(ident)[source]

Return a new instance with the type of this class

get_new_map_instance(ident)[source]

Return a new instance of a map dataset which is associated with the type of this class

get_type()[source]

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”

is_stds()[source]

Return True if this class is a space time dataset

Returns

True if this class is a space time dataset, False otherwise

reset(ident)[source]

Reset the internal structure and set the identifier

set_map_register(name)[source]

Set the name of the map register table

spatial_disjoint_union(dataset)[source]

Return the two dimensional union as spatial_extent object.

Parameters

dataset – The abstract dataset to create a union with

Returns

The union spatial extent

spatial_intersection(dataset)[source]

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_overlapping(dataset)[source]

Return True if the spatial extents 2d overlap

spatial_relation(dataset)[source]

Return the two dimensional spatial relation

spatial_union(dataset)[source]

Return the two dimensional 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 or None

class grass.temporal.space_time_datasets.VectorDataset(ident)[source]

Bases: grass.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 gs
>>> init()
>>> gs.use_temp_region()
>>> gs.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
>>> gs.run_command("v.random", overwrite=True, output="stvds_map_test_case",
... n=100, zmin=0, zmax=100, flags="z", column="elevation", quiet=True)
0
>>> gs.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

>>> gs.run_command("v.timestamp", map="stvds_map_test_case",
...                date="2 years", quiet=True)
0
>>> vmap.read_timestamp_from_grass()
True
>>> vmap.get_temporal_extent_as_tuple()
(2, None)
>>> vmap.get_relative_time_unit()
'years'
>>> vmap.is_in_db()
False
>>> vmap.is_stds()
False

>>> 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
>>> gs.run_command("g.remove", flags="f", type="vector", name=name, quiet=True)
0
>>> gs.del_temp_region()
get_layer()[source]

Return the layer

get_new_instance(ident)[source]

Return a new instance with the type of this class

get_new_stds_instance(ident)[source]

Return a new space time dataset instance in which maps are stored with the type of this class

get_type()[source]

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”

has_grass_timestamp()[source]

Check if a grass file bsased time stamp exists for this map.

is_stds()[source]

Return True if this class is a space time dataset

Returns

True if this class is a space time dataset, False otherwise

load()[source]

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 successful, False otherwise

map_exists()[source]

Return True in case the map exists in the grass spatial database

Returns

True if map exists, False otherwise

read_timestamp_from_grass()[source]

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_timestamp_from_grass()[source]

Remove the timestamp from the grass file system based spatial database

Internally the libgis API functions are used for removal

reset(ident)[source]

Reset the internal structure and set the identifier

spatial_disjoint_union(dataset)[source]

Return the two dimensional union as spatial_extent object.

Parameters

dataset – The abstract dataset to create a union with

Returns

The union spatial extent

spatial_intersection(dataset)[source]

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_overlapping(dataset)[source]

Return True if the spatial extents 2d overlap

spatial_relation(dataset)[source]

Return the two dimensional spatial relation

spatial_union(dataset)[source]

Return the two dimensional 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 or None

write_timestamp_to_grass()[source]

Write the timestamp of this map into the map metadata in the grass file system based spatial database.

Internally the libgis API functions are used for writing

grass.temporal.spatial_extent module

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

class grass.temporal.spatial_extent.Raster3DSpatialExtent(ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None)[source]

Bases: grass.temporal.spatial_extent.SpatialExtent

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

class grass.temporal.spatial_extent.RasterSpatialExtent(ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None)[source]

Bases: grass.temporal.spatial_extent.SpatialExtent

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

class grass.temporal.spatial_extent.STR3DSSpatialExtent(ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None)[source]

Bases: grass.temporal.spatial_extent.SpatialExtent

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

class grass.temporal.spatial_extent.STRDSSpatialExtent(ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None)[source]

Bases: grass.temporal.spatial_extent.SpatialExtent

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

class grass.temporal.spatial_extent.STVDSSpatialExtent(ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None)[source]

Bases: grass.temporal.spatial_extent.SpatialExtent

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

class grass.temporal.spatial_extent.SpatialExtent(table=None, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None, proj='XY')[source]

Bases: grass.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

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

property bottom

Get the bottom edge of the map :return: None if not found

contain(extent)[source]

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

contain_2d(extent)[source]

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

cover(extent)[source]

Return True if this extent covers the provided spatial extent in three dimensions.

The following cases are excluded:

  • contain

  • in

  • equivalent

Parameters

extent – The spatial extent

Returns

True or False

cover_2d(extent)[source]

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:

  • contain

  • in

  • equivalent

Parameters

extent – The spatial extent

Returns

True or False

covered(extent)[source]

Return True if this extent is covered by the provided spatial extent in three dimensions.

The following cases are excluded:

  • contain

  • in

  • equivalent

Parameters

extent – The spatial extent

Returns

True or False

covered_2d(extent)[source]

Return True if this extent is covered by the provided spatial extent in two dimensions.

The following cases are excluded:

  • contain

  • in

  • equivalent

Parameters

extent – The spatial extent

Returns

True or False

disjoint(extent)[source]

Return True if this extent is disjoint with the provided spatial extent in three dimensions.

Parameters

extent – The spatial extent

Returns

True or False

disjoint_2d(extent)[source]

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

disjoint_union(extent)[source]

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
disjoint_union_2d(extent)[source]

Return the two dimensional union as spatial_extent.

Parameters

extent – The spatial extent to create a union with

Returns

The union spatial extent

property east

Get the eastern edge of the map :return: None if not found

equivalent(extent)[source]

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

equivalent_2d(extent)[source]

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

get_area()[source]

Compute the area of the extent, extent in z direction is ignored

get_bottom()[source]

Get the bottom edge of the map :return: None if not found

get_east()[source]

Get the eastern edge of the map :return: None if not found

get_id()[source]

Convenient method to get the unique identifier (primary key) :return: None if not found

get_north()[source]

Get the northern edge of the map :return: None if not found

get_projection()[source]

Get the projection of the spatial extent

get_south()[source]

Get the southern edge of the map :return: None if not found

get_spatial_extent_as_tuple()[source]

Return a tuple (north, south, east, west, top, bottom) of the spatial extent

get_spatial_extent_as_tuple_2d()[source]

Return a tuple (north, south, east, west,) of the 2d spatial extent

get_top()[source]

Get the top edge of the map :return: None if not found

get_volume()[source]

Compute the volume of the extent, in case z is zero (top == bottom or top - bottom = 1) the area is returned

get_west()[source]

Get the western edge of the map :return: None if not found

property id

Convenient method to get the unique identifier (primary key) :return: None if not found

intersect(extent)[source]

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
intersect_2d(extent)[source]
Return the two dimensional intersection as spatial_extent

object or None in case no intersection was found.

Parameters

extent – The spatial extent to intersect with

Returns

The intersection spatial extent

is_in(extent)[source]

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

is_in_2d(extent)[source]

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

meet(extent)[source]

Return True if this extent meets with the provided spatial extent in three dimensions.

Parameters

extent – The spatial extent

Returns

True or False

meet_2d(extent)[source]

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

property north

Get the northern edge of the map :return: None if not found

overlap(extent)[source]

Return True if this extent overlaps with the provided spatial extent in three dimensions.

The following cases are excluded:

  • contain

  • in

  • cover

  • covered

  • equivalent

Parameters

extent – The spatial extent

Returns

True or False

overlap_2d(extent)[source]

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:

  • contain

  • in

  • cover

  • covered

  • equivalent

Parameters

extent – The spatial extent

Returns

True or False

overlapping(extent)[source]

Return True if this (A) and the provided spatial extent (B) overlaps in three dimensional space.

Overlapping includes the spatial relations:

  • contain

  • in

  • cover

  • covered

  • equivalent

Usage:

>>> 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

overlapping_2d(extent)[source]

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:

  • contain

  • in

  • cover

  • covered

  • equivalent

>>> 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

print_info()[source]

Print information about this class in human readable style

print_shell_info()[source]

Print information about this class in shell style

set_bottom(bottom)[source]

Set the bottom edge of the map

set_east(east)[source]

Set the eastern edge of the map

set_id(ident)[source]

Convenient method to set the unique identifier (primary key)

set_north(north)[source]

Set the northern edge of the map

set_projection(proj)[source]

Set the projection of the spatial extent it should be XY or LL. As default the projection is XY

set_south(south)[source]

Set the southern edge of the map

set_spatial_extent(spatial_extent)[source]

Set the three dimensional spatial extent

Parameters

spatial_extent – An object of type SpatialExtent or its subclasses

set_spatial_extent_2d(spatial_extent)[source]

Set the three dimensional spatial extent

Parameters

spatial_extent – An object of type SpatialExtent or its subclasses

set_spatial_extent_from_values(north, south, east, west, top, bottom)[source]

Set the three dimensional spatial extent

Parameters
  • north – The northern edge

  • south – The southern edge

  • east – The eastern edge

  • west – The western edge

  • top – The top edge

  • bottom – The bottom edge

set_spatial_extent_from_values_2d(north, south, east, west)[source]

Set the two dimensional spatial extent from values

Parameters
  • north – The northern edge

  • south – The southern edge

  • east – The eastern edge

  • west – The western edge

set_top(top)[source]

Set the top edge of the map

set_west(west)[source]

Set the western edge of the map

property south

Get the southern edge of the map :return: None if not found

spatial_relation(extent)[source]

Returns the two dimensional spatial relation between this extent and the provided spatial extent in three dimensions.

Spatial relations are:

  • disjoint

  • meet

  • overlap

  • cover

  • covered

  • in

  • contain

  • equivalent

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'
spatial_relation_2d(extent)[source]

Returns the two dimensional spatial relation between this extent and the provided spatial extent in two dimensions.

Spatial relations are:

  • disjoint

  • meet

  • overlap

  • cover

  • covered

  • in

  • contain

  • equivalent

Usage: see self.spatial_relation()

property top

Get the top edge of the map :return: None if not found

union(extent)[source]
Return the three dimensional union as spatial_extent

object or None in case the extents does not overlap or meet.

Parameters

extent – The spatial extent to create a union with

Returns

The union spatial extent

union_2d(extent)[source]
Return the two dimensional union as spatial_extent

object or None in case the extents does not overlap or meet.

Parameters

extent – The spatial extent to create a union with

Returns

The union spatial extent

property west

Get the western edge of the map :return: None if not found

class grass.temporal.spatial_extent.VectorSpatialExtent(ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None)[source]

Bases: grass.temporal.spatial_extent.SpatialExtent

Constructor of this class

Parameters
  • table – The name of the table

  • ident – The identifier (primary key) of this object in the database table

grass.temporal.spatial_topology_dataset_connector module

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

class grass.temporal.spatial_topology_dataset_connector.SpatialTopologyDatasetConnector[source]

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:

  • equivalent

  • overlap

  • in

  • contain

  • meet

  • cover

  • covered

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_contain(map)[source]

Append a map that this map spatially contains

Parameters

map – This object should be of type AbstractMapDataset or derived classes

append_cover(map)[source]

Append a map that spatially cover this map

Parameters

map – This object should be of type AbstractMapDataset or derived classes

append_covered(map)[source]

Append a map that is spatially covered by this map

Parameters

map – This object should be of type AbstractMapDataset or derived classes

append_equivalent(map)[source]

Append a map with equivalent spatial extent as this map

Parameters

map – This object should be of type AbstractMapDataset or derived classes

append_in(map)[source]

Append a map that this is spatial in this map

Parameters

map – This object should be of type AbstractMapDataset or derived classes

append_meet(map)[source]

Append a map that spatially meet with this map

Parameters

map – This object should be of type AbstractMapDataset or derived classes

append_overlap(map)[source]

Append a map that this spatial overlap with this map

Parameters

map – This object should be of type AbstractMapDataset or derived classes

property contain

Return a list of map objects that this map contains

Returns

A list of map objects or None

property cover

Return a list of map objects that spatially cover this map

Returns

A list of map objects or None

property covered

Return a list of map objects that are spatially covered by this map

Returns

A list of map objects or None

property equivalent

Return a list of map objects with equivalent spatial extent as this map

Returns

A list of map objects or None

get_contain()[source]

Return a list of map objects that this map contains

Returns

A list of map objects or None

get_cover()[source]

Return a list of map objects that spatially cover this map

Returns

A list of map objects or None

get_covered()[source]

Return a list of map objects that are spatially covered by this map

Returns

A list of map objects or None

get_equivalent()[source]

Return a list of map objects with equivalent spatial extent as this map

Returns

A list of map objects or None

get_in()[source]

Return a list of map objects that are spatial in this map

Returns

A list of map objects or None

get_meet()[source]

Return a list of map objects that spatially meet with this map

Returns

A list of map objects or None

get_number_of_spatial_relations()[source]

Return a dictionary in which the keys are the relation names and the value are the number of relations.

The following relations are available:

  • equivalent

  • overlap

  • in

  • contain

  • meet

  • cover

  • covered

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

get_overlap()[source]

Return a list of map objects that this map spatial overlap with

Returns

A list of map objects or None

get_spatial_relations()[source]

Return the dictionary of spatial relationships

Keys are the spatial relationships in upper case, values are abstract map objects.

Returns

The spatial relations dictionary

property in_

Return a list of map objects that are spatial in this map

Returns

A list of map objects or None

is_spatial_topology_build()[source]

Check if the temporal topology was build

property meet

Return a list of map objects that spatially meet with this map

Returns

A list of map objects or None

property overlap

Return a list of map objects that this map spatial overlap with

Returns

A list of map objects or None

print_spatial_topology_info()[source]

Print information about this class in human readable style

print_spatial_topology_shell_info()[source]

Print information about this class in shell style

reset_spatial_topology()[source]

Reset any information about temporal topology

set_spatial_topology_build_false()[source]

Same as name

set_spatial_topology_build_true()[source]

Same as name

grass.temporal.spatio_temporal_relationships module

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

class grass.temporal.spatio_temporal_relationships.SpatioTemporalTopologyBuilder[source]

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, connection_state_changed = 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: