2

In the picture you can see polygon number 39a in the center. This polygon is drawn on one layer. The layer underneath holds information with soil conditions (green and red). You can see that polygon 39a is laying in 'vochtig zand'(red) and a little bit in 'Nat zandleem'(green).

In the 39a polygon attribute table, I want to see the soil condition which is most present within the surface of the polygon. Not by making a new 'clipping' shapefile but by a formula or expression. Is this possible? Can anybody help me with the expression formula?

enter image description here

1

Yet another approach...using Virtual Layer.

enter image description here

Above is an example with soil polygon layer with red vochtig zand and green nat zandleem is defined in soiltype field. Red polygon (your 39a) is on my_polygon layer.

By selecting menu Layer | Add Layer | Add/Edit Virtual Layer and after [import] your layers, you can set up a query like below:

enter image description here

The query is:

SELECT round(st_area(v_zand)/st_area(my_polygon.geometry)*100,3)||'%' AS 'voching zand (%)'
FROM my_polygon,
(SELECT st_intersection(soil.geometry, my_polygon.geometry) AS v_zand
 FROM soil, my_polygon WHERE soil.soiltype = 'vochtig zand')

When you open the attribute table of the virtual layer, it will show the percentage of vochtig zand.

enter image description here

Please change layer/field name in the SQL syntax as required.

EDIT ... as suggested by @artwork21

SELECT 
  CASE 
    WHEN st_area(v_zand) > (st_area(my_polygon.geometry) - st_area(v_zand)) THEN 'vochtig zand'
    WHEN st_area(v_zand) = (st_area(my_polygon.geometry) - st_area(v_zand)) THEN 'equal'
    WHEN st_area(v_zand) < (st_area(my_polygon.geometry) - st_area(v_zand)) THEN 'nat zandleem'
  END 
  AS Predominant 
FROM my_polygon,
(SELECT st_intersection(soil.geometry, my_polygon.geometry) AS v_zand
 FROM soil, my_polygon WHERE soil.soiltype = 'vochtig zand')

enter image description here

  • How does the query evaluate the soil condition which is most present? – artwork21 Nov 17 '17 at 13:16
  • @artwork21 As it stands, op shows just two types. So the percentage of voching zand would be enough. If there are more types then the syntax can be modified to accommodate them. – Kazuhito Nov 17 '17 at 13:24

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.