So I am getting much closer to a working implementation in PostGIS, but have just run into an issue which I am assuming is my misunderstanding something...
https://github.com/pramsey/postgis/blob/92268c94f3aa1fc63a2941f2b451be15b28662cf/postgis/gserialized_supportfn.c#L287 I had what seemed to be working code except for a couple rare cases, but when I fixed those cases it turned out that I had a major problem: building a <var> OP <const> expression works fine, but building a <const> OP <var> expression returns me an error. create table f as select st_makepoint(200*random() - 100, 200*random() - 100) as g from generate_series(0, 100000); create index f_g_x on f using gist (g); explain select * from baz where st_coveredby('POINT(5 0)', geom); explain select * from f where st_coveredby(g, 'POINT(5 0)'); QUERY PLAN ----------------------------------------------------------------------------------- Bitmap Heap Scan on f (cost=13.36..314.58 rows=33334 width=32) Filter: st_coveredby(g, '010100000000000000000014400000000000000000'::geometry) -> Bitmap Index Scan on f_g_x (cost=0.00..5.03 rows=100 width=0) Index Cond: (g @ '010100000000000000000014400000000000000000'::geometry) postgis=# explain select * from f where st_coveredby('POINT(5 0)', g); ERROR: index key does not match expected index column Any thoughts? P