Skip to content

Commit

Permalink
Merge pull request #17 from PDOK/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
WouterVisscher authored Jun 16, 2022
2 parents 0296a2a + 8bf6f0c commit cab201b
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 329 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/example
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
*.gpkg

example/*
!example/example.gpkg
!example/example.gpkg

/.vscode
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-bullseye AS build-env
FROM golang:1.18-bullseye AS build-env

ENV GO111MODULE=on
ENV GOPROXY=https://proxy.golang.org
Expand Down Expand Up @@ -26,7 +26,7 @@ RUN go test ./... -covermode=atomic
RUN go build -v -ldflags='-s -w -linkmode auto' -a -installsuffix cgo -o /sieve .

# FROM scratch
FROM golang:1.17-bullseye
FROM golang:1.18-bullseye
RUN apt-get update && apt-get install -y \
libsqlite3-mod-spatialite \
&& rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ go build .
go run . -s=[source GPKG] -t=[target GPKG] -r=[resolution for filtering] \
-p=[pagesize for writing to target GPKG]

go test .
go test ./... -covermode=atomic
```

## Docker
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/woutervisscher/sieve
module github.com/pdok/sieve

go 1.17
go 1.18

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-spatial/geom v0.0.0-20220426070044-6e8855d2cfe6
github.com/mattn/go-sqlite3 v1.14.13 // indirect
github.com/urfave/cli/v2 v2.8.1
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/arolek/p v0.0.0-20191103215535-df3c295ed582/go.mod h1:JPNItmi3yb44Q5QWM+Kh5n9oeRhfcJzPNS90mbLo25U=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb h1:FYO+lZtAUnakgSW9xYs7QvgawjCDM5wgHaXoDhYHNH4=
github.com/gdey/errors v0.0.0-20190426172550-8ebd5bc891fb/go.mod h1:PFaV7MgSRe92Wo9O2H2i1CIm7urUk10AgdSHKyBfjmQ=
Expand Down Expand Up @@ -29,10 +28,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191114222411-4191b8cbba09/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
48 changes: 17 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"fmt"
"log"
"os"

"github.com/go-spatial/geom/encoding/gpkg"
"github.com/pdok/sieve/pkg"
"github.com/pdok/sieve/pkg/gpkg"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -53,25 +53,23 @@ func main() {
}

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)
}
srcHandle, err := gpkg.Open(c.String(SOURCE))
if err != nil {
log.Fatalf("error opening source GeoPackage: %s", err)
}
defer srcHandle.Close()

trgHandle, err := gpkg.Open(c.String(TARGET))
if err != nil {
log.Fatalf("error opening target GeoPackage: %s", err)
}
defer trgHandle.Close()
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 := getSourceTableInfo(srcHandle)
tables := source.GetTableInfo()

err = initTargetGeopackage(trgHandle, tables)
err = target.CreateTables(tables)
if err != nil {
log.Fatalf("error initialization the target GeoPackage: %s", err)
}
Expand All @@ -80,23 +78,11 @@ func main() {

// Process the tables sequential
for _, table := range tables {
log.Printf(" sieving %s", table.name)
preSieve := make(chan feature)
postSieve := make(chan feature)
kill := make(chan bool)

go writeFeatures(postSieve, kill, trgHandle, table, c.Int(PAGESIZE))
go sieveFeatures(preSieve, postSieve, c.Float64(RESOLUTION))
go readFeatures(srcHandle, preSieve, table)

for {
if <-kill {
break
}
}
close(kill)
log.Println(fmt.Sprintf(` finished %s`, table.name))
log.Println("")
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 ===")
Expand Down
Loading

0 comments on commit cab201b

Please sign in to comment.