Created
November 8, 2019 01:00
-
-
Save ear7h/b35f93dc19bebaf728eb5a79ed623a4e to your computer and use it in GitHub Desktop.
mvt2wkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
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