SQLite Forum

another performance question related to `geopoly`
Login
I have a similar use case which selects lines within proximity of a point. 
I used RTrees for this and when GeoPoly became available I tried that but as you did, found it far too slow. However, I didn't need it because I wasn't dealing with polygons as you aren't.

Although GeoPoly and RTrees are related and one is dependent on the other, there is a difference and you should ask yourself if you really need GeoPoly and maybe a straight RTree would be better and it would certainly be faster. Polygons after all, are more complex and require much more processing.

It's likely that neither of these functions will perform all the functions you need and only serve as an index to narrow the search so that your application can process the results. A straight RTree query will be more approximate than GeoPoly function because it is all rectangles, but again it depends on your needs if that will suffice.

Constructing the index is as simple as providing max/min coordinates half the required size less and more than the point coords, and the rest is done with the query.

I would encourage you to have a good read of the [RTree](https://sqlite.org/rtree.html) page to see if that will work for you, in particular the simplified new Auxiliary Columns section so that subqueries are not required in the WHERE clause for the index.

If you need more then perhaps something like [Spatialite](http://www.gaia-gis.it/gaia-sins/) might be useful, which is purpose built for the task and provides a very quick KNN function.