[GIS] How to recalculate an attribute based on overlap with another layer

qgissrtm

I have 2 layers: The first one is a point Layer (converted from SRTM) with height information. The second one is a polygon layer (shows the forest).

I want to reduce the height value – let's say about 15m if the point value is in a forest area. How can I do that?

Best Answer

One way to do this is to create a new point layer that contains information about overlapping forest areas. If your point layer has an attribute 'height' and each forest polygon an attribute 'forest' which is 1 for all forest areas:

  1. Select Vector|Data Management Tools|Join attributes by location;
  2. Select the point layer as the 'target vector layer' and the polygon as the 'join vector layer';
  3. Make sure to select 'keep all records' so you keep all your points;
  4. Enter an output shapefile (like points_forestoverlap.shp) and click 'ok'; add to the TOC (layers). enter image description here

    Your new points layer will have a 'forest' attribute - forest areas will be 1 (or whatever value was in the polygon layer) and all non-overlapping points will have NULL. I have not found a way to do calculations using 'NULL' in the field calculator so you have to replace these with 0:

  5. Open the attribute table and click the 'forest' column heading to sort it;
  6. Select all the rows with NULL under 'forest';
  7. Start editing, then open the field calculator;
  8. Keep 'Only update selected features', and select 'Update existing field', and select 'forest' in the dropdown box;
  9. Enter 0 in the Expression text box and click OK - all the NULLS are replaced by 0.
  10. Open the field calculator again, deselect 'Only update selected features', and create a new field new_heights (decimal);
  11. Enter the expression "height" - (("forest" = 1) * 15) then OK; this will test if it's a forest area ("forest" =1), returning 1, and multiplying by your correction factor. enter image description here

You could also (in step 6) choose to update the existing heights field, and use the same expression.

I suspect you're doing this to correct for canopy height in a forest area? You could have a 'canopy' attribute in your forest polygon and use that to do your correction, thus you could have different canopy heights for different forest areas.