[GRASS-dev] v.what and spatial index

Moritz Lennert mlennert at club.worldonline.be
Wed Sep 6 11:56:16 EDT 2006


Moritz Lennert wrote:
> Hello,
> 
> Trying to use v.what on a fairly large file (124658 areas) I noticed 
> that it rebuilds the spatial index at every usage, obviously making it 
> extremely inefficient.
> 
> This is discussed briefly in bug #3193:
> 
> http://www.intevation.de/rt/webrt?serial_num=3193&display=History
> 
> And Radim mentions spatial index in his Vector ToDo document:
> 
> http://freegis.org/cgi-bin/viewcvs.cgi/grass6/doc/vector/TODO?rev=HEAD&content-type=text/vnd.viewcvs-markup 
> 
> 
> This is a serious issue when you have to query such large maps frequently.
> 
> 
> Radim wrote at the time:
> 
> "Writing of the index to disk could be enabled by GRASS variable and/or
> v.build option. But that changes vector format which must be supported
> in all next version. Before we enable writing of spatial index, it
> should be revised if the format can be changed to save some space."
> 
> I think that seen the fact that we are quickly moving to new releases 
> and then to further development, it might be the time to take this up 
> again in order to plan ahead.
> 
> In the bug report, Hamish proposes to create the spatial index once per 
> session and erase it when leaving the session. I don't know if space is 
> such as problem, but for me even this seems inefficient. Once the index 
> is created it should stay there even when leaving the session. Or at 
> least there should be a configurable option (maybe a GRASS environment 
> variable) to leave the index files in place.
> 
> Any reactions ?
> 


I have looked into the issue a bit more, and I see the following:

v.what calls Vect_build_spatial_index()

This function checks whether the spatial index is already available in 
memory (checking whether Map->plus.Spidx_built is set) and if not, goes 
on to call Vect_build_sidx_from_topo() which builds the actual index.

IIUC, the memory holding the index is released automatically when v.what 
calls exit().

This means that for every v.what call the index needs to be rebuilt.

The discussion so far has been about putting the spatial index into a 
file and then either erasing that file when the GRASS session is closed, 
or even keeping it across sessions.

But, would it be possible to keep it in memory after v.what exits (or 
whatever program is first to build the index in a session) and erase it 
at the end of the GRASS session ? Or this is impossible with GRASS' 
modular structure ?

Moritz




More information about the grass-dev mailing list