0

I am using SpatiaLite (or rather, its WebAssembly port SpatiaSQL.js) in a web application.

A use-case in this application is that the user wants to query point geometries (>500k of them, anywhere in the world) against a single (multi-)polygon geometry, filtering points which are not inside said geometry.

I don't know the (multi-)polygon in advance, because it is yielded by a dynamic mechanism. It could be e.g. a country, province, city, or a hand-drawn custom polygon.

Using a simple query with SpatiaLite's Within function works great. Performance is also great for small (multi-)polygons, such as a city. However, when querying against, say, Australia (a huge multi-polygon with many parts), performance suffers.

I am tied to SpatiaLite or a custom solution because most spatial database solutions cannot run in client-side JavaScript.

Sorry if this is an obvious question - I didn't find any similar questions so far.

Any thoughts on how to speed this up? Some loss of accuracy is acceptable.

Sander Vocke
  • 125
  • 5
  • FYI, some things I considered: I've seen a lot of related questions about SpatiaLite using `RTree`s to speed up similar problems. The main difference I see is me not knowing the polygon in advance. Maybe an `RTree` cannot be made in this case. However, I could imagine that it would still be possible to have a tree-like structure which could quickly reject any far points.. I imagine maybe some kind of raster can be made, which could maybe somehow be used to quickly reject points that are not even close. Another thing I am thinking of is clustering points prior to the query. – Sander Vocke Feb 04 '20 at 15:37
  • I ended up going with a non-Spatialite solution: KDBush in Javascript. – Sander Vocke Feb 06 '20 at 22:29

0 Answers0