-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovider.go
84 lines (80 loc) · 1.52 KB
/
provider.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
package govector
import (
"io"
"path/filepath"
"strings"
"github.com/flywave/go-geom"
)
type Provider interface {
Match(filename string, file io.Reader) bool
Open(filename string, file io.Reader) error
Close() error
Reset() error
Next() bool
Read() *geom.Feature
}
func MatchProvider(filename string, file io.ReadSeeker) Provider {
ext := filepath.Ext(filename)
switch ext {
case ".geobuf":
p := &GeoBufProvider{}
if p.Match(filename, file) {
return p
}
case ".csv":
p := NewGeoCSVProvider()
if p.Match(filename, file) {
return p
}
case ".geojson":
p := &GeoJSONProvider{}
if p.Match(filename, file) {
return p
} else {
p2 := &GeoJSONGSeqProvider{}
if p2.Match(filename, file) {
return p2
}
}
case ".json":
p := &GeoJSONProvider{}
if p.Match(filename, file) {
return p
} else {
file.Seek(0, io.SeekStart)
p2 := &GeoJSONGSeqProvider{}
if p2.Match(filename, file) {
return p2
}
}
case ".gpkg":
p := &GeoPackageProvider{}
if p.Match(filename, file) {
return p
}
case ".pbf":
p := &OSMPbfProvider{}
if p.Match(filename, file) {
return p
}
case ".gz":
if strings.HasSuffix(filename, ".geojson.gz") || strings.HasSuffix(filename, ".json.gz") {
p := &GeoJSONGZProvider{}
if p.Match(filename, file) {
return p
}
}
if strings.HasSuffix(filename, ".tar.gz") {
p := &ShapeProvider{}
if p.Match(filename, file) {
return p
}
}
case ".zip":
p := &ShapeProvider{}
if p.Match(filename, file) {
return p
}
}
return nil
}