Skip to content
Open
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# GoMEOS

[MEOS (Mobility Engine, Open Source)](https://www.libmeos.org/) is a C library which enables the manipulation of
temporal and spatio-temporal data based on [MobilityDB](https://mobilitydb.com/)'s data types and functions.
temporal and spatio-temporal data based on [MobilityDB](https://github.com/MobilityDB/MobilityDB)'s data types and functions.

GoMEOS is a Go library that wraps the MEOS C library using [CGO](https://pkg.go.dev/cmd/cgo), providing a set of Go functions that allows to use MEOS functionality by directly accessing C structs and C functions.
GoMEOS is a Go library that wraps the MEOS C library using [CGO](https://pkg.go.dev/cmd/cgo), providing a set of Go functions that allows to use MEOS functionality by directly accessing C structs and C functions. It tracks MEOS 1.4.

GoMEOS exposes the functionality of MEOS and is meant to be used directly by the user.

The wrappers are generated from the [MEOS-API](https://github.com/MobilityDB/MEOS-API) `meos-idl.json` catalog rather than written by hand. To regenerate them against a given MEOS version, see [`tools/README.md`](tools/README.md).

# Usage

## Installation
Expand Down
36 changes: 18 additions & 18 deletions main_tpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TPointAtValue[TP TPoint](tp TP, value *Geom) Temporal {

// TPointAtGeomTime Return a temporal point restricted to a geometry
func TpointAtGeomTime[T Temporal](temp T, new_temp T, geom *Geom) T {
c_temp := C.tpoint_at_geom(temp.Inner(), geom._inner, nil)
c_temp := C.tpoint_at_geom(temp.Inner(), geom._inner)
new_temp.Init(c_temp)
return new_temp
}
Expand All @@ -238,7 +238,7 @@ func TPointMinusValue[TP TPoint](tp TP, value *Geom) Temporal {

// TPointMinusGeomTime Return a temporal point minus a geometry
func TpointMinusGeomTime[T Temporal](temp T, new_temp T, geom *Geom) T {
c_temp := C.tpoint_minus_geom(temp.Inner(), geom._inner, nil)
c_temp := C.tpoint_minus_geom(temp.Inner(), geom._inner)
new_temp.Init(c_temp)
return new_temp
}
Expand Down Expand Up @@ -457,43 +457,43 @@ func EverNeTPointPoint(temp Temporal, gs *Geom) bool {
return int(C.ever_ne_tgeo_geo(temp.Inner(), gs._inner)) > 0
}

func TContainsGeoTPoint[TP TPoint](gs *Geom, temp TP, restr, atvalue bool) Temporal {
res := C.tcontains_geo_tgeo(gs._inner, temp.Inner(), C.bool(restr), C.bool(atvalue))
func TContainsGeoTPoint[TP TPoint](gs *Geom, temp TP) Temporal {
res := C.tcontains_geo_tgeo(gs._inner, temp.Inner())
return CreateTemporal(res)
}

func TDisjointTPointGeo[TP TPoint](temp TP, gs *Geom, restr, atvalue bool) Temporal {
res := C.tdisjoint_tgeo_geo(temp.Inner(), gs._inner, C.bool(restr), C.bool(atvalue))
func TDisjointTPointGeo[TP TPoint](temp TP, gs *Geom) Temporal {
res := C.tdisjoint_tgeo_geo(temp.Inner(), gs._inner)
return CreateTemporal(res)
}

func TDisjointTPointTPoint[TP1 TPoint, TP2 TPoint](temp1 TP1, temp2 TP2, restr, atvalue bool) Temporal {
res := C.tdisjoint_tgeo_tgeo(temp1.Inner(), temp2.Inner(), C.bool(restr), C.bool(atvalue))
func TDisjointTPointTPoint[TP1 TPoint, TP2 TPoint](temp1 TP1, temp2 TP2) Temporal {
res := C.tdisjoint_tgeo_tgeo(temp1.Inner(), temp2.Inner())
return CreateTemporal(res)
}

func TDWithinTPointGeo[TP TPoint](temp TP, gs *Geom, dist float64, restr, atvalue bool) Temporal {
res := C.tdwithin_tgeo_geo(temp.Inner(), gs._inner, C.double(dist), C.bool(restr), C.bool(atvalue))
func TDWithinTPointGeo[TP TPoint](temp TP, gs *Geom, dist float64) Temporal {
res := C.tdwithin_tgeo_geo(temp.Inner(), gs._inner, C.double(dist))
return CreateTemporal(res)
}

func TDWithinTPointTPoint[TP1 TPoint, TP2 TPoint](temp1 TP1, temp2 TP2, dist float64, restr, atvalue bool) Temporal {
res := C.tdwithin_tgeo_tgeo(temp1.Inner(), temp2.Inner(), C.double(dist), C.bool(restr), C.bool(atvalue))
func TDWithinTPointTPoint[TP1 TPoint, TP2 TPoint](temp1 TP1, temp2 TP2, dist float64) Temporal {
res := C.tdwithin_tgeo_tgeo(temp1.Inner(), temp2.Inner(), C.double(dist))
return CreateTemporal(res)
}

func TIntersectsTPointGeo[TP TPoint](temp TP, gs *Geom, restr, atvalue bool) Temporal {
res := C.tintersects_tgeo_geo(temp.Inner(), gs._inner, C.bool(restr), C.bool(atvalue))
func TIntersectsTPointGeo[TP TPoint](temp TP, gs *Geom) Temporal {
res := C.tintersects_tgeo_geo(temp.Inner(), gs._inner)
return CreateTemporal(res)
}

func TIntersectsTPointTPoint[TP1 TPoint, TP2 TPoint](temp1 TP1, temp2 TP2, restr, atvalue bool) Temporal {
res := C.tintersects_tgeo_tgeo(temp1.Inner(), temp2.Inner(), C.bool(restr), C.bool(atvalue))
func TIntersectsTPointTPoint[TP1 TPoint, TP2 TPoint](temp1 TP1, temp2 TP2) Temporal {
res := C.tintersects_tgeo_tgeo(temp1.Inner(), temp2.Inner())
return CreateTemporal(res)
}

func TTouchesTPointGeo[TP TPoint](temp TP, gs *Geom, restr, atvalue bool) Temporal {
res := C.ttouches_tgeo_geo(temp.Inner(), gs._inner, C.bool(restr), C.bool(atvalue))
func TTouchesTPointGeo[TP TPoint](temp TP, gs *Geom) Temporal {
res := C.ttouches_tgeo_geo(temp.Inner(), gs._inner)
return CreateTemporal(res)
}

Expand Down
58 changes: 56 additions & 2 deletions meos.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

/* C */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/* PostgreSQL */
#ifndef POSTGRES_H
Expand Down Expand Up @@ -114,6 +115,15 @@ extern char *timestamptz_out(TimestampTz t);
#define strdup _strdup
#endif

/*
* Thread-local storage qualifier (MEOS_TLS) used internally by MEOS to
* make per-thread state (last-error number, PROJ context, SRS cache,
* ways cache, RNG, session timezone) safe under multithreading. Defined
* in a stand-alone header so that vendored PostgreSQL files can pick it
* up without pulling in the full meos.h.
*/
#include "meos_tls.h"

/*****************************************************************************
* Type definitions
*****************************************************************************/
Expand Down Expand Up @@ -309,6 +319,34 @@ typedef struct SkipList SkipList;

/*****************************************************************************/

/**
* Structure for expandable arrays
*/
typedef struct MeosArray MeosArray;

/* MeosArray functions */

extern MeosArray *meos_array_create(int elem_size);
extern void meos_array_add(MeosArray *array, void *value);
extern void *meos_array_get(const MeosArray *array, int n);
extern int meos_array_count(const MeosArray *array);
extern void meos_array_reset(MeosArray *array);
extern void meos_array_reset_free(MeosArray *array);
extern void meos_array_destroy(MeosArray *array);
extern void meos_array_destroy_free(MeosArray *array);

/*****************************************************************************/

/**
* @brief Enumeration that defines the search operations for an RTree.
*/
typedef enum
{
RTREE_OVERLAPS, /**< Find stored boxes that overlap the query */
RTREE_CONTAINS, /**< Find stored boxes that contain the query */
RTREE_CONTAINED_BY /**< Find stored boxes contained by the query */
} RTreeSearchOp;

/**
* Structure for the in-memory Rtree index
*/
Expand All @@ -324,8 +362,10 @@ extern RTree *rtree_create_tstzspan();
extern RTree *rtree_create_tbox();
extern RTree *rtree_create_stbox();
extern void rtree_free(RTree *rtree);
extern void rtree_insert(RTree *rtree, void *box, int64 id);
extern int *rtree_search(const RTree *rtree,const void *query, int *count);
extern void rtree_insert(RTree *rtree, void *box, int id);
extern void rtree_insert_temporal(RTree *rtree, const Temporal *temp, int id);
extern int rtree_search(const RTree *rtree, RTreeSearchOp op, const void *query, MeosArray *result);
extern int rtree_search_temporal(const RTree *rtree, RTreeSearchOp op, const Temporal *temp, MeosArray *result);

/*****************************************************************************
* Error codes
Expand Down Expand Up @@ -371,6 +411,18 @@ extern int meos_errno_reset(void);

/*****************************************************************************
* Initialization of the MEOS library
*
* Multithreading
* --------------
* The MEOS state managed by these functions is per-thread. Each thread
* that calls into MEOS must call `meos_initialize()` before its first
* MEOS call and `meos_finalize()` before exiting; the PROJ context, SRS
* cache, ways cache, RNGs, last-error number (`meos_errno`), and
* session timezone are all thread-local.
*
* The error handler set by `meos_initialize_error_handler()` is the
* one exception: it is process-global and should be installed once
* before workers are spawned.
*****************************************************************************/

/* Definition of error handler function */
Expand Down Expand Up @@ -1797,6 +1849,8 @@ extern int nad_tint_tint(const Temporal *temp1, const Temporal *temp2);
extern SkipList *tbool_tand_transfn(SkipList *state, const Temporal *temp);
extern SkipList *tbool_tor_transfn(SkipList *state, const Temporal *temp);
extern Span *temporal_extent_transfn(Span *s, const Temporal *temp);
extern SkipList *temporal_merge_transfn(SkipList *state, const Temporal *temp);
extern SkipList *temporal_merge_combinefn(SkipList *state1, SkipList *state2);
extern Temporal *temporal_tagg_finalfn(SkipList *state);
extern SkipList *temporal_tcount_transfn(SkipList *state, const Temporal *temp);
extern SkipList *tfloat_tmax_transfn(SkipList *state, const Temporal *temp);
Expand Down
Loading