[postgis-devel] [topology] missing = operator for topogeometry

Rémi Cura remi.cura at gmail.com
Wed Oct 23 02:39:14 PDT 2013


Some code :
_first a cast from topogeometry to int[]
_second an = operator for topogeometry, there is 2 possibilities regarding
the behavior with NULL value.

my prefered behavior is that NULL is just another int value
the other behavior (commented code) is the int=int behavior with null
value, that is when one or more null, returns null.

I tested manually both.
Comments welcome
Cheers,
Rémi-C

_first a cast from topogeometry to int[]


--creating a cast from topology.topogeom to int[]
DROP FUNCTION IF EXISTS  topology.topogeometry_CastToIntArr(tg1
topology.topogeometry);
CREATE FUNCTION topology.topogeometry_CastToIntArr(tg1
topology.topogeometry)
    RETURNS int[] AS
    $BODY$
-- This function rast a topology.topogeom into an int[]
DECLARE
BEGIN
RETURN ARRAY[(tg1).topology_id, (tg1).layer_id,(tg1).id,(tg1).type];
END;
    $BODY$
LANGUAGE plpgsql IMMUTABLE;

SELECT
 topology.topogeometry_CastToIntArr((NULL,2,3,4)::topology.topogeometry);
CREATE CAST (topology.topogeometry AS int[])
    WITH FUNCTION  topology.topogeometry_CastToIntArr(topology.topogeometry)
    AS IMPLICIT ;

SELECT (1,2,3,4)::topogeometry::int[];


_second an = operator for topogeometry

--creating the egal operator for topology.topogeometry type
DROP FUNCTION IF EXISTS  topology.topogeometry_egal(tg1
topology.topogeometry,tg2 topology.topogeometry) CASCADE;
CREATE FUNCTION topology.topogeometry_egal(tg1 topology.topogeometry,tg2
topology.topogeometry)
    RETURNS boolean AS
    $BODY$
-- This function returns true if every field of topogeom1 are egal to
topogeom2 (int = meaning) in the same order, false else.
--returns null if any field is NULL, whatever the others.
DECLARE
BEGIN
-- RETURN
-- (tg1).topology_id=(tg2).topology_id
-- AND (tg1).layer_id=(tg2).layer_id
-- AND (tg1).id=(tg2).id
-- AND (tg1).type=(tg2).type;
RETURN tg1::int[]=tg2::int[];
END;
    $BODY$
LANGUAGE plpgsql IMMUTABLE;

CREATE OPERATOR = (
    leftarg = topology.topogeometry,
    rightarg = topology.topogeometry,
    procedure = topology.topogeometry_egal,
    commutator = =
);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20131023/7887b1c5/attachment.html>


More information about the postgis-devel mailing list