Re: [sqlite] Advice to choose an index for quad tree?

2011-05-04 Thread Jean-Denis Muys
I found the R-Tree idea fascinating. Conceptually, this is exactly what I need. 
But indeed, my case is very simple: my dataset is not sparse, my tiles never 
overlap (for a given zoom factor), the number of tiles is still rather small, 
they are all rectangular and the same size (modulo edge effects).

So while the asymptotic behavior of the R-Tree is likely to be much better, I 
am more concerned with the behavior towards small data sizes...

The other important criterion is ease of implementation. Thanks to the SQLite 
R-Tree extension, both ways seem equally easy.

I guess I'll start with my initial idea of a 3 column index, and experiment 
with R-Tree a bit later.

Thanks for your suggestions.

Jean-Denis


On 3 mai 2011, at 19:42, David Garfield wrote:

 Actually, for what he wants, you don't need anything fancy.  A simple
 multi-column index is enough.
 
 The R-Tree is to allow queries of a sparse dataset, that might also
 have overlaps.
 
 So: A simple index for your background imagery.  An R-Tree index for
 the features added on top of your background imagery.
 
 --David Garfield
 
 Enrico Thierbach writes:
 Hi,
 
 I think an R Tree is what you are after.
 
 http://www.sqlite.org/rtree.html
 
 /eno
 
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Advice to choose an index for quad tree?

2011-05-03 Thread Jean-Denis Muys
Hi,

My application displays very large images at different zoom factors. I have 
tiled my images into individual tiles of a much smaller size. Each image has 
hundreds of tiles. The tiles will be used to interactively display the image 
and the speed of the zooming and panning is very important.

That's why I am thinking storing the tiles into an SQLite database. I am 
soliciting some advice on how to setup the index.

The main column for a Tile table will be its pixel blob. I can setup the rest 
of its structure as I wish. For example:

left: integer horizontal offset of the tile
top: integer vertical pixel offset of the tile
width: integer horizontal size of the tile
height: integer vertical size of the tile
shrink ratio: a power of two. How much the resolution of the tile has been 
reduced from the image resolution

width and height are typically constant, equal, and a power of two. The 
exception is at the right and bottom edges for the right-most and bottom-most 
rows of tiles for images that have non-power of 2 dimensions.

In memory, my data structure is a quad tree. The leaves of the quad tree point 
to elementary tiles: tiles that holds exact pixels from the image at the same 
resolution. At he next tree level, I take 4 tiles (arranged in a square) and 
make a new tile from them. This new tile is shrunk in resolution from its 4 
source tiles by a factor of 2 in each direction. That is, each of its pixels 
represent 4 pixels from the source tiles. I iterate at the next level. 
Conceptually, this process stops when level n has only one tile, which can be 
considered as a thumbnail of the original image.

When I need a tile, I know the topleft of the tile and I know the current zoom 
factor. The zoom factor can be 1.0 (actual pixels) or smaller (zooming out). 
From the zoom factor, I can easily compute the shrink ratio to use: I want to 
use those tiles that have just enough resolution, not better, as that would be 
wasteful and I am memory constrained (I can't load the full image in memory at 
any time). To find out the shrink ratio, it's basically 1/zoom factor, rounded 
to the correct adjacent power of two.

The set of tiles needed at any given time is those that cover (at least 
partially) the displayed rectangle. The number of needed tiles is constant for 
a given window size, since tiles have a constant size (not quite constant: edge 
and zoom rounding effects can affect slightly that number. at least there is a 
known upper bound to that number). That number is small, much smaller than the 
number of elementary tiles. The required tiles are adjacent: they form a 
connected rectangle.

Note that I can set up my Tile table differently if I want. For example, I can 
use row and column numbers rather than left and top since the pixel sizes are 
known.

My question is: is there any smart way to set up my table index? My naive idea 
is to have a composite index: shrink ratio/left/top (or ratio/row/column).

Is there any better? For example is there any reason to prefer either of 
ratio/left/top and ratio/top/left?

Is there any reason to consider smart encodings similar to geo hashing where 
each additional bit in an identifier encodes a smaller area?

I realize that since I have only hundreds - not millions - of tiles, this may 
sound like premature optimization. But I am not after optimization here (yet), 
only after sensible design.

Thanks,

Jean-Denis

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Advice to choose an index for quad tree?

2011-05-03 Thread Enrico Thierbach
Hi,

I think an R Tree is what you are after.

http://www.sqlite.org/rtree.html

/eno

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Advice to choose an index for quad tree?

2011-05-03 Thread David Garfield
Actually, for what he wants, you don't need anything fancy.  A simple
multi-column index is enough.

The R-Tree is to allow queries of a sparse dataset, that might also
have overlaps.

So: A simple index for your background imagery.  An R-Tree index for
the features added on top of your background imagery.

--David Garfield

Enrico Thierbach writes:
 Hi,
 
 I think an R Tree is what you are after.
 
 http://www.sqlite.org/rtree.html
 
 /eno
 
 ___
 sqlite-users mailing list
 sqlite-users@sqlite.org
 http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users