-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo.go
112 lines (94 loc) · 2.87 KB
/
geo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package gomeos
/*
#include "meos.h"
#include <stdio.h>
#include <stdlib.h>
#include "cast.h"
*/
import "C"
import "unsafe"
type Geom struct {
_inner *C.GSERIALIZED
}
func NewGeom(geom_str string, typemod int) Geom {
c_geom_str := C.CString(geom_str)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.pgis_geometry_in(c_geom_str, C.int(typemod))
g := Geom{_inner: c_geom}
return g
}
func PgisGeometryIn(input string, typemod int) *Geom {
c_geom_str := C.CString(input)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.pgis_geometry_in(c_geom_str, C.int(typemod))
g := &Geom{_inner: c_geom}
return g
}
func PgisGeographyIn(input string, typemod int) *Geom {
c_geom_str := C.CString(input)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.pgis_geography_in(c_geom_str, C.int(typemod))
g := &Geom{_inner: c_geom}
return g
}
func GeographyFromHexEwkb(input string) *Geom {
c_geom_str := C.CString(input)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.geography_from_hexewkb(c_geom_str)
g := &Geom{_inner: c_geom}
return g
}
func GeometryFromHexEwkb(input string) *Geom {
c_geom_str := C.CString(input)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.geometry_from_hexewkb(c_geom_str)
g := &Geom{_inner: c_geom}
return g
}
func GeographyFromText(input string, srid int) *Geom {
c_geom_str := C.CString(input)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.geography_from_text(c_geom_str, C.int(srid))
g := &Geom{_inner: c_geom}
return g
}
func GeometryFromText(input string, srid int) *Geom {
c_geom_str := C.CString(input)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.geometry_from_text(c_geom_str, C.int(srid))
g := &Geom{_inner: c_geom}
return g
}
func GeoFromGeojson(input string) *Geom {
c_geom_str := C.CString(input)
defer C.free(unsafe.Pointer(c_geom_str))
c_geom := C.geo_from_geojson(c_geom_str)
g := &Geom{_inner: c_geom}
return g
}
func (geom *Geom) GeoOut() string {
c_tgmpi_out := C.geo_out(geom._inner)
defer C.free(unsafe.Pointer(c_tgmpi_out))
tgmpi_out := C.GoString(c_tgmpi_out)
return tgmpi_out
}
func GeoAsText(g *Geom, precision int) string {
return C.GoString(C.geo_as_text(g._inner, C.int(precision)))
}
func GeoAsGeojson(g *Geom, option int, precision int, srs string) string {
return C.GoString(C.geo_as_geojson(g._inner, C.int(option), C.int(precision), C.CString(srs)))
}
func GeoAsEWKT(g *Geom, precision int) string {
return C.GoString(C.geo_as_ewkt(g._inner, C.int(precision)))
}
func GeoAsHexEwkb(g *Geom, endian string) string {
return C.GoString(C.geo_as_hexewkb(g._inner, C.CString(endian)))
}
func GeoSame(g1 *Geom, g2 *Geom) bool {
return bool(C.geo_same(g1._inner, g2._inner))
}
// BearingPointPoint Return the temporal bearing between two geometry/geography points
func BearingPointPoint(g1 *Geom, g2 *Geom) bool {
var res *C.double
return bool(C.bearing_point_point(g1._inner, g2._inner, res))
}