Skip to Main Content

Oracle Database Free

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ANYINTERACT spatial query in 23ai and 21c with a polygon touching both poles returns invalid results

Chris SlaterApr 5 2025

When selecting features in an area that touches both poles, some invalid points are returned. This query used to work with 18c, which my team upgraded from. I've tried both 23ai and 21c.

First, setting up a test table:

create table FEATURE
(
ID NUMBER(19) not null primary key,
GEOMETRY MDSYS.SDO_GEOMETRY not null
);

insert into MDSYS.USER_SDO_GEOM_METADATA (table_name, column_name, diminfo, srid)
values ('FEATURE', 'GEOMETRY', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('Longitude', -180, 180, 0.05), MDSYS.SDO_DIM_ELEMENT('Latitude', -90, 90, 0.05)), 4326);

create index UFN_FEATURE_SPX on FEATURE (GEOMETRY) indextype is MDSYS.SPATIAL_INDEX;

Insert a point:

insert into FEATURE (ID, GEOMETRY) values (1, SDO_GEOMETRY('POINT (177.56667 -68.31667)', 4326));

Sanity check that point exists and is located where we expect it:

select F.ID ID, SDO_UTIL.TO_WKTGEOMETRY(F.GEOMETRY) GEOMETRY from FEATURE F;

1,POINT (177.56667 -68.31667)

Query in an area where the point does not exist, in a box that includes the poles:

select F.ID ID, SDO_UTIL.TO_WKTGEOMETRY(F.GEOMETRY) GEOMETRY from FEATURE F
where SDO_RELATE(
    F.GEOMETRY,
    SDO_GEOMETRY('POLYGON ((180 90, 179 90, 179 -90, 180 -90, 180 90))', 4326),
    'mask=ANYINTERACT')
= 'TRUE';

1,POINT (177.56667 -68.31667)

That point is found, incorrectly.

If I change the query to get close to the poles, but not touch:

select F.ID ID, SDO_UTIL.TO_WKTGEOMETRY(F.GEOMETRY) GEOMETRY from FEATURE F
where SDO_RELATE(
    F.GEOMETRY,
    SDO_GEOMETRY('POLYGON ((180 89.99, 179 89.99, 179 -89.99, 180 -89.99, 180 89.99))',   4326),
    'mask=ANYINTERACT')
= 'TRUE';

There are no results, as expected.

Similarly, if the query area touches one pole, but not the other:

select F.ID ID, SDO_UTIL.TO_WKTGEOMETRY(F.GEOMETRY) GEOMETRY from FEATURE F
where SDO_RELATE(
    F.GEOMETRY,
    SDO_GEOMETRY('POLYGON ((180 89.99, 179 89.99, 179 -90, 180 -90, 180 89.99))', 4326),
    'mask=ANYINTERACT')
= 'TRUE';

Or

select F.ID ID, SDO_UTIL.TO_WKTGEOMETRY(F.GEOMETRY) GEOMETRY from FEATURE F
where SDO_RELATE(
    F.GEOMETRY,
    SDO_GEOMETRY('POLYGON ((180 90, 179 90, 179 -89.99, 180 -89.99, 180 90))', 4326),
'mask=ANYINTERACT')
= 'TRUE';

No results are returned, as expected.

Comments
Post Details
Added on Apr 5 2025
9 comments
271 views