mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 09:20:17 +01:00
Fixed interleaved sqlite spatial query.
This commit is contained in:
parent
edbd790268
commit
06c8ef8f88
@ -366,50 +366,50 @@ func (ss *SqliteSession) interleavedSpatialQuery(
|
||||
zmin, zmax = order(zmin, zmax)
|
||||
cub := common.Cuboid{P1: c1, P2: c2}
|
||||
rangeStmt := ss.txStmt(ss.backend.rangeStmt)
|
||||
var (
|
||||
err error
|
||||
rows *sql.Rows
|
||||
)
|
||||
|
||||
zcode := zmin
|
||||
|
||||
loop:
|
||||
// log.Printf("query %d %d\n", zmin, zmax)
|
||||
if rows, err = rangeStmt.Query(zmin, zmax); err != nil {
|
||||
log.Printf("Error in range query: %s\n", err)
|
||||
|
||||
rows, err := rangeStmt.Query(zcode, zmax)
|
||||
if err != nil {
|
||||
log.Printf("error: fetching range failed: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
var zcode int64
|
||||
var data []byte
|
||||
if err = rows.Scan(&zcode, &data); err != nil {
|
||||
log.Printf("Error in scanning row: %s\n", err)
|
||||
rows.Close()
|
||||
log.Printf("error: scanning row failed: %s\n", err)
|
||||
return
|
||||
}
|
||||
// log.Printf("zcode: %d\n", zcode)
|
||||
c := common.InterleavedToCoord(zcode)
|
||||
if cub.Contains(c) {
|
||||
var encodedKey []byte
|
||||
if encodedKey, err = common.EncodeStringToBytes(common.CoordToPlain(c)); err != nil {
|
||||
log.Printf("Key encoding failed: %s\n", err)
|
||||
rows.Close()
|
||||
return
|
||||
}
|
||||
key := common.StringToBytes(common.CoordToPlain(c))
|
||||
//fmt.Printf("sending: %q\n", c)
|
||||
select {
|
||||
case blocks <- Block{Key: encodedKey, Data: data}:
|
||||
case blocks <- Block{Key: key, Data: data}:
|
||||
case <-done:
|
||||
rows.Close()
|
||||
return
|
||||
}
|
||||
} else { // Left the cuboid
|
||||
// log.Printf("Left cuboid %d\n", zcode)
|
||||
rows.Close()
|
||||
zmin = common.BigMin(zmin, zmax, zcode)
|
||||
} else {
|
||||
if err = rows.Close(); err != nil {
|
||||
log.Printf("error: closing range failed: %s\n", err)
|
||||
return
|
||||
}
|
||||
zcode = common.BigMin(zmin, zmax, zcode)
|
||||
goto loop
|
||||
}
|
||||
}
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
log.Printf("Error in range query: %s\n", err)
|
||||
log.Printf("error: iterating range failed: %s\n", err)
|
||||
}
|
||||
|
||||
if err = rows.Close(); err != nil {
|
||||
log.Printf("error: closing range failed: %s\n", err)
|
||||
}
|
||||
rows.Close()
|
||||
}()
|
||||
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user