SpatiaLite
4.2.0
|
This is a sample C source showing how to use the SQLite / SpatiaLite Spatial Index [MbrCache].It is very similar to demo3.c, but uses a different indexing approach
The main steps in this example are:
The typical output of this demo is shown below (where test.sqlite does not exist before the run).
$ ./demo4 test.sqlite SQLite version: 3.7.4 SpatiaLite version: 3.0.0-beta1 now we are going to insert 1 million POINTs; wait, please ... insert row: 25000 [elapsed time: 0.370] insert row: 50000 [elapsed time: 0.820] insert row: 75000 [elapsed time: 1.280] insert row: 100000 [elapsed time: 1.750] insert row: 125000 [elapsed time: 2.210] insert row: 150000 [elapsed time: 2.690] insert row: 175000 [elapsed time: 3.180] insert row: 200000 [elapsed time: 3.670] insert row: 225000 [elapsed time: 4.210] insert row: 250000 [elapsed time: 4.720] insert row: 275000 [elapsed time: 5.240] insert row: 300000 [elapsed time: 5.780] insert row: 325000 [elapsed time: 6.330] insert row: 350000 [elapsed time: 6.910] insert row: 375000 [elapsed time: 7.510] insert row: 400000 [elapsed time: 8.120] insert row: 425000 [elapsed time: 8.750] insert row: 450000 [elapsed time: 9.420] insert row: 475000 [elapsed time: 10.120] insert row: 500000 [elapsed time: 10.850] insert row: 525000 [elapsed time: 11.610] insert row: 550000 [elapsed time: 12.390] insert row: 575000 [elapsed time: 13.200] insert row: 600000 [elapsed time: 14.040] insert row: 625000 [elapsed time: 14.900] insert row: 650000 [elapsed time: 15.790] insert row: 675000 [elapsed time: 16.700] insert row: 700000 [elapsed time: 17.650] insert row: 725000 [elapsed time: 18.620] insert row: 750000 [elapsed time: 19.610] insert row: 775000 [elapsed time: 20.650] insert row: 800000 [elapsed time: 21.700] insert row: 825000 [elapsed time: 22.760] insert row: 850000 [elapsed time: 23.860] insert row: 875000 [elapsed time: 25.060] insert row: 900000 [elapsed time: 26.290] insert row: 925000 [elapsed time: 27.480] insert row: 950000 [elapsed time: 28.760] insert row: 975000 [elapsed time: 30.020] insert row: 1000000 [elapsed time: 31.280] performing test#0 - not using Spatial Index Count(*) = 25 [elapsed time: 1.2500] performing test#1 - not using Spatial Index Count(*) = 25 [elapsed time: 1.2400] performing test#2 - not using Spatial Index Count(*) = 25 [elapsed time: 1.2400] performing test#0 - using the MBR cache Spatial Index Count(*) = 25 [elapsed time: 0.0000] performing test#1 - using the MBR cache Spatial Index Count(*) = 25 [elapsed time: 0.0000] performing test#2 - using the MBR cache Spatial Index Count(*) = 25 [elapsed time: 0.0000] sample successfully terminated
As for demo3.c, note the significant speed difference between the indexed and non-indexed queries.