|
@@ -76,26 +76,17 @@ def open_old_space_time_dataset(name, type, dbif=None):
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
-def open_new_space_time_dataset(name, type, temporaltype, title, descr, semantic,
|
|
|
- dbif=None, overwrite=False, dry=False):
|
|
|
- """!Create a new space time dataset of a specific type
|
|
|
-
|
|
|
- This function is sensitive to the settings in grass.core.overwrite to
|
|
|
- overwrite existing space time datasets.
|
|
|
+def check_new_space_time_dataset(name, type, dbif=None, overwrite=False):
|
|
|
+ """!Check if a new space time dataset of a specific type can be created
|
|
|
|
|
|
@param name The name of the new space time dataset
|
|
|
@param type The type of the new space time dataset (strd, str3ds, stvds,
|
|
|
raster, vector, raster3d)
|
|
|
- @param temporaltype The temporal type (relative or absolute)
|
|
|
- @param title The title
|
|
|
- @param descr The dataset description
|
|
|
- @param semantic Semantical information
|
|
|
@param dbif The temporal database interface to be used
|
|
|
@param overwrite Flag to allow overwriting
|
|
|
- @param dry Do not create the space time dataset in the temporal database,
|
|
|
- make a dry run with including all checks
|
|
|
|
|
|
- @return The new created space time dataset
|
|
|
+ @return A space time dataset object that must be filled with
|
|
|
+ content before insertion in the temporal database
|
|
|
|
|
|
This function will raise a ScriptError in case of an error.
|
|
|
"""
|
|
@@ -120,26 +111,53 @@ def open_new_space_time_dataset(name, type, temporaltype, title, descr, semantic
|
|
|
elif type == "stvds" or type == "vect" or type == "vector":
|
|
|
sp = dataset_factory("stvds", id)
|
|
|
else:
|
|
|
- core.fatal(_("Unkown type: %s") % (type))
|
|
|
+ core.error(_("Unkown type: %s") % (type))
|
|
|
+ return None
|
|
|
|
|
|
dbif, connected = init_dbif(dbif)
|
|
|
|
|
|
if sp.is_in_db(dbif) and overwrite is False:
|
|
|
- if connected:
|
|
|
- dbif.close()
|
|
|
core.fatal(_("Space time %(sp)s dataset <%(name)s> is already in the"
|
|
|
" database. Use the overwrite flag.") % {
|
|
|
'sp': sp.get_new_map_instance(None).get_type(),
|
|
|
'name': name})
|
|
|
- return None
|
|
|
+ if connected:
|
|
|
+ dbif.close()
|
|
|
+
|
|
|
+ return sp
|
|
|
+
|
|
|
+###############################################################################
|
|
|
|
|
|
- if sp.is_in_db(dbif) and overwrite is True:
|
|
|
+def open_new_space_time_dataset(name, type, temporaltype, title, descr, semantic,
|
|
|
+ dbif=None, overwrite=False):
|
|
|
+ """!Create a new space time dataset of a specific type
|
|
|
+
|
|
|
+ @param name The name of the new space time dataset
|
|
|
+ @param type The type of the new space time dataset (strd, str3ds, stvds,
|
|
|
+ raster, vector, raster3d)
|
|
|
+ @param temporaltype The temporal type (relative or absolute)
|
|
|
+ @param title The title
|
|
|
+ @param descr The dataset description
|
|
|
+ @param semantic Semantical information
|
|
|
+ @param dbif The temporal database interface to be used
|
|
|
+ @param overwrite Flag to allow overwriting
|
|
|
+ @param dry Do not create the space time dataset in the temporal database,
|
|
|
+ make a dry run with including all checks
|
|
|
+
|
|
|
+ @return The new created space time dataset
|
|
|
+
|
|
|
+ This function will raise a ScriptError in case of an error.
|
|
|
+ """
|
|
|
+ dbif, connected = init_dbif(dbif)
|
|
|
+ sp = check_new_space_time_dataset(name, type, dbif, overwrite)
|
|
|
+
|
|
|
+ if sp.is_in_db(dbif):
|
|
|
core.warning(_("Overwrite space time %(sp)s dataset <%(name)s> and "
|
|
|
"unregister all maps.") % {
|
|
|
'sp': sp.get_new_map_instance(None).get_type(),
|
|
|
'name': name})
|
|
|
- if not dry:
|
|
|
- sp.delete(dbif)
|
|
|
+ id = sp.get_id()
|
|
|
+ sp.delete(dbif)
|
|
|
sp = sp.get_new_instance(id)
|
|
|
|
|
|
core.verbose(_("Create new space time %s dataset.") %
|
|
@@ -147,10 +165,94 @@ def open_new_space_time_dataset(name, type, temporaltype, title, descr, semantic
|
|
|
|
|
|
sp.set_initial_values(temporal_type=temporaltype, semantic_type=semantic,
|
|
|
title=title, description=descr)
|
|
|
- if not dry:
|
|
|
- sp.insert(dbif)
|
|
|
+
|
|
|
+ sp.insert(dbif)
|
|
|
|
|
|
if connected:
|
|
|
dbif.close()
|
|
|
|
|
|
return sp
|
|
|
+
|
|
|
+############################################################################
|
|
|
+
|
|
|
+def check_new_map_dataset(name, layer=None, mapset=None,
|
|
|
+ type="raster", overwrite=False, dbif=None):
|
|
|
+ """!Check if a new map dataset of a specific type can be created in
|
|
|
+ the temporal database
|
|
|
+
|
|
|
+ @param name The name of the new map dataset
|
|
|
+ @param layer The layer of the new map dataset
|
|
|
+ @param mapset The current mapset the new map dataset is created in,
|
|
|
+ this argument is optional, if not provided g.gisenv
|
|
|
+ will be called to reveive the current mapset
|
|
|
+ @param type The type of the new map dataset (raster, vector, raster3d)
|
|
|
+ @param dbif The temporal database interface to be used
|
|
|
+ @param overwrite Flag to allow overwriting
|
|
|
+
|
|
|
+ @return A map dataset object
|
|
|
+
|
|
|
+ This function will raise a ScriptError in case of an error.
|
|
|
+ """
|
|
|
+ if not mapset:
|
|
|
+ mapset = core.gisenv()["MAPSET"]
|
|
|
+
|
|
|
+ dbif, connected = init_dbif(dbif)
|
|
|
+ map_id = AbstractMapDataset.build_id(name, mapset, layer)
|
|
|
+
|
|
|
+ new_map = dataset_factory(type, map_id)
|
|
|
+ # Check if new map is in the temporal database
|
|
|
+ if new_map.is_in_db(dbif):
|
|
|
+ if not overwrite:
|
|
|
+ if connected:
|
|
|
+ dbif.close()
|
|
|
+ core.fatal(_("Map <%s> is already in temporal database,"
|
|
|
+ " use overwrite flag to overwrite") % (map_id))
|
|
|
+
|
|
|
+ if connected:
|
|
|
+ dbif.close()
|
|
|
+
|
|
|
+ return new_map
|
|
|
+
|
|
|
+############################################################################
|
|
|
+
|
|
|
+def open_new_map_dataset(name, layer=None, mapset=None, type="raster",
|
|
|
+ temporal_extent=None, overwrite=False,
|
|
|
+ dbif=None):
|
|
|
+ """!Create a new map dataset object of a specific type that can be
|
|
|
+ registered in the temporal database
|
|
|
+
|
|
|
+ @param name The name of the new map dataset
|
|
|
+ @param layer The layer of the new map dataset
|
|
|
+ @param mapset The current mapset the new map dataset is created in,
|
|
|
+ this argument is optional, if not provided g.gisenv
|
|
|
+ will be called to reveive the current mapset
|
|
|
+ @param type The type of the new map dataset (raster, vector, raster3d)
|
|
|
+ @param dbif The temporal database interface to be used
|
|
|
+ @param overwrite Flag to allow overwriting
|
|
|
+
|
|
|
+ @return A map dataset object
|
|
|
+
|
|
|
+ This function will raise a ScriptError in case of an error.
|
|
|
+ """
|
|
|
+
|
|
|
+ if not mapset:
|
|
|
+ mapset = core.gisenv()["MAPSET"]
|
|
|
+
|
|
|
+ dbif, connected = init_dbif(dbif)
|
|
|
+ new_map = check_new_map_dataset(name, layer, mapset, "raster",
|
|
|
+ overwrite, dbif)
|
|
|
+
|
|
|
+ # Check if new map is in the temporal database
|
|
|
+ if new_map.is_in_db(dbif):
|
|
|
+ # Remove the existing temporal database entry
|
|
|
+ map_id = new_map.get_id()
|
|
|
+ new_map.delete(dbif)
|
|
|
+ new_map = new_map.get_new_instance(map_id)
|
|
|
+
|
|
|
+ if temporal_extent:
|
|
|
+ new_map.set_temporal_extent(temporal_extent)
|
|
|
+
|
|
|
+ if connected:
|
|
|
+ dbif.close()
|
|
|
+
|
|
|
+ return new_map
|