Ejemplo n.º 1
0
 def __init__(self, value, time=None):
     if time is None:
         # Constructor with a single argument of type string
         if isinstance(value, str):
             couple = parse_temporalinst(value, 0)
             value = couple[2][0]
             time = couple[2][1]
         # Constructor with a single argument of type tuple or list
         elif isinstance(value, (tuple, list)):
             value, time = value
         else:
             raise Exception(
                 "ERROR: Could not parse temporal instant value")
     # Now both value and time are not None
     assert (isinstance(value,
                        (str, bool))), "ERROR: Invalid value argument"
     assert (isinstance(time,
                        (str, datetime))), "ERROR: Invalid time argument"
     if isinstance(value, str):
         if value.lower() == 'true' or value.lower() == 't':
             self._value = True
         elif value.lower() == 'false' or value.lower() == 'f':
             self._value = False
         else:
             raise Exception(
                 "ERROR: Could not parse temporal instant value")
     else:
         self._value = value
     self._time = parse(time) if isinstance(time, str) else time
Ejemplo n.º 2
0
 def __init__(self, value, time=None, srid=None):
     if time is None:
         # Constructor with a single argument of type string
         if isinstance(value, str):
             # If srid is given
             if re.match(r'^(SRID|srid)\s*=\s*\d+\s*(;|,)\s*', value):
                 #Get the srid and remove the "srid=xxx;" prefix
                 srid_str = int(re.search(r'(\d+)', value).group())
                 if srid is not None and srid_str != srid:
                     raise Exception(f"ERROR: SRID mismatch: {srid_str} vs {srid}")
                 srid = srid_str
                 value = re.sub(r'^(SRID|srid)\s*=\s*\d+\s*(;|,)\s*', '', value)
             else:
                 if srid is None:
                     srid = 0
             #Parse without the eventual "srid=xxx;" prefix
             couple = parse_temporalinst(value, 0)
             value = couple[2][0]
             time = couple[2][1]
         # Constructor with a single argument of type tuple or list
         elif isinstance(value, (tuple, list)):
             value, time, *extra = value
             if extra:
                 srid, *extra = extra
             else:
                 srid = 0
         else:
             raise Exception("ERROR: Could not parse temporal instant value")
     if srid is None:
         srid = 0
     # Now value, time, and srid are not None
     assert(isinstance(value, (str, Point))), "ERROR: Invalid value argument"
     assert(isinstance(time, (str, datetime))), "ERROR: Invalid time argument"
     assert(isinstance(srid, (str, int))), "ERROR: Invalid SRID"
     if isinstance(value, str):
         if '(' in value and ')' in value:
             idx1 = value.find('(')
             idx2 = value.find(')')
             coords = (value[idx1 + 1:idx2]).split(' ')
             self._value = Point(coords, srid=srid)
         else:
             self._value = Geometry.from_ewkb(value)
     else:
         self._value = value
     self._time = parse(time) if isinstance(time, str) else time
     # Verify validity of the resulting instance
     self._valid()
Ejemplo n.º 3
0
 def __init__(self, value, time=None):
     if (time is None):
         # Constructor with a single argument of type string
         if isinstance(value, str):
             couple = parse_temporalinst(value, 0)
             value = couple[2][0]
             time = couple[2][1]
         # Constructor with a single argument of type tuple or list
         elif isinstance(value, (tuple, list)):
             value, time = value
         else:
             raise Exception(
                 "ERROR: Could not parse temporal instant value")
     # Now both value and time are not None
     assert (isinstance(
         value, (str, self.BaseClass))), "ERROR: Invalid value argument"
     assert (isinstance(time,
                        (str, datetime))), "ERROR: Invalid time argument"
     self._value = self.BaseClass(value) if isinstance(value,
                                                       str) else value
     self._time = parse(time) if isinstance(time, str) else time
Ejemplo n.º 4
0
 def __init__(self, value, time=None):
     if (time is None):
         # Constructor with a single argument of type string
         if (isinstance(value, str)):
             couple = parse_temporalinst(value, 0)
             value = couple[2][0]
             time = couple[2][1]
         # Constructor with a single argument of type tuple or list
         elif (isinstance(value, (tuple, list))):
             value, time = value
         else:
             raise Exception(
                 "ERROR: Could not parse temporal instant value")
     # Now both value and time are not None
     assert (isinstance(value, str)), "ERROR: Invalid value argument"
     assert (isinstance(time,
                        (str, datetime))), "ERROR: Invalid time argument"
     # Remove double quotes if present
     if value[0] == '"' and value[-1] == '"':
         value = value[1:-1]
     self._value = value
     self._time = parse(time) if isinstance(time, str) else time