From 2945479321e679bd11f04833eacbc950a2e74297 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Fri, 13 Jan 2017 09:31:35 -0700 Subject: [PATCH] Allow 3d object searches with 2d geojson area fixes #127 --- controller/collection/collection.go | 14 ++++++++++++++ controller/search.go | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/controller/collection/collection.go b/controller/collection/collection.go index 0b6235cc..460da3fe 100644 --- a/controller/collection/collection.go +++ b/controller/collection/collection.go @@ -1,6 +1,8 @@ package collection import ( + "math" + "github.com/tidwall/btree" "github.com/tidwall/tile38/geojson" "github.com/tidwall/tile38/index" @@ -384,6 +386,12 @@ func (c *Collection) Within(cursor uint64, sparse uint8, obj geojson.Object, min var bbox geojson.BBox if obj != nil { bbox = obj.CalculatedBBox() + if minZ == math.Inf(-1) && maxZ == math.Inf(+1) { + if bbox.Min.Z == 0 && bbox.Max.Z == 0 { + bbox.Min.Z = minZ + bbox.Max.Z = maxZ + } + } } else { bbox = geojson.BBox{Min: geojson.Position{X: minLon, Y: minLat, Z: minZ}, Max: geojson.Position{X: maxLon, Y: maxLat, Z: maxZ}} } @@ -432,6 +440,12 @@ func (c *Collection) Intersects(cursor uint64, sparse uint8, obj geojson.Object, var bbox geojson.BBox if obj != nil { bbox = obj.CalculatedBBox() + if minZ == math.Inf(-1) && maxZ == math.Inf(+1) { + if bbox.Min.Z == 0 && bbox.Max.Z == 0 { + bbox.Min.Z = minZ + bbox.Max.Z = maxZ + } + } } else { bbox = geojson.BBox{Min: geojson.Position{X: minLon, Y: minLat, Z: minZ}, Max: geojson.Position{X: maxLon, Y: maxLat, Z: maxZ}} } diff --git a/controller/search.go b/controller/search.go index a256bff0..336bc2a1 100644 --- a/controller/search.go +++ b/controller/search.go @@ -298,9 +298,9 @@ func (c *Controller) cmdNearby(msg *server.Message) (res string, err error) { } return sw.writeObject(ScanWriterParams{ - id: id, - o: o, - fields: fields, + id: id, + o: o, + fields: fields, distance: distance, }) }) @@ -349,8 +349,8 @@ func (c *Controller) cmdWithinOrIntersects(cmd string, msg *server.Message) (res s.cursor = sw.col.Within(s.cursor, s.sparse, s.o, s.minLat, s.minLon, s.maxLat, s.maxLon, minZ, maxZ, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ - id: id, - o: o, + id: id, + o: o, fields: fields, }) }, @@ -359,8 +359,8 @@ func (c *Controller) cmdWithinOrIntersects(cmd string, msg *server.Message) (res s.cursor = sw.col.Intersects(s.cursor, s.sparse, s.o, s.minLat, s.minLon, s.maxLat, s.maxLon, minZ, maxZ, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ - id: id, - o: o, + id: id, + o: o, fields: fields, }) }, @@ -414,8 +414,8 @@ func (c *Controller) cmdSearch(msg *server.Message) (res string, err error) { s.cursor = sw.col.SearchValues(s.cursor, s.desc, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ - id: id, - o: o, + id: id, + o: o, fields: fields, }) }, @@ -428,8 +428,8 @@ func (c *Controller) cmdSearch(msg *server.Message) (res string, err error) { s.cursor, g.Limits[0], g.Limits[1], s.desc, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ - id: id, - o: o, + id: id, + o: o, fields: fields, }) },