[postgis-tickets] [PostGIS] #4088: Erroneous definition of relative position operators in PostGIS

PostGIS trac at osgeo.org
Tue May 15 04:21:06 PDT 2018


#4088: Erroneous definition of relative position operators in PostGIS
----------------------+---------------------------
 Reporter:  ezimanyi  |      Owner:  pramsey
     Type:  defect    |     Status:  new
 Priority:  medium    |  Milestone:  PostGIS 2.4.5
Component:  postgis   |    Version:  2.4.x
 Keywords:            |
----------------------+---------------------------
 I think there is a problem in the definition of the &<, &>, &<|, and |&>
 operators in PostGIS since at the SQL level they are defined as being
 commutative by pairs (e.g., &< are &> commutative) and this should not be
 the case. As a comparison, the corresponding range operators are not
 commutative.

 {{{
 select oid, * from pg_operator
 where (oprname = '&<' or oprname = '&>' or oprname = '&<|' or oprname =
 '|&>')
 and (oprcode::text like 'geometry%' or oprcode::text like 'range%')

 3895;"&<";11;10;"b";f;f;3831;3831;16;0;0;"range_overleft";"rangesel";"scalarltjoinsel"
 3896;"&>";11;10;"b";f;f;3831;3831;16;0;0;"range_overright";"rangesel";"scalargtjoinsel"
 2221902;"&>";2200;16386;"b";f;f;2221809;2221809;16;2221903;0;"geometry_overright";"positionsel";"positionjoinsel"
 2221903;"&<";2200;16386;"b";f;f;2221809;2221809;16;2221902;0;"geometry_overleft";"positionsel";"positionjoinsel"
 2221908;"|&>";2200;16386;"b";f;f;2221809;2221809;16;2221909;0;"geometry_overabove";"positionsel";"positionjoinsel"
 2221909;"&<|";2200;16386;"b";f;f;2221809;2221809;16;2221908;0;"geometry_overbelow";"positionsel";"positionjoinsel"
 }}}

 As can be seen in their C definition in PostGIS

 {{{
 static bool box2df_overleft(const BOX2DF *a, const BOX2DF *b)
 {
         if ( ! a || ! b ) return FALSE; /* TODO: might be smarter for
 EMPTY */

         /* a.xmax <= b.xmax */
         return a->xmax <= b->xmax;
 }

 static bool box2df_overright(const BOX2DF *a, const BOX2DF *b)
 {
         if ( ! a || ! b ) return FALSE; /* TODO: might be smarter for
 EMPTY */

         /* a.xmin >= b.xmin */
         return a->xmin >= b->xmin;
 }

 }}}

 if a &< b (that is a->xmax <= b->xmax) it is not necessarily the case that
 b &> a (that is b->xmin >= x->xmin).

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4088>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list