On Thu, 8 Aug 2024 22:59:11 +0100,
ckgoo...@gmail.com wrote:
> How can I get the results I need when polygons cross the 180 degree
> meridian?
>
Hi Chris,
always remember that the SpatialIndex is a very efficient and very fast
filter, but that it's also very imprecise because it takes into
consideration exclusively the MBRs and not the Geometries as such.
The WHERE clause of your Spatial Queries should never be limited to
simply query the SpatialIndex.
It must also contain a function that checks whether a real intersection
exists between the two Geometries.
Example #1 (wrong)
==================
SELECT a, b, c
FROM some_table
WHERE rowid IN (
SELECT rowid FROM SpatialIndex
WHERE f_table_name = 'some_table'
AND search_frame = MakePoint(...));
Note: the inner query on the Spatial Index may contain rows
presenting an intersection between the MBRs but not between
the Geometries themselves.
Example #2 (correct)
====================
SELECT a, b, c
FROM some_table
WHERE ST_Intersects(geom, MakePoint(...)) = 1
AND rowid IN (
SELECT rowid FROM SpatialIndex
WHERE f_table_name = 'some_table'
AND search_frame = MakePoint(...));
Note: in this second case, however, ST_Intersects() will
verify the presence of a real intersection between the
two geometries, thus refining the resultset until it's
accurate.
This requires a little extra work, but the negative
impact on speed is very modest because you are operating
on a resultset that's already filtered by the SpatialIndex.
bye Sandro