Skip to content

Instantly share code, notes, and snippets.

@ear7h
Created November 8, 2019 01:00
Show Gist options
  • Save ear7h/b35f93dc19bebaf728eb5a79ed623a4e to your computer and use it in GitHub Desktop.
Save ear7h/b35f93dc19bebaf728eb5a79ed623a4e to your computer and use it in GitHub Desktop.
mvt2wkt
package main
import (
"fmt"
"os"
"github.com/go-spatial/geom/encoding/mvt"
"github.com/go-spatial/geom/encoding/wkt"
)
func main() {
tile, err := mvt.Decode(os.Stdin)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
col := mvt.TileGeomCollection(tile)
err = wkt.Encode(os.Stdout, col)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
os.Exit(0)
}
diff --git a/encoding/mvt/decode.go b/encoding/mvt/decode.go
index dcbe2bf..41a29f6 100644
--- a/encoding/mvt/decode.go
+++ b/encoding/mvt/decode.go
@@ -240,7 +240,10 @@ func decodePoly(buf []uint32) (geom.Geometry, error) {
ln := curs.decodeNPoints(cmd.Count(), buf, true)
buf = buf[cmd.Count()*2:]
- if windingorder.OfPoints(ln...).IsClockwise() {
+ if windingorder.OfPoints(ln...).IsClockwise() == isCorrect {
+ ret = append(ret, nil)
+ } else if len(ret) == 0 {
+ isCorrect = false
ret = append(ret, nil)
}
@@ -268,6 +271,8 @@ func decodePoly(buf []uint32) (geom.Geometry, error) {
}
}
+var isCorrect = true
+
type decodeCursor struct {
x, y float64
}
@ear7h
Copy link
Author

ear7h commented Nov 8, 2019

Usage:

cat tile.pbf | go run main.go > tile.wkt

Apply the patch to https://github.com/go-spatial/geom/tree/mvt-decode if your mvt might have a bad winding order otherwise the current branch will panic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment