Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
MobilityDBPublic

About

Go binding for the MEOS spatiotemporal library, via CGO

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

219 Commits

Folders and files

Repository files navigation

GoMEOS

MEOS (Mobility Engine, Open Source) is a C library which enables the manipulation of temporal and spatio-temporal data based on MobilityDB's data types and functions.

GoMEOS is a Go library that wraps the MEOS C library using 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 in two packages, both generated: types holds a class per MEOS type, types.TGeomPoint or types.FloatSpan, whose methods are the functions of the type, and functions holds one Go function per MEOS C function, which the methods call.

The wrappers are generated from the MEOS-API meos-idl.json catalog rather than written by hand. To regenerate them against a given MEOS version, see tools/README.md.

Usage

Installation

You'll need to install the MEOS library by compling MobilityDB.

git clone git@github.com:MobilityDB/MobilityDB.git
cd MobilityDB
mkdir build
cd build
cmake -DMEOS=on ..
make
sudo make install

GoMEOS requires CGO (CGO_ENABLED=1) in order to be built.

Then install GoMEOS by go get command.

go get github.com/MobilityDB/GoMEOS

Quick Start

IMPORTANT Before using any GoMEOS function, always call functions.MeosInitialize(). Otherwise, the library will crash with a Segmentation Fault error. You should also always call functions.MeosFinalize() at the end of your code.

// main.go
package main

import (
	"fmt"

	"github.com/MobilityDB/GoMEOS/functions"
	"github.com/MobilityDB/GoMEOS/types"
)

func main() {
	functions.MeosInitialize()
	functions.MeosInitializeTimezone("UTC")

	/* Input temporal points in WKT format */
	inst_wkt := "POINT(1 1)@2000-01-01"
	seq_disc_wkt := "{POINT(1 1)@2000-01-01, POINT(2 2)@2000-01-02}"
	seq_linear_wkt := "[POINT(1 1)@2000-01-01, POINT(2 2)@2000-01-02]"
	seq_step_wkt := "Interp=Step;[POINT(1 1)@2000-01-01, POINT(2 2)@2000-01-02]"
	ss_linear_wkt := "{[POINT(1 1)@2000-01-01, POINT(2 2)@2000-01-02],[POINT(3 3)@2000-01-03, POINT(3 3)@2000-01-04]}"
	ss_step_wkt := "Interp=Step;{[POINT(1 1)@2000-01-01, POINT(2 2)@2000-01-02],[POINT(3 3)@2000-01-03, POINT(3 3)@2000-01-04]}"

	/* Read WKT into temporal point object */
	inst, _ := types.TGeomPointFromText(inst_wkt)
	seq_disc, _ := types.TGeomPointFromText(seq_disc_wkt)
	seq_linear, _ := types.TGeomPointFromText(seq_linear_wkt)
	seq_step, _ := types.TGeomPointFromText(seq_step_wkt)
	ss_linear, _ := types.TGeomPointFromText(ss_linear_wkt)
	ss_step, _ := types.TGeomPointFromText(ss_step_wkt)

	out := func(p *types.TGeomPoint) string {
		s, _ := p.AsText(5)
		return s
	}
	fmt.Println("--------------------Temporal Instant--------------------")
	fmt.Println(out(inst))
	fmt.Println("--------------------Temporal Sequence with Discrete Interpolation--------------------")
	fmt.Println(out(seq_disc))
	fmt.Println("--------------------Temporal Sequence with Linear Interpolation--------------------")
	fmt.Println(out(seq_linear))
	fmt.Println("--------------------Temporal Sequence with Step Interpolation--------------------")
	fmt.Println(out(seq_step))
	fmt.Println("--------------------Temporal Sequence Set with Linear Interpolation--------------------")
	fmt.Println(out(ss_linear))
	fmt.Println("--------------------Temporal Sequence Set with Step Interpolation--------------------")
	fmt.Println(out(ss_step))
	functions.MeosFinalize()
}

To run this file:

go build main.go
./main
output:
--------------------Temporal Instant--------------------
POINT(1 1)@2000-01-01 00:00:00+00
--------------------Temporal Sequence with Discrete Interpolation--------------------
{POINT(1 1)@2000-01-01 00:00:00+00, POINT(2 2)@2000-01-02 00:00:00+00}
--------------------Temporal Sequence with Linear Interpolation--------------------
[POINT(1 1)@2000-01-01 00:00:00+00, POINT(2 2)@2000-01-02 00:00:00+00]
--------------------Temporal Sequence with Step Interpolation--------------------
Interp=Step;[POINT(1 1)@2000-01-01 00:00:00+00, POINT(2 2)@2000-01-02 00:00:00+00]
--------------------Temporal Sequence Set with Linear Interpolation--------------------
{[POINT(1 1)@2000-01-01 00:00:00+00, POINT(2 2)@2000-01-02 00:00:00+00], [POINT(3 3)@2000-01-03 00:00:00+00, POINT(3 3)@2000-01-04 00:00:00+00]}
--------------------Temporal Sequence Set with Step Interpolation--------------------
Interp=Step;{[POINT(1 1)@2000-01-01 00:00:00+00, POINT(2 2)@2000-01-02 00:00:00+00], [POINT(3 3)@2000-01-03 00:00:00+00, POINT(3 3)@2000-01-04 00:00:00+00]}

For more examples, you can see the examples.

Each example ports a C program of MobilityDB's meos/examples and reads and writes the files of its data directory, the data every binding's examples share. Build an example, then run it from that directory:

git clone https://github.com/MobilityDB/MobilityDB.git
git clone https://github.com/MobilityDB/GoMEOS.git
cd GoMEOS
go build -o ais ./examples/ais/assemble
cd ../MobilityDB/meos/examples
../../../GoMEOS/ais

Documentation

Visit pkg.go.dev for a more complete and detailed documentation.

About

Go binding for the MEOS spatiotemporal library, via CGO

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages