mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 09:20:17 +01:00
Clip coordinates in interleaved spatial queries to world boundaries.
This commit is contained in:
parent
6b717e41fb
commit
eb9cfb9959
@ -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),
|
||||
|
11
leveldb.go
11
leveldb.go
@ -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
|
||||
|
@ -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.
Loading…
Reference in New Issue
Block a user