The Attribute Statistics node is lacking an index output for things like the min/max values. Here's a technique i use frequently based on the Attribute Transfer node:
Basic min/max finding:
Grouped min/max:
- For the basic "Find index of min/max": Arrange points on the X axis using the search value. Subtract the minimum value so they all start at x = 0 (this also works for negative values).
- Then use Transfer Attribute to find the closest point to (0,0,0). Since this will be the point with the smallest search value, we can use this to get the index attribute of that point. Notice the explicit Combine Vector input node, this is needed because we need to override the default input of Source Position (which would be the position of any point for which we evaluate this field).
- This setup can return the maximum value as well by simply using Max output of the statistics node.
The technique can be extended to search in multiple sub-groups simultaneously. For that i separate the point group by spacing them out on the Y axis, in addition to the original X axis sorting.
The purpose of the spacing is to avoid accidentally getting the closest point from a different group. The statistics node's Range output is useful for that, i multiply it by 2 to be on the safe side.
In the attribute search the source positions are then similarly spaced out along the Y axis, to find the closest point in each group. I use a separate input value for this, which makes it easier to pick a single group or map min/max values from a different geometry.
One caveat: If a group is empty, this method will just pick the closest point from a neighboring group. You can add a final distance check to see if the nearest point is closer than the Y axis spacing to handle this case if necessary.
EDIT
Here's a concrete solution for finding the longest section within each spline of a curve object:
First, lets compute the actual section lengths (point to point). This is more complicated than one might think, because if we just go to the next point it will jump to the next spline at the end and give us negative section lengths. I made a little utility node group to compute this.
Now we could use the attribute transfer technique to compute the longest section, grouped by spline index, but there are a few more hurdles to overcome.
First we need to compute the index of the spline for each point. Best way i found is to use the Index input node and capture it on the spline domain. When we then use this attribute for points it will get transferred automatically, so each point uses the spline index we captured. Call it a "domain transfer".
Next, we have to modify the min/max node group a bit. The version i made above searches for the minimum value, so we have to change it to using the maximum value.
Since we using curves we also have to fix the problem that "Transfer Attribute" only works on meshes. The node will show a little error icon:
To fix this we can set the curve resolution to 1 and then convert to points. We only need this during the search, it won't affect the output geometry.
And that, at long last, gives use the desired max length section index. Phew!