Skip to content

PyMEOS Architecture

Víctor Diví edited this page Oct 7, 2023 · 9 revisions

PyMEOS is a python library that wraps the MEOS C Library providing a set of Python classes that provides all functionality provided by MEOS.

PyMEOS has a 3-layer wrapper architecture with MEOS at its core.

PyMEOS 3-Layer Architecture

The wrappers are divided into two different packages:

  • PyMEOS CFFI Package
    Contains the two inner wrappers that exposes MEOS functionality.
  • PyMEOS Package
    Contains the outer wrapper that provides the Python classes interface.

Each wrapper hides implementation details to improve the usability of the library.

  • CFFI
    The CFFI layer is automatically generated by the CFFI library which results in a shared library that can be imported from python.
  • CFFI Wrapper
    The CFFI wrapper is a collection of functions that wraps every function exposed by the CFFI wrapper and handles basic type conversion (such as transforming Python's str to C's char *), and some other logic related to the mapping between Python and C types. Although it is not meant to be used directly, it is completely possible to do so:
from pymeos_cffi import meos_initialize, meos_finish, tbool_in, tbool_out

meos_initialize()

tp = tgeompoint_in('[POINT (0 0)@2000-01-01 00:00:00, POINT (10 10)@2000-01-01 00:10:00, POINT (15 15)@2000-01-01 00:20:00]')
speed = tpoint_speed(tp)
print(tfloat_out(speed, 5))
# Interp=Stepwise;[0.02357@2000-01-01 00:00:00+01, 0.01179@2000-01-01 00:10:00+01, 0.01179@2000-01-01 00:20:00+01]

meos_finish()
  • Outer Wrapper
    The Outer Wrapper contains all the python classes providing an Object Oriented interface.
from pymeos import meos_initialize, meos_finish, TGeomPointSeq

meos_initialize()

tp = TGeomPointSeq(string='[POINT (0 0)@2000-01-01 00:00:00, POINT (10 10)@2000-01-01 00:10:00, POINT (15 15)@2000-01-01 00:20:00]')
print(tp.speed)
# Interp=Stepwise;[0.02357@2000-01-01 00:00:00+01, 0.01179@2000-01-01 00:10:00+01, 0.01179@2000-01-01 00:20:00+01]

meos_finish()

Clone this wiki locally