Closed sid6mathur closed 6 years ago
This library does not support that, and because of its design can't really do that easily. However, I am working on a new library that tries to fix these problems (and other). https://github.com/paulmach/orb
Using orb you'd take your raw geojson data and do something like
package main
import (
"fmt"
"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"
"github.com/paulmach/orb/planar"
)
func main() {
point := orb.Point{1, 2} // some point to test
rawGeoJSONFeature := []byte{}
feature, err := geojson.UnmarshalFeature(rawGeoJSONFeature)
if err != nil {
panic(err)
}
polygon, ok := feature.Geometry.(orb.Polygon)
if !ok {
panic(fmt.Sprintf("geometry not a polygon, it's a %s", feature.Geometry.GeoJSONType()))
}
if planar.PolygonContains(polygon, point) {
fmt.Printf("YES")
} else {
fmt.Printf("NO")
}
}
I hope that helps.
I'm going to close this since I'm since it's question that I think I answered.
This library is beautiful work Paul, much gratitude.
I see no way to check if a
Point
is within a hexagon using eithergo.geo
or usinggo.geojson
. Could such a helper function be added?I have a Polygon-type
Geometry
handy with[][][]float64
underlying data guaranteed to be closed and hexagonal, but there is no way to check whether a Point is in it.The overall topic is segmenting a city into hundreds of hexagons and binning samples into each of them. Equivalent functionality in Turf.js is
hexGrid()
for generating hexagons in a bounding box and then assigning points to bins withpointsWithinPolygon()
.Thank you! Siddharth