diff --git a/pymeos/pymeos/__init__.py b/pymeos/pymeos/__init__.py index e86c7dde..9618a098 100644 --- a/pymeos/pymeos/__init__.py +++ b/pymeos/pymeos/__init__.py @@ -28,7 +28,7 @@ MeosGeoJsonInputError, \ MeosGeoJsonOutputError -__version__ = '1.1.3b1' +__version__ = '1.1.3b2' __all__ = [ # initialization 'pymeos_initialize', 'pymeos_finalize', diff --git a/pymeos/pymeos/factory.py b/pymeos/pymeos/factory.py index 0c6484da..a9d10de9 100644 --- a/pymeos/pymeos/factory.py +++ b/pymeos/pymeos/factory.py @@ -1,4 +1,4 @@ -from enum import Enum +from pymeos_cffi import MeosType, MeosTemporalSubtype from .main import TBoolInst, TBoolSeq, TBoolSeqSet, \ TIntInst, TIntSeq, TIntSeqSet, \ @@ -8,87 +8,6 @@ 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. @@ -96,29 +15,29 @@ class _TemporalFactory: 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 @@ -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) diff --git a/pymeos/pymeos/temporal/interpolation.py b/pymeos/pymeos/temporal/interpolation.py index a6bbbe7b..5abb981f 100644 --- a/pymeos/pymeos/temporal/interpolation.py +++ b/pymeos/pymeos/temporal/interpolation.py @@ -1,5 +1,5 @@ from __future__ import annotations - +from pymeos_cffi import InterpolationType from enum import IntEnum @@ -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: diff --git a/pymeos/pyproject.toml b/pymeos/pyproject.toml index 9d9f5e28..b52017fd 100644 --- a/pymeos/pyproject.toml +++ b/pymeos/pyproject.toml @@ -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' }, @@ -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', @@ -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', ] diff --git a/pymeos_cffi/pymeos_cffi/__init__.py b/pymeos_cffi/pymeos_cffi/__init__.py index b0ca01a3..f902628d 100644 --- a/pymeos_cffi/pymeos_cffi/__init__.py +++ b/pymeos_cffi/pymeos_cffi/__init__.py @@ -1,9 +1,10 @@ from .functions import * - +from .enums import * from .errors import * +__version__ = '1.1.0b3' __all__ = [ - # Exceptions + # Exceptions 'MeosException', 'MeosInternalError', 'MeosArgumentError', @@ -26,6 +27,12 @@ 'MeosWkbOutputError', 'MeosGeoJsonInputError', 'MeosGeoJsonOutputError', + # Enums + 'MeosType', + 'MeosTemporalSubtype', + 'MeosOperation', + 'InterpolationType', + 'SpatialRelation', # Functions 'meos_set_debug', 'py_error_handler', diff --git a/pymeos_cffi/pymeos_cffi/builder/build_header.py b/pymeos_cffi/pymeos_cffi/builder/build_header.py index 0159005e..aa4ff276 100644 --- a/pymeos_cffi/pymeos_cffi/builder/build_header.py +++ b/pymeos_cffi/pymeos_cffi/builder/build_header.py @@ -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) diff --git a/pymeos_cffi/pymeos_cffi/builder/build_pymeos_functions.py b/pymeos_cffi/pymeos_cffi/builder/build_pymeos_functions.py index d7007dc4..a4437986 100644 --- a/pymeos_cffi/pymeos_cffi/builder/build_pymeos_functions.py +++ b/pymeos_cffi/pymeos_cffi/builder/build_pymeos_functions.py @@ -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') @@ -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) diff --git a/pymeos_cffi/pymeos_cffi/builder/meos.h b/pymeos_cffi/pymeos_cffi/builder/meos.h index 009de136..8513acb4 100644 --- a/pymeos_cffi/pymeos_cffi/builder/meos.h +++ b/pymeos_cffi/pymeos_cffi/builder/meos.h @@ -1828,6 +1828,11 @@ extern bool ensure_tnumber_tgeo_type(meosType type); //#include //#include "meos_catalog.h" +#define ANYTEMPSUBTYPE 0 +#define TINSTANT 1 +#define TSEQUENCE 2 +#define TSEQUENCESET 3 + extern uint32 datum_hash(Datum d, meosType basetype); diff --git a/pymeos_cffi/pymeos_cffi/builder/templates/init.py b/pymeos_cffi/pymeos_cffi/builder/templates/init.py new file mode 100644 index 00000000..34a32eb7 --- /dev/null +++ b/pymeos_cffi/pymeos_cffi/builder/templates/init.py @@ -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] diff --git a/pymeos_cffi/pymeos_cffi/enums.py b/pymeos_cffi/pymeos_cffi/enums.py new file mode 100644 index 00000000..7679fea7 --- /dev/null +++ b/pymeos_cffi/pymeos_cffi/enums.py @@ -0,0 +1,117 @@ +from _meos_cffi import lib as _lib +from enum import IntEnum + + +class MeosType(IntEnum): + T_UNKNOWN = _lib.T_UNKNOWN + T_BOOL = _lib.T_BOOL + T_DOUBLE2 = _lib.T_DOUBLE2 + T_DOUBLE3 = _lib.T_DOUBLE3 + T_DOUBLE4 = _lib.T_DOUBLE4 + T_FLOAT8 = _lib.T_FLOAT8 + T_FLOATSET = _lib.T_FLOATSET + T_FLOATSPAN = _lib.T_FLOATSPAN + T_FLOATSPANSET = _lib.T_FLOATSPANSET + T_INT4 = _lib.T_INT4 + T_INT4RANGE = _lib.T_INT4RANGE + T_INT4MULTIRANGE = _lib.T_INT4MULTIRANGE + T_INTSET = _lib.T_INTSET + T_INTSPAN = _lib.T_INTSPAN + T_INTSPANSET = _lib.T_INTSPANSET + T_INT8 = _lib.T_INT8 + T_BIGINTSET = _lib.T_BIGINTSET + T_BIGINTSPAN = _lib.T_BIGINTSPAN + T_BIGINTSPANSET = _lib.T_BIGINTSPANSET + T_STBOX = _lib.T_STBOX + T_TBOOL = _lib.T_TBOOL + T_TBOX = _lib.T_TBOX + T_TDOUBLE2 = _lib.T_TDOUBLE2 + T_TDOUBLE3 = _lib.T_TDOUBLE3 + T_TDOUBLE4 = _lib.T_TDOUBLE4 + T_TEXT = _lib.T_TEXT + T_TEXTSET = _lib.T_TEXTSET + T_TFLOAT = _lib.T_TFLOAT + T_TIMESTAMPTZ = _lib.T_TIMESTAMPTZ + T_TINT = _lib.T_TINT + T_TSTZMULTIRANGE = _lib.T_TSTZMULTIRANGE + T_TSTZRANGE = _lib.T_TSTZRANGE + T_TSTZSET = _lib.T_TSTZSET + T_TSTZSPAN = _lib.T_TSTZSPAN + T_TSTZSPANSET = _lib.T_TSTZSPANSET + T_TTEXT = _lib.T_TTEXT + T_GEOMETRY = _lib.T_GEOMETRY + T_GEOMSET = _lib.T_GEOMSET + T_GEOGRAPHY = _lib.T_GEOGRAPHY + T_GEOGSET = _lib.T_GEOGSET + T_TGEOMPOINT = _lib.T_TGEOMPOINT + T_TGEOGPOINT = _lib.T_TGEOGPOINT + T_NPOINT = _lib.T_NPOINT + T_NPOINTSET = _lib.T_NPOINTSET + T_NSEGMENT = _lib.T_NSEGMENT + T_TNPOINT = _lib.T_TNPOINT + + +class MeosTemporalSubtype(IntEnum): + ANY = _lib.ANYTEMPSUBTYPE + INSTANT = _lib.TINSTANT + SEQUENCE = _lib.TSEQUENCE + SEQUENCE_SET = _lib.TSEQUENCESET + + +class MeosOperation(IntEnum): + UNKNOWN_OP = _lib.UNKNOWN_OP + EQ_OP = _lib.EQ_OP + NE_OP = _lib.NE_OP + LT_OP = _lib.LT_OP + LE_OP = _lib.LE_OP + GT_OP = _lib.GT_OP + GE_OP = _lib.GE_OP + ADJACENT_OP = _lib.ADJACENT_OP + UNION_OP = _lib.UNION_OP + MINUS_OP = _lib.MINUS_OP + INTERSECT_OP = _lib.INTERSECT_OP + OVERLAPS_OP = _lib.OVERLAPS_OP + CONTAINS_OP = _lib.CONTAINS_OP + CONTAINED_OP = _lib.CONTAINED_OP + SAME_OP = _lib.SAME_OP + LEFT_OP = _lib.LEFT_OP + OVERLEFT_OP = _lib.OVERLEFT_OP + RIGHT_OP = _lib.RIGHT_OP + OVERRIGHT_OP = _lib.OVERRIGHT_OP + BELOW_OP = _lib.BELOW_OP + OVERBELOW_OP = _lib.OVERBELOW_OP + ABOVE_OP = _lib.ABOVE_OP + OVERABOVE_OP = _lib.OVERABOVE_OP + FRONT_OP = _lib.FRONT_OP + OVERFRONT_OP = _lib.OVERFRONT_OP + BACK_OP = _lib.BACK_OP + OVERBACK_OP = _lib.OVERBACK_OP + BEFORE_OP = _lib.BEFORE_OP + OVERBEFORE_OP = _lib.OVERBEFORE_OP + AFTER_OP = _lib.AFTER_OP + OVERAFTER_OP = _lib.OVERAFTER_OP + EVEREQ_OP = _lib.EVEREQ_OP + EVERNE_OP = _lib.EVERNE_OP + EVERLT_OP = _lib.EVERLT_OP + EVERLE_OP = _lib.EVERLE_OP + EVERGT_OP = _lib.EVERGT_OP + EVERGE_OP = _lib.EVERGE_OP + ALWAYSEQ_OP = _lib.ALWAYSEQ_OP + ALWAYSNE_OP = _lib.ALWAYSNE_OP + ALWAYSLT_OP = _lib.ALWAYSLT_OP + ALWAYSLE_OP = _lib.ALWAYSLE_OP + ALWAYSGT_OP = _lib.ALWAYSGT_OP + ALWAYSGE_OP = _lib.ALWAYSGE_OP + + +class InterpolationType(IntEnum): + NONE = _lib.INTERP_NONE + DISCRETE = _lib.DISCRETE + STEP = _lib.STEP + LINEAR = _lib.LINEAR + + +class SpatialRelation(IntEnum): + INTERSECTS = _lib.INTERSECTS + CONTAINS = _lib.CONTAINS + TOUCHES = _lib.TOUCHES diff --git a/pymeos_cffi/pyproject.toml b/pymeos_cffi/pyproject.toml index d8a515a3..31d48097 100644 --- a/pymeos_cffi/pyproject.toml +++ b/pymeos_cffi/pyproject.toml @@ -7,14 +7,14 @@ py-modules = [] [project] name = 'pymeos_cffi' -version = '1.1.0-beta.2' +version = '1.1.0-beta.3' authors = [ { name = 'Victor Divi', email = 'vdiviloper@gmail.com' } ] description = 'PyMEOS 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',