Go bindings for tidwall/tg Geometry library for C - Fast point-in-polygon
This is partial but functional, tg is a very small self contained C library, tgo compiles tg, no external dependencies needed.
Simply go get this library with CGO enabled (you'll need a C compiler).
// Unmarshal from WKT input := "POLYGON((0 0,0 1,1 1,1 0,0 0))" g, _ := tgo.UnmarshalWKT(input) // Marshal to WKT output := g.AsText() fmt.Println(output) // Prints: POLYGON((0 0,0 1,1 1,1 0,0 0))
input := `{"type":"Feature","properties":{},"geometry":{"coordinates":[-79.20159897229003,43.636785010689835],"type":"Point"}}` g, _ := tgo.UnmarshalGeoJSON(input)
input := []byte{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 63, 0, 0, 0, 0, 0, 0, 4, 64} g, _ := tgo.UnmarshalWKB(input)
if Intersects(g1, g2) { fmt.Println("Intersects") }
// load your collection using UnmarshalGeoJSON found := g.StabOne(2, 48) if found != nil { fmt.Println(found.Properties()) } // Output: {"properties":{ "ADMIN": "France", "ISO_A2": "FR", "ISO_A3": "FRA" }}
input := "POLYGON((0 0,0 1,1 1,1 0,0 0))" g, _ := tgo.UnmarshalWKT(input) if g.Types() == tgo.Polygon() { p, _ := g.AsPoly() p.HolesCount() }
Some tests are borrowed from simplefeatures.