1

I need to merge multiple shape files and want the merged file to have the maximum value for each feature of a specific attribute (called DEPTH2D in the example below)

What I need is exactly what it is asked here below but instead of a raster I have a shape file:

Combining multiple overlapping rasters - retain maximum value?

I also went through this other topic but what it does is giving the maximum value for each attribute, while I need to have the maximum for each row (so for each attribute):

Getting maximum values of attribute of multiple Shapefiles merged into new shapefile in QGIS?

Just to give you some context:

I generated on Infoworks ICM multiple flood map shape files, each for a different storm durations. I now need to merge them on a unique shape file that contains the maximum depth for each attribute

Any idea?

Say for example I want to merge shape file 1 and 2 containing polygons, in the picture below. The element 98312 is contained in both shape file and has a value of the field 'DEPTH2D' =0.055 in the shape file 1 and 0.027 in the shape file 2

I want to merge together shape files 1 and 2 and I want the merged shape file to have the element 98312 with a have a value of 0.055 (the maximum between 0.055 and 0.027)

enter image description here

Angelo S.
  • 13
  • 3

1 Answers1

0

You don't mention any specific software package, but your screen grabs look like QGIS to me, so I'll answer in that context.

You could do a join on your layers using element_no as the join and target field. Select only the DEPTH2D field to add to the join, and pick a convenient prefix (or accept the very long default).

enter image description here

Now open the field calculator and create a new field MAX_DEPTH with formula

max( "DEPTH2D" , "30-DEPTH2D" )

If you want the max over many layers, join each layer, then include the appropriate xx-DEPTH2D field in the max(..) calculation.

I noticed that not every layer contains the same number of elements. You will want to start with a layer containing every element that appears in any layer.

There's probably a direct approach using SQL, but that's not my thing.

Llaves
  • 5,963
  • 5
  • 31
  • 56
  • Hi Llaves, thanks very much for you answer. Yes, unfortunately every layer has different elements in it. Is starting with a layer containing every element a necessary condition to apply successfully your work flow? – Angelo S. Oct 05 '22 at 08:37
  • Yes, you were right, I am using QGIS – Angelo S. Oct 05 '22 at 08:38
  • If the two layers you are joining don't have the same elements, then if you join layer 2 to layer 1, only the elements that were in layer 1 to start will appear in the joined table. You could start by merging all your layers into a single layer using Vector->DataManagementTools->Merge Vector Layers. This will have duplicate rows for elements that appear in multiple input layers. You can remove the duplicates using Delete Duplicates By Attribute from the Processing Toolbox. Now you have a master layer with every element. Join the DEPTH2D field to this layer from each layer. Now take MAX – Llaves Oct 05 '22 at 17:55
  • Hi Llaves, I managed to apply your workflow! Thank you very much for your help. Could you point me towards a tool I can use to automatize all steps, if any? I need to perform this task multiple times. Thanks again. A – Angelo S. Oct 08 '22 at 07:29