[GRASS-SVN] r58915 - grass/trunk/lib/python/temporal
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 6 16:14:24 PST 2014
Author: huhabla
Date: 2014-02-06 16:14:24 -0800 (Thu, 06 Feb 2014)
New Revision: 58915
Modified:
grass/trunk/lib/python/temporal/pythontemporallib.dox
grass/trunk/lib/python/temporal/temporal_vector_algebra.py
Log:
Do not create PyGRASS module instances at import time.
Modified: grass/trunk/lib/python/temporal/pythontemporallib.dox
===================================================================
--- grass/trunk/lib/python/temporal/pythontemporallib.dox 2014-02-06 22:45:32 UTC (rev 58914)
+++ grass/trunk/lib/python/temporal/pythontemporallib.dox 2014-02-07 00:14:24 UTC (rev 58915)
@@ -72,7 +72,6 @@
space time datasets are defined here:
- python::temporal::aggregation
-- python::temporal::create
- python::temporal::extract
- python::temporal::factory
- python::temporal::open_stds
Modified: grass/trunk/lib/python/temporal/temporal_vector_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_vector_algebra.py 2014-02-06 22:45:32 UTC (rev 58914)
+++ grass/trunk/lib/python/temporal/temporal_vector_algebra.py 2014-02-07 00:14:24 UTC (rev 58915)
@@ -433,12 +433,6 @@
from temporal_vector_operator import *
from temporal_algebra import *
-m_overlay = pygrass.Module('v.overlay', quiet=True, run_=False)
-m_rename = pygrass.Module('g.rename', quiet=True, run_=False)
-m_patch = pygrass.Module('v.patch', quiet=True, run_=False)
-m_mremove = pygrass.Module('g.mremove', quiet=True, run_=False)
-m_buffer = pygrass.Module('v.buffer', quiet=True, run_=False)
-
##############################################################################
class TemporalVectorAlgebraLexer(TemporalAlgebraLexer):
@@ -493,25 +487,7 @@
# Get the tokens from the lexer class
tokens = TemporalVectorAlgebraLexer.tokens
-
- def remove_intermediate_vector_maps(self):
- """! Removes the intermediate vector maps.
- """
- if self.names != {}:
- namelist = self.names.values()
- max = 100
- chunklist = [namelist[i:i + max] for i in range(0, len(namelist), max)]
- for chunk in chunklist:
- stringlist = ",".join(chunk)
- if self.debug:
- print "g.mremove vect=%s"%(stringlist)
- if self.run:
- m = copy.deepcopy(m_mremove)
- m.inputs["vect"].value = stringlist
- m.flags["f"].value = True
- m.run()
-
# Setting equal precedence level for select and hash operations.
precedence = (
('left', 'T_SELECT_OPERATOR', 'T_SELECT', 'T_NOT_SELECT'), # 1
@@ -522,6 +498,12 @@
def __init__(self, pid=None, run=False, debug=True, spatial = False):
TemporalAlgebraParser.__init__(self, pid, run, debug, spatial)
+ self.m_overlay = pygrass.Module('v.overlay', quiet=True, run_=False)
+ self.m_rename = pygrass.Module('g.rename', quiet=True, run_=False)
+ self.m_patch = pygrass.Module('v.patch', quiet=True, run_=False)
+ self.m_mremove = pygrass.Module('g.mremove', quiet=True, run_=False)
+ self.m_buffer = pygrass.Module('v.buffer', quiet=True, run_=False)
+
def parse(self, expression, stdstype = 'strds', basename = None):
self.lexer = TemporalVectorAlgebraLexer()
self.lexer.build()
@@ -533,9 +515,26 @@
self.expression = expression
self.parser.parse(expression)
-
######################### Temporal functions ##############################
+ def remove_intermediate_vector_maps(self):
+ """! Removes the intermediate vector maps.
+ """
+ if self.names != {}:
+ namelist = self.names.values()
+ max = 100
+ chunklist = [namelist[i:i + max] for i in range(0, len(namelist), max)]
+ for chunk in chunklist:
+ stringlist = ",".join(chunk)
+ if self.debug:
+ print "g.mremove vect=%s"%(stringlist)
+
+ if self.run:
+ m = copy.deepcopy(self.m_mremove)
+ m.inputs["vect"].value = stringlist
+ m.flags["f"].value = True
+ m.run()
+
def eval_toperator(self, operator, comparison = False):
"""!This function evaluates a string containing temporal operations.
@@ -740,7 +739,7 @@
mapset = map_i.get_mapset()
# Change map name to given basename.
newident = self.basename + "_" + str(count)
- m = copy.deepcopy(m_rename)
+ m = copy.deepcopy(self.m_rename)
m.inputs["vect"].value = (map_i.get_name(),newident)
m.flags["overwrite"].value = grass.overwrite()
m.run()
@@ -751,16 +750,15 @@
register_list.append(map_i)
else:
register_list.append(map_i)
-
+
if len(register_list) > 0:
# Open connection to temporal database.
dbif, connected = init_dbif(dbif=self.dbif)
# Create result space time dataset.
resultstds = open_new_space_time_dataset(t[1], self.stdstype, \
'absolute', t[1], t[1], \
- None, None, \
- overwrite = grass.overwrite(),
- dbif=dbif)
+ "temporal vector algebra", dbif=dbif,
+ overwrite = grass.overwrite())
for map_i in register_list:
# Check if modules should be executed from command list.
if "cmd_list" in dir(map_i):
@@ -850,7 +848,7 @@
def create_overlay_operations(self, maplistA, maplistB, relations, temporal, function):
"""!Create the spatial overlay operation commad list
-
+
@param maplistA A list of map objects
@param maplistB A list of map objects
@param relations The temporal relationships that must be fullfilled as list of strings
@@ -860,7 +858,7 @@
@return Return the list of maps with overlay commands
"""
topolist = self.get_temporal_topo_list(maplistA, maplistB, topolist = relations)
-
+
# Select operation name.
if function == "&":
opname = "and"
@@ -911,7 +909,7 @@
mapbinput = map_j.get_id()
# Create module command in PyGRASS for v.overlay and v.patch.
if opname != "disor":
- m = copy.deepcopy(m_overlay)
+ m = copy.deepcopy(self.m_overlay)
m.run_ = False
m.inputs["operator"].value = opname
m.inputs["ainput"].value = str(mapainput)
@@ -920,7 +918,7 @@
m.flags["overwrite"].value = grass.overwrite()
else:
patchinput = str(mapainput) + ',' + str(mapbinput)
- m = copy.deepcopy(m_patch)
+ m = copy.deepcopy(self.m_patch)
m.run_ = False
m.inputs["input"].value = patchinput
m.outputs["output"].value = name
@@ -973,7 +971,7 @@
buff_type = "line"
elif t[1] == "buff_a":
buff_type = "area"
- m = copy.deepcopy(m_buffer)
+ m = copy.deepcopy(self.m_buffer)
m.run_ = False
m.inputs["type"].value = buff_type
m.inputs["input"].value = str(map_i.get_id())
More information about the grass-commit
mailing list