SpatiaLite
4.3.0
|
This is a sample C source showing how to use the SQLite / SpatiaLite Spatial Index [RTree].It follows on from demo1.c.
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).
$ ./demo3 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: 1.910] insert row: 50000 [elapsed time: 4.050] insert row: 75000 [elapsed time: 6.270] insert row: 100000 [elapsed time: 8.460] insert row: 125000 [elapsed time: 10.740] insert row: 150000 [elapsed time: 12.910] insert row: 175000 [elapsed time: 15.080] insert row: 200000 [elapsed time: 17.350] insert row: 225000 [elapsed time: 19.610] insert row: 250000 [elapsed time: 21.890] insert row: 275000 [elapsed time: 24.170] insert row: 300000 [elapsed time: 26.380] insert row: 325000 [elapsed time: 28.650] insert row: 350000 [elapsed time: 30.900] insert row: 375000 [elapsed time: 33.130] insert row: 400000 [elapsed time: 35.340] insert row: 425000 [elapsed time: 37.540] insert row: 450000 [elapsed time: 39.760] insert row: 475000 [elapsed time: 41.980] insert row: 500000 [elapsed time: 44.220] insert row: 525000 [elapsed time: 46.500] insert row: 550000 [elapsed time: 48.740] insert row: 575000 [elapsed time: 50.960] insert row: 600000 [elapsed time: 53.190] insert row: 625000 [elapsed time: 55.430] insert row: 650000 [elapsed time: 57.670] insert row: 675000 [elapsed time: 59.900] insert row: 700000 [elapsed time: 62.130] insert row: 725000 [elapsed time: 64.400] insert row: 750000 [elapsed time: 66.660] insert row: 775000 [elapsed time: 68.900] insert row: 800000 [elapsed time: 71.140] insert row: 825000 [elapsed time: 73.410] insert row: 850000 [elapsed time: 75.670] insert row: 875000 [elapsed time: 77.940] insert row: 900000 [elapsed time: 80.230] insert row: 925000 [elapsed time: 82.540] insert row: 950000 [elapsed time: 84.840] insert row: 975000 [elapsed time: 87.150] insert row: 1000000 [elapsed time: 89.450] performing test#0 - not using Spatial Index Count(*) = 25 [elapsed time: 1.2700] performing test#1 - not using Spatial Index Count(*) = 25 [elapsed time: 1.2700] performing test#2 - not using Spatial Index Count(*) = 25 [elapsed time: 1.2900] performing test#0 - using the R*Tree Spatial Index Count(*) = 25 [elapsed time: 0.0000] performing test#1 - using the R*Tree Spatial Index Count(*) = 25 [elapsed time: 0.0000] performing test#2 - using the R*Tree Spatial Index Count(*) = 25 [elapsed time: 0.0000] sample successfully terminated
Note the significant difference in elapsed time associated with use of an appropriate index.