[postgis-users] Strange behaviour of = operator

Steffen Macke sdteffen at gmail.com
Wed Feb 8 03:27:10 PST 2006


Thanks, Strk and Mark,

I've used the code below with success.
I know that it's a performance hit, but isn't it worth
considering to have PostGIS out-of-the box with this
more exact comparion operators? Whoever needs speed will use
GiST indexes in his queries.

Regards,

Steffen

DROP OPERATOR CLASS btree_geometry_ops USING btree;
DROP OPERATOR = (geometry, geometry);

create or replace function btree_equals_opclass(geometry, geometry)
returns integer as $$
 begin
 if equals($1,$2) then
   return 0;
 else
   if area($1) < area($2) then
       return -1;
   else
     return 1;
   end if;
 end if;
end;
$$
language plpgsql;

CREATE OPERATOR = (
  LEFTARG = geometry, RIGHTARG = geometry, PROCEDURE = equals,
  COMMUTATOR = '=', -- we might implement a faster negator here
  RESTRICT = contsel, JOIN = contjoinsel
);

CREATE OPERATOR CLASS btree_geometry_ops DEFAULT
  FOR TYPE geometry USING btree AS
  OPERATOR 1  <,
  OPERATOR 2  <=,
  OPERATOR 3  =,
  OPERATOR 4  >=,
  OPERATOR 5  >,
  FUNCTION 1  btree_equals_opclass(geometry, geometry);



More information about the postgis-users mailing list