<div dir="ltr"><div><div>Ola Marco,<br><br></div>Para fazeres isso tens de implementar um trigger na tua base de dados. Estes comandos deverao funcionar, apenas tens de mudar o nome dos campos:<br><font><br>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:rgb(0,176,80)">-- Cr</span><span style="font-family:Arial;color:rgb(0,176,80)">iar o trigger<br></span></font></p><font>



</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue">CREATE </span><span style="font-family:Arial;color:blue">OR REPLACE FUNCTION </span><span style="font-family:Arial;color:black">computing_area</span><span style="font-family:Arial;color:black">()<span> 
</span></span><span style="font-family:Arial;color:black"><span>  </span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span>RETURNS
</span><span style="font-family:Arial;color:blue">TRIGGER </span><span style="font-family:Arial;color:blue">AS</span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:black"><span>   
</span>$</span><span style="font-family:Arial;color:blue">BODY</span><span style="font-family:Arial;color:black">$</span><span style="font-family:Arial;color:blue"><span>  
</span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span></span><span style="font-family:Arial;color:blue">BEGIN<span>             </span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span><span> </span></span><span style="font-family:Arial;color:blue"><span>   </span></span><span style="font-family:Arial;color:blue">NEW.area</span><span style="font-family:Arial;color:blue"> </span><span style="font-family:Arial;color:blue">:=
ROUND((</span><span style="font-family:Arial;color:blue">st_area</span><span style="font-family:Arial;color:blue">(</span><span style="font-family:Arial;color:blue">NEW.geom</span><span style="font-family:Arial;color:blue">))::numeric,2);<span>        </span><span>  </span></span><span style="font-family:Arial;color:blue"><span>    </span>RETURN </span><span style="font-family:Arial;color:blue">NEW;<span>   </span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span></span><span style="font-family:Arial;color:blue">END;</span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:black"><span>   
</span>$</span><span style="font-family:Arial;color:blue">BODY</span><span style="font-family:Arial;color:black">$</span><span style="font-family:Arial;color:blue"><span>  
</span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue">LANGUAGE </span><span style="font-family:Arial;color:black">'</span><span style="font-family:Arial;color:black">plpgsql</span><span style="font-family:Arial;color:black">'</span></font></p><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:black"><br></span></font></p><font>



</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:rgb(0,176,80)">-- </span><span style="font-family:Arial;color:rgb(0,176,80)">implementar o trigger<br></span></font></p><font>



</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue">CREATE TRIGGER</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:black">calculate_area</span><span style="font-family:Arial;color:black"> </span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span>BEFORE</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:blue">INSERT</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:blue">OR</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:blue">UPDATE<span>  </span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span>ON</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:black">landplot</span><span style="font-family:Arial;color:black"><span>  </span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span>FOR</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:blue">EACH</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:blue">ROW<span>  </span></span></font></p><font>

</font><p style="margin-top:0pt;margin-bottom:0pt;text-align:left;direction:ltr;vertical-align:baseline"><font><span style="font-family:Arial;color:blue"><span>  </span>EXECUTE</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:blue">PROCEDURE</span><span style="font-family:Arial;color:black"> </span><span style="font-family:Arial;color:black">computing_area</span><span style="font-family:Arial;color:black">();</span></font></p>

<br></div><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-02 10:47 GMT+02:00  <span dir="ltr"><<a href="mailto:nmrcortes@gmail.com" target="_blank">nmrcortes@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div dir="ltr" style="font-family:'Calibri','Segoe UI','Meiryo','Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','sans-serif';font-size:12pt"><div><br></div><div><div>Quero criar uma coluna numa tabela (polígono) no PostGIS que calcule a área automaticamente e que a mantenha actualizada sempre que se altere a geometria do polígono no Qgis.</div><div><br></div><div>Com o seguinte SQL:<br>UPDATE "Parcela" SET AreaHectares=ST_AREA(geom)/10000;  <br>FROM<br>  "Parcela"</div><div><br></div><div>Faz a actualização da área mas tenho que fazer o Update sempre que altero a geometria.<br>Há alguma forma de fazer isto automaticamente?</div><div><br></div><div>Obrigado<br>Nuno Cortês<br></div><div><br></div><div><br></div></div></div>
</div>

<br>_______________________________________________<br>
Portugal mailing list<br>
<a href="mailto:Portugal@lists.osgeo.org">Portugal@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/portugal" target="_blank">http://lists.osgeo.org/mailman/listinfo/portugal</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">..................................<br>André Mano<br><a style="color:rgb(0,0,153)" href="http://opussig.blogspot.com/" target="_blank"><font size="1">http://opussig.blogspot.com/</font></a><br></div>
</div>