[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] constraint issue in 2.0.2 r10789
From:       Nicolas Ribot <nicolas.ribot () gmail ! com>
Date:       2012-12-17 15:36:17
Message-ID: CAGAwT=0=wdbVBjEGgGMBKwjYf8-g8Z4AQeGTcE17AQ=MryW_ZQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

If data contain both LINESTRING and MULTILINESTRING, then you should use
the MULTILINESTRING constraint. (this is the default shp2pgsql behavior, as
you noted).

Concerning the trigger, this is a 2 step operation:
First you create the function the trigger will call
Then you create a trigger on a table using this function:

-- function definition
create or replace function forceMulti() returns trigger as $$
    DECLARE

    BEGIN
        NEW.geom := st_multi(NEW.geom);
        RETURN NEW;
    END;
$$ LANGUAGE PLPGSQL;

-- then trigger creation
create trigger forceMulti_trigger
    BEFORE UPDATE OR INSERT
    ON profiles_line_wgs84
    FOR EACH ROW
EXECUTE PROCEDURE forceMulti();

insert into profiles_line_wgs84 (geom)
values ('srid=4326;LINESTRING(0 0, 1 1)'::geometry);

select st_astext(geom) from profiles_line_wgs84;

Nicolas

[Attachment #5 (text/html)]

Hi,<div><br></div><div>If data contain both LINESTRING and MULTILINESTRING, then you \
should use the MULTILINESTRING constraint. (this is the default shp2pgsql behavior, \
as you noted).</div><div><br></div><div>Concerning the trigger, this is a 2 step \
operation:</div> <div>First you create the function the trigger will \
call</div><div>Then you create a trigger on a table using this \
function:</div><div><br></div><div><div><font face="courier new, monospace">-- \
function definition</font></div> <div><font face="courier new, monospace">create or \
replace function forceMulti() returns trigger as $$</font></div><div><font \
face="courier new, monospace">    DECLARE</font></div><div><font face="courier new, \
monospace">    </font></div> <div><font face="courier new, monospace">    \
BEGIN</font></div><div><font face="courier new, monospace">        NEW.geom := \
st_multi(NEW.geom);</font></div><div><font face="courier new, monospace">        \
RETURN NEW;</font></div> <div><font face="courier new, monospace">    \
END;</font></div><div><font face="courier new, monospace">$$ LANGUAGE \
PLPGSQL;</font></div><div><font face="courier new, \
monospace"><br></font></div><div><font face="courier new, monospace">-- then trigger \
creation</font></div> <div><span style="font-family:&#39;courier \
new&#39;,monospace">create trigger forceMulti_trigger </span><br></div><div><font \
face="courier new, monospace">    BEFORE UPDATE OR INSERT</font></div><div><font \
face="courier new, monospace">    ON profiles_line_wgs84 </font></div> <div><font \
face="courier new, monospace">    FOR EACH ROW</font></div><div><font face="courier \
new, monospace"><span class="" style="white-space:pre">	</span>EXECUTE PROCEDURE \
forceMulti();</font></div><div><font face="courier new, monospace"><br> \
</font></div><div><font face="courier new, monospace">insert into profiles_line_wgs84 \
(geom)</font></div><div><font face="courier new, monospace"><span class="" \
style="white-space:pre">	</span>values (&#39;srid=4326;LINESTRING(0 0, 1 \
1)&#39;::geometry);</font></div> <div><font face="courier new, \
monospace"><br></font></div><div><font face="courier new, monospace">select \
st_astext(geom) from \
profiles_line_wgs84;</font></div></div><div><br></div><div>Nicolas</div>



_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic