0

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.

nmtoken
  • 13,355
  • 5
  • 38
  • 87
Pimpel
  • 2,353
  • 3
  • 25
  • 39
  • I think you will need some python scripting for that. – Alexandre Neto Jul 02 '13 at 15:44
  • 1
    @Pimpel, make math difference in Excel (save result in csv or dbf table), then Join this table to shape-file (http://gis.stackexchange.com/questions/6398/join-non-spatial-csv-to-spatial-data-in-qgis) – spatialhast Jul 02 '13 at 17:02

1 Answers1

1

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
WHERE p1.ROWID=p2.ROWID-1 AND p2.ROWID>=2); 
Micha
  • 15,555
  • 23
  • 29