-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmanager.go
78 lines (70 loc) · 2.1 KB
/
manager.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
package gismanager
import (
"errors"
"path/filepath"
"strings"
gsconfig "github.com/hishamkaram/geoserver"
"github.com/lukeroth/gdal"
"github.com/sirupsen/logrus"
)
//GeoserverConfig geoserver configuration
type GeoserverConfig struct {
WorkspaceName string `yaml:"workspace"`
ServerURL string `yaml:"url"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}
//SourceConfig Data Source/Dir configuration
type SourceConfig struct {
Path string `yaml:"path"`
}
//ManagerConfig is the configuration Object
type ManagerConfig struct {
Geoserver GeoserverConfig `yaml:"geoserver"`
Datastore DatastoreConfig `yaml:"datastore"`
Source SourceConfig `yaml:"source"`
logger *logrus.Logger
}
//GetGeoserverCatalog return geoserver Catalog instance to deal with geoserver
func (manager *ManagerConfig) GetGeoserverCatalog() *gsconfig.GeoServer {
gsCatalog := gsconfig.GetCatalog(manager.Geoserver.ServerURL, manager.Geoserver.Username, manager.Geoserver.Password)
return gsCatalog
}
//OpenSource open data source from a given Path and access permission 0/1
func (manager *ManagerConfig) OpenSource(path string, access int) (source *gdal.DataSource, ok bool) {
driver, err := manager.GetDriver(path)
if err != nil {
manager.logger.Error(err)
ok = false
return
}
targetSource, success := driver.Open(path, access)
source = &targetSource
ok = success
return
}
//GetDriver return the proper driver based on file path/database connection
func (manager *ManagerConfig) GetDriver(path string) (driver gdal.OGRDriver, err error) {
if pgRegex.MatchString(path) {
driver = gdal.OGRDriverByName(postgreSQLDriver)
} else {
switch strings.ToLower(filepath.Ext(path)) {
case ".gpkg":
driver = gdal.OGRDriverByName(geopackageDriver)
break
case ".shp", ".zip":
driver = gdal.OGRDriverByName(shapeFileDriver)
break
case ".json", ".geojson":
driver = gdal.OGRDriverByName(geoJSONDriver)
break
case ".kml":
driver = gdal.OGRDriverByName(kmlDriver)
break
default:
err = errors.New("Can't Find the Proper Driver")
manager.logger.Error(err)
}
}
return
}