-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
96 lines (81 loc) · 2.11 KB
/
main.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
package main
import (
"log"
"os"
"github.com/pdok/sieve/pkg"
"github.com/pdok/sieve/pkg/gpkg"
"github.com/urfave/cli/v2"
)
const SOURCE string = `source`
const TARGET string = `target`
const RESOLUTION string = `resolution`
const PAGESIZE string = `pagesize`
func main() {
app := cli.NewApp()
app.Name = "GOSieve"
app.Usage = "A Golang Polygon Sieve application"
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: SOURCE,
Aliases: []string{"s"},
Usage: "Source GPKG",
Required: true,
EnvVars: []string{"SOURCE_GPKG"},
},
&cli.StringFlag{
Name: TARGET,
Aliases: []string{"t"},
Usage: "Target GPKG",
Required: true,
EnvVars: []string{"TARGET_GPKG"},
},
&cli.Float64Flag{
Name: RESOLUTION,
Aliases: []string{"r"},
Usage: "Resolution, the threshold area to determine if a feature is sieved or not",
Value: 0.0,
Required: false,
EnvVars: []string{"SIEVE_RESOLUTION"},
},
&cli.IntFlag{
Name: PAGESIZE,
Aliases: []string{"p"},
Usage: "Page Size, how many features are written per transaction to the target GPKG",
Value: 1000,
Required: false,
EnvVars: []string{"SIEVE_PAGESIZE"},
},
}
app.Action = func(c *cli.Context) error {
_, err := os.Stat(c.String(SOURCE))
if os.IsNotExist(err) {
log.Fatalf("error opening source GeoPackage: %s", err)
}
source := gpkg.SourceGeopackage{}
source.Init(c.String(SOURCE))
defer source.Close()
target := gpkg.TargetGeopackage{}
target.Init(c.String(TARGET), c.Int(PAGESIZE))
defer target.Close()
tables := source.GetTableInfo()
err = target.CreateTables(tables)
if err != nil {
log.Fatalf("error initialization the target GeoPackage: %s", err)
}
log.Println("=== start sieving ===")
// Process the tables sequential
for _, table := range tables {
log.Printf(" sieving %s", table.Name)
source.Table = table
target.Table = table
pkg.Sieve(source, target, c.Float64(RESOLUTION))
log.Printf(" finised %s", table.Name)
}
log.Println("=== done sieving ===")
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}