Skip to content

Commit

Permalink
Fixed Z not matching on where clause Feature points.
Browse files Browse the repository at this point in the history
This issues fixes an issue where a search command with a where
clause using the "z" field would not match correctly for point
that where contained inside a GeoJSON Feature type.

Tile38 now extracts the Z coordinate from Point and Feature/Point
types.

fixes tidwall#622
  • Loading branch information
tidwall committed Sep 29, 2021
1 parent 4f4e168 commit de59d23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
5 changes: 1 addition & 4 deletions internal/server/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ func (server *Server) cmdGet(msg *Message) (resp.Value, error) {
buf.Write(appendJSONSimplePoint(nil, o))
} else {
point := o.Center()
var z float64
if gPoint, ok := o.(*geojson.Point); ok {
z = gPoint.Z()
}
z := extractZCoordinate(o)
if z != 0 {
vals = append(vals, resp.ArrayValue([]resp.Value{
resp.StringValue(strconv.FormatFloat(point.Y, 'f', -1, 64)),
Expand Down
5 changes: 1 addition & 4 deletions internal/server/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ func appendJSONSimpleBounds(dst []byte, o geojson.Object) []byte {

func appendJSONSimplePoint(dst []byte, o geojson.Object) []byte {
point := o.Center()
var z float64
if gPoint, ok := o.(*geojson.Point); ok {
z = gPoint.Z()
}
z := extractZCoordinate(o)
dst = append(dst, `{"lat":`...)
dst = strconv.AppendFloat(dst, point.Y, 'f', -1, 64)
dst = append(dst, `,"lon":`...)
Expand Down
26 changes: 16 additions & 10 deletions internal/server/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ func (sw *scanWriter) writeFoot() {
}
}

func extractZCoordinate(o geojson.Object) float64 {
for {
switch g := o.(type) {
case *geojson.Point:
return g.Z()
case *geojson.Feature:
o = g.Base()
default:
return 0
}
}
}

func (sw *scanWriter) fieldMatch(fields []float64, o geojson.Object) (fvals []float64, match bool) {
var z float64
var gotz bool
Expand All @@ -222,9 +235,7 @@ func (sw *scanWriter) fieldMatch(fields []float64, o geojson.Object) (fvals []fl
for _, where := range sw.wheres {
if where.field == "z" {
if !gotz {
if point, ok := o.(*geojson.Point); ok {
z = point.Z()
}
z = extractZCoordinate(o)
}
if !where.match(z) {
return
Expand Down Expand Up @@ -270,9 +281,7 @@ func (sw *scanWriter) fieldMatch(fields []float64, o geojson.Object) (fvals []fl
for _, where := range sw.wheres {
if where.field == "z" {
if !gotz {
if point, ok := o.(*geojson.Point); ok {
z = point.Z()
}
z = extractZCoordinate(o)
}
if !where.match(z) {
return
Expand Down Expand Up @@ -455,10 +464,7 @@ func (sw *scanWriter) writeObject(opts ScanWriterParams) bool {
vals = append(vals, resp.StringValue(opts.o.String()))
case outputPoints:
point := opts.o.Center()
var z float64
if point, ok := opts.o.(*geojson.Point); ok {
z = point.Z()
}
z := extractZCoordinate(opts.o)
if z != 0 {
vals = append(vals, resp.ArrayValue([]resp.Value{
resp.FloatValue(point.Y),
Expand Down

0 comments on commit de59d23

Please sign in to comment.