spatialite使用空间索引

spatialite提供了R*tree索引。

spatialite的空间索引需要显式的调用,而不像postGIS等那样默认调用。spatialite的空间索引是基于sqlite的virtual table技术实现的。
要使用spatialite的空间索引,首先要创建SpatialIndex表

CREATE VIRTUAL TABLE SpatialIndex USING VirtualSpatialIndex();

创建索引:

SELECT CreateSpatialIndex('councils','Geometry')

使用索引:

SELECT c.Name AS Name, SUM(s.sales) AS "Total Sales"
FROM councils AS c, stores AS s
WHERE ST_Contains(c.Geometry, s.Geometry) AND
s.ROWID IN
(SELECT ROWID FROM SpatialIndex WHERE f_table_name='stores' AND search_frame=c.Geometry)
GROUP BY c.pk_uid;

注意,空间索引的显式调用

   s.ROWID IN
(SELECT ROWID FROM SpatialIndex WHERE f_table_name='stores' AND search_frame=c.Geometry)

禁用索引

   SELECT DisableSpatialIndex('local_councils', 'geometry');
This entry was posted in gis.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">