Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymeos/pymeos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
MeosGeoJsonInputError, \
MeosGeoJsonOutputError

__version__ = '1.1.3b1'
__version__ = '1.1.3b2'
__all__ = [
# initialization
'pymeos_initialize', 'pymeos_finalize',
Expand Down
121 changes: 20 additions & 101 deletions pymeos/pymeos/factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from enum import Enum
from pymeos_cffi import MeosType, MeosTemporalSubtype

from .main import TBoolInst, TBoolSeq, TBoolSeqSet, \
TIntInst, TIntSeq, TIntSeqSet, \
Expand All @@ -8,117 +8,36 @@
TGeogPointInst, TGeogPointSeq, TGeogPointSeqSet


class TempType(Enum):
"""
Enum for representing the different base/temporal types present in MEOS.

This class is used internally by PyMEOS classes and there shouldn't be any need to be used outside of them.
"""
BOOL = 1
FLOAT = 2
INT = 3
TEXT = 4
GG_POINT = 5
GM_POINT = 6

INSTANT = 10
INSTANT_SET = 11
SEQUENCE = 12
SEQUENCE_SET = 13

@classmethod
def get_temp_type(cls, c):
"""
Return the temporal type of `c`.

Args:
c: MEOS object.

Returns:
A :class:`TempType` representing the temporal type (int, float, bool, etc.).
"""
temp_type = c.temptype
if temp_type == 20:
return cls.BOOL
elif temp_type == 27:
return cls.FLOAT
elif temp_type == 29:
return cls.INT
elif temp_type == 35:
return cls.TEXT
elif temp_type == 40:
return cls.GM_POINT
elif temp_type == 41:
return cls.GG_POINT
raise Exception(f'Invalid temporal type: {temp_type}. Valid temporal types are: 12 (bool), 18 (float), '
f'21 (int), 22 (text), 25 (geometric point) and 26 (geographical point).')

@classmethod
def get_sub_type(cls, c):
"""
Return the temporal subtype of `c`.

Args:
c: MEOS object.

Returns:
A :class:`TempType` representing the temporal subtype (instant, sequence or sequenceSet).
"""
subtype = c.subtype
if subtype == 1:
return cls.INSTANT
elif subtype == 2:
return cls.SEQUENCE
elif subtype == 3:
return cls.SEQUENCE_SET
raise Exception(
f'Invalid subtype: {subtype}. Valid subtypes are: 1 (Instant), 2 (Sequence) and 3 (Sequence Set)')

@classmethod
def get_type(cls, c):
"""
Return the temporal MEOS type of `c` as a tuple of temporal type and subtype.

Args:
c: MEOS object.

Returns:
Tuple of two :class:`TempType` representing the temporal type (int, float, bool, etc.) and the temporal
subtype (instant, sequence or sequenceSet).
"""
return TempType.get_temp_type(c), TempType.get_sub_type(c)


class _TemporalFactory:
"""
Factory class to create the proper PyMEOS class from a MEOS object.

This class is used internally by PyMEOS classes and there shouldn't be any need to be used outside of them.
"""
_mapper = {
(TempType.BOOL, TempType.INSTANT): TBoolInst,
(TempType.BOOL, TempType.SEQUENCE): TBoolSeq,
(TempType.BOOL, TempType.SEQUENCE_SET): TBoolSeqSet,
(MeosType.T_TBOOL, MeosTemporalSubtype.INSTANT): TBoolInst,
(MeosType.T_TBOOL, MeosTemporalSubtype.SEQUENCE): TBoolSeq,
(MeosType.T_TBOOL, MeosTemporalSubtype.SEQUENCE_SET): TBoolSeqSet,

(TempType.INT, TempType.INSTANT): TIntInst,
(TempType.INT, TempType.SEQUENCE): TIntSeq,
(TempType.INT, TempType.SEQUENCE_SET): TIntSeqSet,
(MeosType.T_TINT, MeosTemporalSubtype.INSTANT): TIntInst,
(MeosType.T_TINT, MeosTemporalSubtype.SEQUENCE): TIntSeq,
(MeosType.T_TINT, MeosTemporalSubtype.SEQUENCE_SET): TIntSeqSet,

(TempType.FLOAT, TempType.INSTANT): TFloatInst,
(TempType.FLOAT, TempType.SEQUENCE): TFloatSeq,
(TempType.FLOAT, TempType.SEQUENCE_SET): TFloatSeqSet,
(MeosType.T_TFLOAT, MeosTemporalSubtype.INSTANT): TFloatInst,
(MeosType.T_TFLOAT, MeosTemporalSubtype.SEQUENCE): TFloatSeq,
(MeosType.T_TFLOAT, MeosTemporalSubtype.SEQUENCE_SET): TFloatSeqSet,

(TempType.TEXT, TempType.INSTANT): TTextInst,
(TempType.TEXT, TempType.SEQUENCE): TTextSeq,
(TempType.TEXT, TempType.SEQUENCE_SET): TTextSeqSet,
(MeosType.T_TTEXT, MeosTemporalSubtype.INSTANT): TTextInst,
(MeosType.T_TTEXT, MeosTemporalSubtype.SEQUENCE): TTextSeq,
(MeosType.T_TTEXT, MeosTemporalSubtype.SEQUENCE_SET): TTextSeqSet,

(TempType.GM_POINT, TempType.INSTANT): TGeomPointInst,
(TempType.GM_POINT, TempType.SEQUENCE): TGeomPointSeq,
(TempType.GM_POINT, TempType.SEQUENCE_SET): TGeomPointSeqSet,
(MeosType.T_TGEOMPOINT, MeosTemporalSubtype.INSTANT): TGeomPointInst,
(MeosType.T_TGEOMPOINT, MeosTemporalSubtype.SEQUENCE): TGeomPointSeq,
(MeosType.T_TGEOMPOINT, MeosTemporalSubtype.SEQUENCE_SET): TGeomPointSeqSet,

(TempType.GG_POINT, TempType.INSTANT): TGeogPointInst,
(TempType.GG_POINT, TempType.SEQUENCE): TGeogPointSeq,
(TempType.GG_POINT, TempType.SEQUENCE_SET): TGeogPointSeqSet,
(MeosType.T_TGEOGPOINT, MeosTemporalSubtype.INSTANT): TGeogPointInst,
(MeosType.T_TGEOGPOINT, MeosTemporalSubtype.SEQUENCE): TGeogPointSeq,
(MeosType.T_TGEOGPOINT, MeosTemporalSubtype.SEQUENCE_SET): TGeogPointSeqSet,
}

@staticmethod
Expand All @@ -134,5 +53,5 @@ def create_temporal(inner):
"""
if inner is None:
return None
temp_type = TempType.get_type(inner)
temp_type = (inner.temptype, inner.subtype)
return _TemporalFactory._mapper[temp_type](_inner=inner)
10 changes: 5 additions & 5 deletions pymeos/pymeos/temporal/interpolation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

from pymeos_cffi import InterpolationType
from enum import IntEnum


Expand All @@ -8,10 +8,10 @@ class TInterpolation(IntEnum):
Enum for representing the different types of interpolation present in
PyMEOS.
"""
NONE = 0
DISCRETE = 1
STEPWISE = 2
LINEAR = 3
NONE = InterpolationType.NONE
DISCRETE = InterpolationType.DISCRETE
STEPWISE = InterpolationType.STEP
LINEAR = InterpolationType.LINEAR

@staticmethod
def from_string(source: str, none: bool = True) -> TInterpolation:
Expand Down
6 changes: 3 additions & 3 deletions pymeos/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'

[project]
name = 'pymeos'
version = '1.1.3-beta.1-post2'
version = '1.1.3-beta.2'
authors = [
{ name = 'Victor Divi', email = 'vdiviloper@gmail.com' },
{ name = 'Zhicheng Luo', email = 'zhicheng.luo@ulb.be' },
Expand All @@ -13,7 +13,7 @@ authors = [
description = 'Python wrapper for the MEOS C Library.'
classifiers = [
'License :: OSI Approved :: PostgreSQL License',
'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Programming Language :: C',
Expand All @@ -34,7 +34,7 @@ license = {file = 'LICENSE'}

requires-python = '>=3.7'
dependencies = [
'pymeos-cffi ==1.1.0b1',
'pymeos-cffi ==1.1.0b3',
'python-dateutil',
'shapely',
]
Expand Down
11 changes: 9 additions & 2 deletions pymeos_cffi/pymeos_cffi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from .functions import *

from .enums import *
from .errors import *

__version__ = '1.1.0b3'
__all__ = [
# Exceptions
# Exceptions
'MeosException',
'MeosInternalError',
'MeosArgumentError',
Expand All @@ -26,6 +27,12 @@
'MeosWkbOutputError',
'MeosGeoJsonInputError',
'MeosGeoJsonOutputError',
# Enums
'MeosType',
'MeosTemporalSubtype',
'MeosOperation',
'InterpolationType',
'SpatialRelation',
# Functions
'meos_set_debug',
'py_error_handler',
Expand Down
2 changes: 1 addition & 1 deletion pymeos_cffi/pymeos_cffi/builder/build_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(include_dir, so_path=None, destination_path='pymeos_cffi/builder/meos.h

# Remove macros that are not number constants
content = content.replace('#', '//#')
content = re.sub(r'^//(#define \w+ \d+)\s*$', r'\g<1>', content, flags=re.RegexFlag.MULTILINE)
content = re.sub(r'^//(#define +\w+ +\d+)\s*$', r'\g<1>', content, flags=re.RegexFlag.MULTILINE)
content = re.sub(r'//#ifdef.*?//#endif', '', content, flags=re.RegexFlag.DOTALL)
content = content.replace('//#endif', '')
content = re.sub(r'//# *\w+ +([\w,()]+) *((?:\\\n|.)*?)\n', '', content)
Expand Down
41 changes: 9 additions & 32 deletions pymeos_cffi/pymeos_cffi/builder/build_pymeos_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ def main(header_path='pymeos_cffi/builder/meos.h'):
matches = re.finditer(f_regex, ''.join(content.splitlines()), flags=RegexFlag.MULTILINE)

template_path = os.path.join(os.path.dirname(__file__), 'templates/functions.py')
with open(template_path) as f:
init_template_path = os.path.join(os.path.dirname(__file__), 'templates/init.py')
with open(template_path) as f, open(init_template_path) as i:
base = f.read()
init_text = i.read()

functions_path = os.path.join(os.path.dirname(__file__), '../functions.py')
init_path = os.path.join(os.path.dirname(__file__), '../__init__.py')
Expand All @@ -250,44 +252,19 @@ def main(header_path='pymeos_cffi/builder/meos.h'):
file.write('\n\n\n')

functions = []
with open(functions_path, 'r') as funcs, open(init_path, 'w+') as init:
with open(functions_path, 'r') as funcs:
content = funcs.read()
matches = list(re.finditer(r'def (\w+)\(', content))
init.write('from .functions import *\n\n')
init.write('from .errors import *\n\n')
init.write('__all__ = [\n'
" # Exceptions \n"
" 'MeosException',\n"
" 'MeosInternalError',\n"
" 'MeosArgumentError',\n"
" 'MeosIoError',\n"
" 'MeosInternalTypeError',\n"
" 'MeosValueOutOfRangeError',\n"
" 'MeosDivisionByZeroError',\n"
" 'MeosMemoryAllocError',\n"
" 'MeosAggregationError',\n"
" 'MeosDirectoryError',\n"
" 'MeosFileError',\n"
" 'MeosInvalidArgError',\n"
" 'MeosInvalidArgTypeError',\n"
" 'MeosInvalidArgValueError',\n"
" 'MeosMfJsonInputError',\n"
" 'MeosMfJsonOutputError',\n"
" 'MeosTextInputError',\n"
" 'MeosTextOutputError',\n"
" 'MeosWkbInputError',\n"
" 'MeosWkbOutputError',\n"
" 'MeosGeoJsonInputError',\n"
" 'MeosGeoJsonOutputError',\n"
" # Functions\n"
)
function_text = ''
for fn in matches:
function_name = fn.group(1)
if function_name in hidden_functions:
continue
init.write(f" '{function_name}',\n")
function_text += f" '{function_name}',\n"
functions.append(function_name)
init.write(']\n')
init_text = init_text.replace('FUNCTIONS_REPLACE', function_text)
with open(init_path, 'w+') as init:
init.write(init_text)

check_modifiers(functions)

Expand Down
5 changes: 5 additions & 0 deletions pymeos_cffi/pymeos_cffi/builder/meos.h
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,11 @@ extern bool ensure_tnumber_tgeo_type(meosType type);
//#include <meos.h>
//#include "meos_catalog.h"

#define ANYTEMPSUBTYPE 0
#define TINSTANT 1
#define TSEQUENCE 2
#define TSEQUENCESET 3



extern uint32 datum_hash(Datum d, meosType basetype);
Expand Down
37 changes: 37 additions & 0 deletions pymeos_cffi/pymeos_cffi/builder/templates/init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from .functions import *
from .enums import *
from .errors import *

__version__ = '1.1.0b3'
__all__ = [
# Exceptions
'MeosException',
'MeosInternalError',
'MeosArgumentError',
'MeosIoError',
'MeosInternalTypeError',
'MeosValueOutOfRangeError',
'MeosDivisionByZeroError',
'MeosMemoryAllocError',
'MeosAggregationError',
'MeosDirectoryError',
'MeosFileError',
'MeosInvalidArgError',
'MeosInvalidArgTypeError',
'MeosInvalidArgValueError',
'MeosMfJsonInputError',
'MeosMfJsonOutputError',
'MeosTextInputError',
'MeosTextOutputError',
'MeosWkbInputError',
'MeosWkbOutputError',
'MeosGeoJsonInputError',
'MeosGeoJsonOutputError',
# Enums
'MeosType',
'MeosTemporalSubtype',
'MeosOperation',
'InterpolationType',
'SpatialRelation',
# Functions
FUNCTIONS_REPLACE]
Loading