|
On 12/11/2012 13:00, Bernd Vogelgesang
wrote:
Here's some "witchcraft"
In a spatialite DB, I have a polygon table "fields". I Added an
integer column "val"
and a column "result_val" of type real. Then I set up this
trigger:
CREATE TRIGGER update_result_trig
AFTER UPDATE ON "fields"
BEGIN
UPDATE fields
SET result_val=(val*ST_Area(geometry))
WHERE ROWID=NEW.ROWID;
END
I loaded the spatialite polygon layer into QGIS and set the
"result_val"
attribute as a label for each polygon. Now I started editing. At
each click of
the save button the label, representing the result_val, changes.
Seems to work
nicely.
HTH
Micha
Thanks a lot, Micha!
Did not hurt at all :)
One little glitch maybe:
I first imported the shape into the spatialite db, then created
the new trigger according to your example and then loaded it into
qgis.
Created a label for the calculated value.
Editing the polygon and saving returns the new values.
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?!
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.
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:
toint("result_val")
to display the labels as an integer.
Can someone show me the way to round the values or to
tell spatialite to respect the integer settings?
You could also alter the trigger to do something like:
...
UPDATE fields SET result_val=(CAST(val*ST_Area(geometry) AS
INTEGER))
WHERE...
Further on the original question:
So, it seems there is no way to perform such actions from within
qgis directly, which is a pity.
It will be a very hard if not impossible mission to teach those
people into spatialite ... they are dinosaurs from the
ArcView3.x-aeons.
Witches, dinosaurs... At least you have an interesting job!
Thanx for your answers
Bernd
--
Micha Silver
GIS Consulting
052-3665918
http://www.surfaces.co.il
|
_______________________________________________
Qgis-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-user