New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Intersects with polygon #13
Comments
It's not available today but I plan on having this feature in the very near future. For now you will need to create a custom indexer and then filter out the intersecting polygons from inside the For example, you could use the GeoJSON library from the Tile38 project: // custom index function
func IndexGeoJSON(a string) (min, max []float64) {
o, err := geojson.ObjectJSON(a)
if err != nil {
return []float64{0, 0}, []float64{0, 0}
}
bbox := o.CalculatedBBox()
return []float64{bbox.Min.X, bbox.Min.Y}, []float64{bbox.Max.X, bbox.Max.Y}
}
// create the spatial index and bind it to the custom function
db.CreateSpatialIndex("poly", "poly:*", IndexGeoJSON)
// provide a polygon, or some valid GeoJSON object that you want to intersect against.
polyJSON := `{"type":"Polygon","coordinates":[...]}`
// do the query
var intersectingKeys []string
polyObj, err := geojson.ObjectJSON(poly)
if err == nil {
db.View(func(tx *buntdb.Tx) error {
tx.Intersects("poly", polyJSON, func(key, val string) bool {
valObj, err := geojson.ObjectJSON(val)
if err == nil && valObj.Intersects(polyObj) {
intersectingKeys = append(intersectingKeys, key)
}
return true
})
return nil
})
} |
@tidwall awesome, yeah i started going down this path, i am generating an envelope/bbox for the poly, querying the points, and then filtering points that fall outside of the poly shape. Perf seems fine but it would be awesome to support it out of the box. Let me know if i can help. |
I'm looking at creating a spatial index interface that handles Intersects, Within, and Nearby. I would likely provide GeoJSON and Well-Known Text/Binary out of the box. But the interface would allow for any format such as Topo or KML. I'll keep you posted on progress. |
@tidwall any news regarding this development? |
@eminden I got nothing at this time. Sorry. :( |
I need k-nearest queries, is it possible to do it somehow on the current implementation? |
This issue is pretty old so I'm closing it. Thanks! |
Is it somehow possible to intersect queries with polygons? Do i have to create a custom indexer for that?
Thanks!
The text was updated successfully, but these errors were encountered: