<html style="direction: ltr;">
  <head>
    <meta content="text/html; charset=windows-1255"
      http-equiv="Content-Type">
    <style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
  </head>
  <body style="direction: ltr;"
    bidimailui-detected-decoding-type="preferred-charset"
    bgcolor="#FFFFFF" text="#660000">
    <div class="moz-cite-prefix">On 12/11/2012 13:00, Bernd Vogelgesang
      wrote:<br>
    </div>
    <blockquote cite="mid:op.wnnp7fq2l2i25i@bernd-aspire-5741g"
      type="cite">
      <blockquote type="cite">Here's some "witchcraft"
        <br>
        <br>
        In a spatialite DB, I have a polygon table "fields". I Added an
        integer column "val"
        <br>
        and a column "result_val" of type real. Then I set up this
        trigger:
        <br>
        <br>
        CREATE TRIGGER update_result_trig
        <br>
        AFTER UPDATE ON "fields"
        <br>
        BEGIN
        <br>
        UPDATE fields
        <br>
        SET result_val=(val*ST_Area(geometry))
        <br>
        WHERE ROWID=NEW.ROWID;
        <br>
        END
        <br>
        <br>
        I loaded the spatialite polygon layer into QGIS and set the
        "result_val"
        <br>
        attribute as a label for each polygon. Now I started editing. At
        each click of
        <br>
        the save button the label, representing the result_val, changes.
        Seems to work
        <br>
        nicely.
        <br>
        <br>
        HTH
        <br>
        Micha
        <br>
        <br>
      </blockquote>
      <br>
      Thanks a lot, Micha!
      <br>
      <br>
      Did not hurt at all :)
      <br>
      One little glitch maybe:
      <br>
      I first imported the shape into the spatialite db, then created
      the new trigger according to your example and then loaded it into
      qgis.
      <br>
      Created a label for the calculated value.
      <br>
      Editing the polygon and saving returns the new values.
      <br>
      BUT, these values now seem to be real values with up to 13 digits
      precision. The table manager plugin says, the field is still
      integer. How is this possible to store real values in an integer
      field?!
      <br>
      <br>
    </blockquote>
    <br>
    Spatialite is pretty indifferent as to data types. So when you use a
    calculation like ST_Area that returns a real number, it will use
    that even in a column defined as integer.<br>
    <br>
    Here's a trick to get around that: If you're using the new labeling
    engine, (the ABC button) then when you choose the "Label this layer
    with" click on the ellipsis button (the "...") There you can build
    an expression such as:<br>
    toint("result_val")<br>
    to display the labels as an integer.<br>
       <br>
    <blockquote cite="mid:op.wnnp7fq2l2i25i@bernd-aspire-5741g"
      type="cite">Can someone show me the way to round the values or to
      tell spatialite to respect the integer settings?
      <br>
      <br>
    </blockquote>
    You could also alter the trigger to do something like:<br>
    <br>
    ...<br>
    UPDATE fields SET result_val=(CAST(val*ST_Area(geometry) AS
    INTEGER))<br>
    WHERE...<br>
    <br>
    <blockquote cite="mid:op.wnnp7fq2l2i25i@bernd-aspire-5741g"
      type="cite">Further on the original question:
      <br>
      So, it seems there is no way to perform such actions from within
      qgis directly, which is a pity.
      <br>
      It will be a very hard if not impossible mission to teach those
      people into spatialite ... they are dinosaurs from the
      ArcView3.x-aeons.
      <br>
      <br>
    </blockquote>
    <br>
    Witches, dinosaurs...  At least you have an interesting job!<br>
    <br>
    <br>
    <blockquote cite="mid:op.wnnp7fq2l2i25i@bernd-aspire-5741g"
      type="cite">Thanx for your answers
      <br>
      Bernd
      <br>
      <br>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Micha Silver
GIS Consulting
052-3665918
<a class="moz-txt-link-freetext" href="http://www.surfaces.co.il">http://www.surfaces.co.il</a>
</pre>
  </body>
</html>