Changeset 4763


Ignore:
Timestamp:
Nov 6, 2009 5:31:07 PM (7 years ago)
Author:
pramsey
Message:

Make ~= be a bounding box only operator and upgrade ST_Equals() and ST_OrderingEquals() to match the new behavior. Update regression tests to match new behavior. (#282) See also #289 for an odd quirk discovered while updating regression tests.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/postgis/lwgeom_gist.c

    r4736 r4763  
    3838Datum LWGEOM_overabove(PG_FUNCTION_ARGS);
    3939Datum LWGEOM_contained(PG_FUNCTION_ARGS);
     40Datum LWGEOM_samebox(PG_FUNCTION_ARGS);
    4041Datum LWGEOM_contain(PG_FUNCTION_ARGS);
    4142Datum LWGEOM_gist_compress(PG_FUNCTION_ARGS);
     
    375376}
    376377
     378PG_FUNCTION_INFO_V1(LWGEOM_samebox);
     379Datum LWGEOM_samebox(PG_FUNCTION_ARGS)
     380{
     381        PG_LWGEOM *lwgeom1 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
     382        PG_LWGEOM *lwgeom2 = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
     383        bool result;
     384        BOX2DFLOAT4 box1;
     385        BOX2DFLOAT4 box2;
     386
     387        POSTGIS_DEBUG(2, "GIST: LWGEOM_samebox --entry");
     388
     389        errorIfSRIDMismatch(pglwgeom_getSRID(lwgeom1), pglwgeom_getSRID(lwgeom2));
     390
     391        if ( ! (getbox2d_p(SERIALIZED_FORM(lwgeom1), &box1) && getbox2d_p(SERIALIZED_FORM(lwgeom2), &box2)) )
     392        {
     393                PG_FREE_IF_COPY(lwgeom1, 0);
     394                PG_FREE_IF_COPY(lwgeom2, 1);
     395                PG_RETURN_BOOL(FALSE);
     396        }
     397
     398        result = DatumGetBool(DirectFunctionCall2(BOX2D_same,
     399                                                  PointerGetDatum(&box1), PointerGetDatum(&box2)));
     400
     401        PG_FREE_IF_COPY(lwgeom1, 0);
     402        PG_FREE_IF_COPY(lwgeom2, 1);
     403
     404        PG_RETURN_BOOL(result);
     405}
    377406
    378407PG_FUNCTION_INFO_V1(LWGEOM_contained);
     
    564593        *recheck = false;
    565594       
    566         /* Our ~= operator (strategy 6) requires a re-check in order to
    567            function according to the documentation and past behavior.
    568            We will temporarily enable that behavior here. */
    569         if ( strategy == 6 )
    570                 *recheck = true;
    571595#endif
    572596
  • trunk/postgis/postgis.sql.in.c

    r4758 r4763  
    645645        LANGUAGE 'C' IMMUTABLE STRICT;
    646646
    647 CREATE OR REPLACE FUNCTION geometry_same(geometry, geometry)
     647CREATE OR REPLACE FUNCTION geometry_samebox(geometry, geometry)
    648648        RETURNS bool
    649         AS 'MODULE_PATHNAME', 'LWGEOM_same'
     649        AS 'MODULE_PATHNAME', 'LWGEOM_samebox'
    650650        LANGUAGE 'C' IMMUTABLE STRICT;
    651651
     
    706706
    707707CREATE OPERATOR ~= (
    708         LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_same,
     708        LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = geometry_samebox,
    709709        COMMUTATOR = '~=',
    710710        RESTRICT = eqsel, JOIN = eqjoinsel
     
    42184218        LANGUAGE 'C' IMMUTABLE STRICT;
    42194219
    4220 -- PostGIS equivalent function: Equals(geometry,geometry)
    4221 CREATE OR REPLACE FUNCTION ST_Equals(geometry,geometry)
     4220-- Availability: 1.5.0
     4221CREATE OR REPLACE FUNCTION _ST_Equals(geometry,geometry)
    42224222        RETURNS boolean
    42234223        AS 'MODULE_PATHNAME','geomequals'
    42244224        LANGUAGE 'C' IMMUTABLE STRICT
    42254225        COST 100;
     4226
     4227-- Availability: 1.2.1
     4228CREATE OR REPLACE FUNCTION ST_Equals(geometry,geometry)
     4229        RETURNS boolean
     4230        AS 'SELECT $1 ~= $2 AND _ST_Equals($1,$2)'
     4231        LANGUAGE 'SQL' IMMUTABLE STRICT;
    42264232
    42274233
  • trunk/postgis/sqlmm.sql.in.c

    r4750 r4763  
    149149-- ST_Y(geometry) - already defined.
    150150
    151 -- PostGIS equivalent function: ~=
     151-- Availability: 1.5.0
     152CREATE OR REPLACE FUNCTION _ST_OrderingEquals(geometry, geometry)
     153        RETURNS boolean
     154        AS 'MODULE_PATHNAME', 'LWGEOM_same'
     155        LANGUAGE 'C' IMMUTABLE STRICT
     156        COST 100;
     157
     158-- Availability: 1.3.0
    152159CREATE OR REPLACE FUNCTION ST_OrderingEquals(geometry, geometry)
    153160        RETURNS boolean
    154161        AS $$
    155         SELECT $1 && $2 AND $1 ~= $2
     162        SELECT $1 ~= $2 AND _ST_OrderingEquals($1, $2)
    156163        $$     
    157164        LANGUAGE 'SQL' IMMUTABLE STRICT;
  • trunk/regress/regress.sql

    r4750 r4763  
    9696
    9797select '65','POINT(1 1)'::GEOMETRY ~= 'POINT(1 1)'::GEOMETRY as bool;
     98select '65a',st_orderingequals('POINT(1 1)'::GEOMETRY,'POINT(1 1)'::GEOMETRY) as bool;
    9899select '66','POINT(1 1 0)'::GEOMETRY ~= 'POINT(1 1)'::GEOMETRY as bool;
     100select '66a',st_orderingequals('POINT(1 1 0)'::GEOMETRY,'POINT(1 1)'::GEOMETRY) as bool;
    99101select '67','POINT(1 1 0)'::GEOMETRY ~= 'POINT(1 1 0)'::GEOMETRY as bool;
     102select '67a',st_orderingequals('POINT(1 1 0)'::GEOMETRY,'POINT(1 1 0)'::GEOMETRY) as bool;
    100103
    101104select '68','MULTIPOINT(1 1,2 2)'::GEOMETRY ~= 'MULTIPOINT(1 1,2 2)'::GEOMETRY as bool;
     105select '68a',st_orderingequals('MULTIPOINT(1 1,2 2)'::GEOMETRY,'MULTIPOINT(1 1,2 2)'::GEOMETRY) as bool;
    102106select '69','MULTIPOINT(2 2, 1 1)'::GEOMETRY ~= 'MULTIPOINT(1 1,2 2)'::GEOMETRY as bool;
     107select '69a',st_orderingequals('MULTIPOINT(2 2, 1 1)'::GEOMETRY,'MULTIPOINT(1 1,2 2)'::GEOMETRY) as bool;
    103108
    104109select '70','GEOMETRYCOLLECTION(POINT( 1 2 3),POINT(4 5 6))'::GEOMETRY ~= 'GEOMETRYCOLLECTION(POINT( 4 5 6),POINT(1 2 3))'::GEOMETRY as bool;
     110select '70a',st_orderingequals('GEOMETRYCOLLECTION(POINT( 1 2 3),POINT(4 5 6))'::GEOMETRY,'GEOMETRYCOLLECTION(POINT( 4 5 6),POINT(1 2 3))'::GEOMETRY) as bool;
    105111select '71','MULTIPOINT(4 5 6, 1 2 3)'::GEOMETRY ~= 'GEOMETRYCOLLECTION(POINT( 4 5 6),POINT(1 2 3))'::GEOMETRY as bool;
     112select '71a',st_orderingequals('MULTIPOINT(4 5 6, 1 2 3)'::GEOMETRY,'GEOMETRYCOLLECTION(POINT( 4 5 6),POINT(1 2 3))'::GEOMETRY) as bool;
    106113select '72','MULTIPOINT(1 2 3, 4 5 6)'::GEOMETRY ~= 'GEOMETRYCOLLECTION(POINT( 4 5 6),POINT(1 2 3))'::GEOMETRY as bool;
     114select '72a',st_orderingequals('MULTIPOINT(1 2 3, 4 5 6)'::GEOMETRY,'GEOMETRYCOLLECTION(POINT( 4 5 6),POINT(1 2 3))'::GEOMETRY) as bool;
    107115select '73','MULTIPOINT(1 2 3, 4 5 6)'::GEOMETRY ~= 'GEOMETRYCOLLECTION(MULTIPOINT(1 2 3, 4 5 6))'::GEOMETRY as bool;
     116select '73a',st_orderingequals('MULTIPOINT(1 2 3, 4 5 6)'::GEOMETRY,'GEOMETRYCOLLECTION(MULTIPOINT(1 2 3, 4 5 6))'::GEOMETRY) as bool;
    108117
    109118
    110119select '74','LINESTRING(1 1,2 2)'::GEOMETRY ~= 'POINT(1 1)'::GEOMETRY as bool;
     120select '74a',st_orderingequals('LINESTRING(1 1,2 2)'::GEOMETRY,'POINT(1 1)'::GEOMETRY) as bool;
    111121select '75','LINESTRING(1 1, 2 2)'::GEOMETRY ~= 'LINESTRING(2 2, 1 1)'::GEOMETRY as bool;
     122select '75a',st_orderingequals('LINESTRING(1 1, 2 2)'::GEOMETRY,'LINESTRING(2 2, 1 1)'::GEOMETRY) as bool;
    112123select '76','LINESTRING(1 1, 2 2)'::GEOMETRY ~= 'LINESTRING(1 1, 2 2, 3 3)'::GEOMETRY as bool;
     124select '76a',st_orderingequals('LINESTRING(1 1, 2 2)'::GEOMETRY,'LINESTRING(1 1, 2 2, 3 3)'::GEOMETRY) as bool;
    113125
    114126--- operator testing (testing is on the BOUNDING BOX (2d), not the actual geometries)
  • trunk/regress/regress_expected

    r4750 r4763  
    7777HINT:  "MULTIPOINT(1 1, 2 2" <-- parse error at position 19 within geometry
    787865|t
    79 66|f
     7965a|t
     8066|t
     8166a|f
    808267|t
     8367a|t
    818468|t
     8568a|t
    828669|t
     8769a|t
    838870|t
    84 71|f
    85 72|f
    86 73|f
     8970a|t
     9071|t
     9171a|f
     9272|t
     9372a|f
     9473|t
     9573a|f
    879674|f
    88 75|f
     9774a|f
     9875|t
     9975a|f
    8910076|f
     10176a|f
    9010277|t
    9110378|t
Note: See TracChangeset for help on using the changeset viewer.