36
36
func New [T geom.T ](geom T ) Geometry [T ] { return Geometry [T ]{geom } }
37
37
38
38
// Scan impl sql.Scanner
39
- func (p * Geometry [T ]) Scan (value interface {}) (err error ) {
39
+ func (g * Geometry [T ]) Scan (value interface {}) (err error ) {
40
40
var (
41
41
wkb []byte
42
42
ok bool
@@ -60,7 +60,7 @@ func (p *Geometry[T]) Scan(value interface{}) (err error) {
60
60
return err
61
61
}
62
62
63
- p .Geom , ok = geometryT .(T )
63
+ g .Geom , ok = geometryT .(T )
64
64
if ! ok {
65
65
return ErrUnexpectedValueType
66
66
}
@@ -69,24 +69,24 @@ func (p *Geometry[T]) Scan(value interface{}) (err error) {
69
69
}
70
70
71
71
// Value impl driver.Valuer
72
- func (p Geometry [T ]) Value () (driver.Value , error ) {
73
- if geom .T (p .Geom ) == nil {
72
+ func (g Geometry [T ]) Value () (driver.Value , error ) {
73
+ if geom .T (g .Geom ) == nil {
74
74
return nil , nil
75
75
}
76
76
77
77
sb := & bytes.Buffer {}
78
- if err := ewkb .Write (sb , binary .LittleEndian , p .Geom ); err != nil {
78
+ if err := ewkb .Write (sb , binary .LittleEndian , g .Geom ); err != nil {
79
79
return nil , err
80
80
}
81
81
82
82
return hex .EncodeToString (sb .Bytes ()), nil
83
83
}
84
84
85
85
// GormDataType impl schema.GormDataTypeInterface
86
- func (p Geometry [T ]) GormDataType () string {
86
+ func (g Geometry [T ]) GormDataType () string {
87
87
srid := strconv .Itoa (SRID )
88
88
89
- switch any (p .Geom ).(type ) {
89
+ switch any (g .Geom ).(type ) {
90
90
case * geom.Point :
91
91
return "Geometry(Point, " + srid + ")"
92
92
case * geom.LineString :
@@ -106,10 +106,11 @@ func (p Geometry[T]) GormDataType() string {
106
106
}
107
107
}
108
108
109
- func (p Geometry [T ]) String () string {
110
- if geomWkt , err := wkt .Marshal (p .Geom ); err == nil {
109
+ // String returns geometry formatted using WKT format
110
+ func (g Geometry [T ]) String () string {
111
+ if geomWkt , err := wkt .Marshal (g .Geom ); err == nil {
111
112
return geomWkt
112
113
}
113
114
114
- return fmt .Sprintf ("cannot marshal geometry: %T" , p .Geom )
115
+ return fmt .Sprintf ("cannot marshal geometry: %T" , g .Geom )
115
116
}
0 commit comments