Clip coordinates in interleaved spatial queries to world boundaries.

This commit is contained in:
Sascha L. Teichmann 2014-09-07 21:36:59 +02:00
parent 6b717e41fb
commit eb9cfb9959
4 changed files with 27 additions and 5 deletions

View File

@ -59,6 +59,23 @@ func maxComponent(a, b int16) int16 {
return b
}
func clipComponent(x int16) int16 {
if x < minValue {
return minValue
}
if x > maxValue {
return maxValue
}
return x
}
func ClipCoord(c Coord) Coord {
return Coord{
X: clipComponent(c.X),
Y: clipComponent(c.Y),
Z: clipComponent(c.Z)}
}
func MinCoord(a, b Coord) Coord {
return Coord{
X: minComponent(a.X, b.X),

View File

@ -309,8 +309,8 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
if secondKey, err = common.DecodeStringFromBytes(second); err != nil {
return
}
c1 := common.PlainToCoord(firstKey)
c2 := common.PlainToCoord(secondKey)
c1 := common.ClipCoord(common.PlainToCoord(firstKey))
c2 := common.ClipCoord(common.PlainToCoord(secondKey))
c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2)
blocks = make(chan Block)
@ -336,6 +336,7 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
encodedKey []byte
)
//log.Printf("seeking to: %d", zmin)
it.Seek(common.ToBigEndian(zmin))
for it.Valid() {
zcode := common.FromBigEndian(it.Key())
@ -356,9 +357,13 @@ func (ldbs *LevelDBSession) interleavedSpatialQuery(first, second []byte, done c
}
it.Next()
} else {
it.Seek(common.ToBigEndian(common.BigMin(zmin, zmax, zcode)))
next := common.BigMin(zmin, zmax, zcode)
//log.Printf("seeking to: %d", next)
it.Seek(common.ToBigEndian(next))
//log.Printf("seeking done: %d", next)
}
}
//log.Println("iterating done")
if err = it.GetError(); err != nil {
log.Printf("error while iterating: %s", err)
return

View File

@ -303,8 +303,8 @@ func (ss *SqliteSession) interleavedSpatialQuery(first, second []byte, done chan
if secondKey, err = common.DecodeStringFromBytes(second); err != nil {
return
}
c1 := common.PlainToCoord(firstKey)
c2 := common.PlainToCoord(secondKey)
c1 := common.ClipCoord(common.PlainToCoord(firstKey))
c2 := common.ClipCoord(common.PlainToCoord(secondKey))
c1, c2 = common.MinCoord(c1, c2), common.MaxCoord(c1, c2)
blocks = make(chan Block)

Binary file not shown.