Hi all. I think I now have a successful spatial query.
My database is quite simple with a single spt_Cities table with columns name, country and location where location is a point geometry.
It contains about 8,400 cities downloaded from Wikidata.
I created a spatial index on the location column.
The following statement retrieves cities within a circle of radius 1 which I believe is 1 degree of a point in the northwest of the United Kingdom.
SELECT
name, country,
ROUND( ST_Distance( MakePoint( -3, 55.0, 4326 ), location ), 2 ) AS distance
FROM spt_Cities
WHERE
spt_Cities.ROWID IN
(
--Is the city location within a bounding circle
SELECT ROWID FROM SpatialIndex WHERE
(
( f_table_name = 'spt_Cities') AND
( search_frame = MakeCircle( -3, 55.0, 1, 4326 ) )
)
) ORDER BY distance;
This returns me 3 cities which seem correct to me and it takes about 0.01seconds to execute on a fairly decent Windows laptop.
Do people agree this is the right approach for what I am trying to do?
Presumably I am going to be subject to the circle being distorted the further nearer the poles I go.
Next things for me to work on are testing it on a larger dataset and then using parameters so I can pass in a position and radius to search for.
Any thoughts anyone has welcome.
Best, Chris