I have a shapefile with the attribute "yield". I need to know the math difference between yield (id1) and yield (id2)... then yield (id2) and yield (id3) and so on... I hope you understand what I mean.

In Excel it is easy to handle. But I do not want to export and import the files.


How about a solution in Spatialite? Import your shapefile into a spatialite DB, lets call it "polys". Add a column to hold the differences:

ALTER TABLE polys ADD COLUMN diffs real;

Now this UPDATE will populate the diffs column with the differences between each consecutive row:

UPDATE polys SET diffs=(
SELECT p1.yield-p2.yield
FROM polys AS p1, polys AS p2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.