09-12-2018 10:16 AM
I have a shapefile with attributes like this
I'd like to get the mean of the values for ID 1,2 and 3. Any bright ideas how to do this in spatial modeler?
Solved! Go to Solution.
09-12-2018 01:41 PM
Suplemental and possibly related. Using the merge feature operator, how can the ID be passed through so that it relates to the original ID? Using this I can merge features using merge matching attributes, but if I match attribute ID what's the syntax in the functional attribute to pass this through to the output features?
09-13-2018 02:06 AM
If I got you correctly and you want mean value separately for each ID, so the model will look like below:
09-13-2018 02:49 AM
Regarding your second question, as you are merging few features into one, you need to specify the function how their attributes will be merged via the Functional Attributes (Double-click on Summary Attribute port). In my example, features were merged using common ID, so I can use any Statistical function - MIN, MAX, AVERAGE - as that ID will be the same for merged features.
09-13-2018 05:21 AM
You have correctly identified the new/improved Merge Features operator as the right tool, and attribute-based merge as the right Criteria. To make sure the ID that was used as the basis of the merge is carried through to the output Features, just use the FIRST expression function. Because each set of feature instances being merged shares a common ID, any one of them will do, so the FIRST function essentially just says "grab any one of the ID values for this set" :-). Your two functional attributes would look like this:
09-19-2018 01:44 AM
In best Columbo style, there's just one more thing...
In my original example, I had data thus:
I'd like to bring the original values over as well to the new combined feature dataset, so as to have:
ID Mean Value 1 Value 2
1 11 10 12
2 20.5 20 21
3 14.5 15 14
I was thinking that Choose might be the function to use but it doesn't seem happy.
09-19-2018 03:02 AM
Because you can have a variable number of values per output feature, your proposed approach would require a variable number of output fields, which is not possible. The closest you can come would be to concatenate the values into a single text field. For this you can use the following:
This will concatenate all the values together, separated by commas. I cannot remember if you have to convert non-text values to text first, I think you do. In this case you can wrap the reference to the Value field within a TEXT function specifying the formatting you prefer.
09-19-2018 03:30 AM
Thanks for that Hal. I was hoping that as there was a FIRST and LAST operator, there might be something that would enable us to get intermediate values as well.
I don't think it would be a variable number of values per feature - in that example there are two points per ID that would give two new attributes to the output.