CREATE TABLE runways (
airport_id text,
rwy_ident text,
length integer,
width integer,
base_ident varchar,
base_lat_end real,
base_long_end real,
base_brng integer,
recp_ident varchar,
recp_lat_end real,
recp_long_end real,
recp_brng integer,
source varchar,
PRIMARY KEY (airport_id, rwy_ident)
);
SELECT AddGeometryColumn('runways','runway_polygon', 4326, 'POLYGON', 2, 0);
SELECT CreateSpatialIndex('runways','runway_polygon');
spatialite> select airport_id, rwy_ident, AsText(runway_polygon) from runways limit 5;
00C|01/19|POLYGON((-107.872333 37.196775, -107.872172 37.196726, -107.866057 37.209582, -107.866218 37.20963))
00CA|04/22|POLYGON((-116.89309 35.349381, -116.89291 35.349219, -116.87791 35.360219, -116.87809 35.360381))
00CL|16/34|POLYGON((-121.763332 39.432016, -121.763474 39.432017, -121.763524 39.422361, -121.763382 39.422361))
00F|10/28|POLYGON((-105.464784 45.473207, -105.464913 45.473022, -105.449494 45.467732, -105.449365 45.467916))
00M|16/34|POLYGON((-89.236822 31.957662, -89.236975 31.957618, -89.233827 31.949818, -89.233675 31.949862))
As you can see the query doesn't include any other terms that could've confused sqlite into picking a bad strategy for implementing the query. "Explain" with ".scanstats on" produces the same results with or without the index.
The polygons seem OK, and as I said the queries do work. Here's a bit of an extract from the runways table:spatialite> select airport_id, rwy_ident, AsText(runway_polygon) from runways limit 5;
00C|01/19|POLYGON((-107.872333 37.196775, -107.872172 37.196726, -107.866057 37.209582, -107.866218 37.20963))
00CA|04/22|POLYGON((-116.89309 35.349381, -116.89291 35.349219, -116.87791 35.360219, -116.87809 35.360381))
00CL|16/34|POLYGON((-121.763332 39.432016, -121.763474 39.432017, -121.763524 39.422361, -121.763382 39.422361))
00F|10/28|POLYGON((-105.464784 45.473207, -105.464913 45.473022, -105.449494 45.467732, -105.449365 45.467916))
00M|16/34|POLYGON((-89.236822 31.957662, -89.236975 31.957618, -89.233827 31.949818, -89.233675 31.949862))
I figure I've made some rookie mistake.
Can someone tell me what I did wrong? (I can make the database available and a little Tcl program that demonstrates the performance, if needed.)
SELECT * FROM runwaysWHERE ( ROWID IN ( SELECT ROWID FROM SpatialIndex WHERE ( (f_table_name = 'runways') AND (f_geometry_column = 'runway_polygon') AND (search_frame = MakePoint(-95.346824,29.969761)) ) ));
Regards...Karl
"INSERT OR REPLACE INTO runways (airport_id, rwy_ident, length, width, base_ident, base_lat_end, base_long_end, base_brng, recp_ident, recp_lat_end, recp_long_end, recp_brng, source, runway_polygon) VALUES (:row(airport_id), :row(rwy_ident), :row(length), :row(width), :row(base_ident), :row(base_lat_end), :row(base_long_end), :base_brng, :row(recp_ident), :row(recp_lat_end), :row(recp_long_end), :recp_brng, :row(source), ST_GeomFromText(:polygon, 4326))"