-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgeo.go
More file actions
56 lines (48 loc) · 1.18 KB
/
Copy pathgeo.go
File metadata and controls
56 lines (48 loc) · 1.18 KB
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
package godatabend
import (
"database/sql/driver"
"encoding/hex"
"fmt"
"strings"
)
type geoOutputFormat uint8
const (
geoOutputFormatGeoJSON geoOutputFormat = iota
geoOutputFormatWKB
geoOutputFormatWKT
geoOutputFormatEWKB
geoOutputFormatEWKT
)
func parseGeoOutputFormat(s string) geoOutputFormat {
switch strings.ToUpper(strings.TrimSpace(s)) {
case "WKB":
return geoOutputFormatWKB
case "WKT":
return geoOutputFormatWKT
case "EWKB":
return geoOutputFormatEWKB
case "EWKT":
return geoOutputFormatEWKT
default:
return geoOutputFormatGeoJSON
}
}
func (f geoOutputFormat) returnsBinary() bool {
return f == geoOutputFormatWKB || f == geoOutputFormatEWKB
}
func materializeGeoFromString(kind, value string, format geoOutputFormat) (driver.Value, error) {
if !format.returnsBinary() {
return value, nil
}
raw, err := hex.DecodeString(value)
if err != nil {
return nil, fmt.Errorf("failed to decode %s hex value: %w", strings.ToLower(kind), err)
}
return raw, nil
}
func materializeGeoFromBinary(_ string, value []byte, format geoOutputFormat) (driver.Value, error) {
if format.returnsBinary() {
return append([]byte(nil), value...), nil
}
return string(value), nil
}