Global Mapper v26.0

calculate layer statistics for multiple layers at one time?

JSL
JSL Global Mapper UserTrusted User

I have many streamlines that I've calculated slope statistics for and that I've split into layers based on stream id. When I select all the layers and run any of the "@" functions to determine layer attribute statistics, such as average length, slope, etc., it only gives me the statistic for all the layers aggregated as if they were one layer. Are there any plans to change the calc attribute function so that layer attributes can be calculated on multiple selected layers at one pass, instead of having to run them on each layer individually?

Answers

  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User

    Hi JSL,

    Curious -- I never knew that the attribute calculator could be applied to multiple layers at a time, and I have worked with this code a fair bit (and added the statistics functionality, to boot!). As far as I could see, there's no existing ticket that asks for this, and I'm happy to add one, but first I have some questions.

    I see several possibilities:

    1: We change the behavior to always calculate statistics on a per-layer basis, and apply each to features in the appropriate layer. This would replace the old behavior. My inclination is not to lose this capability, in case some other user relies on it (and it's hard to know whether anyone does, until you change the behavior, and then you find out in a hurry!)

    2: We make it a mode of the calculator (and add a new parameter the GM script engine's implementation to distinguish the cases) so that we'd use use either the old behavior or the new proposed behavior in a formula.

    3: We retain the original behavior for the '@' statistics functions, and add a variant, prefixed by, say, '#' (so #count(), #max(), #average(), etc.) that implements the new behavior, and would allow us to mix/match each of the behaviors in a single formula. I don't have a good sense of whether this would be useful or not.

    Thanks for the suggestion.

    ~Jeff

  • JSL
    JSL Global Mapper User Trusted User

    Hi Jeff, thanks for your help! I definitely think it would be good to keep the option to use the old capability. An example of what I'm looking for is a list of layers of polygons, where I would like to select all the layers and find the average area of each layer with the @function, and then find the average of the entire list as a group. It seems to me like it's a way to apply scripting functionality without actually having to learn how to write a script. Is there any way to allow both #2 and #3 that you've described? Increasing functionality is always a good thing in my book :)

  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User

    I agree that keeping the old way, and adding your new suggested way is probably desirable. So I see a couple of options:

    1: Keep the old set of functions (@area(), @max(), etc.) as is, and add a new separate, parallel set (e.g. #area(), #max(), etc., or something like these) that implement the proposed functionality.

    2: Add an optional flag to the original functions that signals the new behavior, maybe something that's self-descriptive, like 'partitionLayers', so you'd call, e.g. @average( "Area" ) for the original functionality, and @average( "Area", partitionLayers ) for the new option.

    I'd probably choose option 2, as it keeps the list of available functions in the dialog the same size; we'd just want to document the flag in the dialog (and online) descriptions, but the underlying implementation would be pretty much the same.

    Essentially, statistics values represent constant values that are used across a calculation; they're plugged into the executable formula representation so that we don't need to recalculate statistics for every feature processed. Currently we just process all of the features in the selected layers using the same formula (possibly patched with constants like the statistics values). To implement layer-based statistics, we'd need to partition the selected features according to their layer, and process the partitions separately, plugging in layer-based statistics to the formula at the start of each layer; the global statistic values are already plugged into the formula, as they're the same across all partitions.

    I'll write up a ticket for this.

    Cheers,

    ~Jeff

  • JSL
    JSL Global Mapper User Trusted User

    Thank you very much, that will be very helpful!

  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User

    Ticket number is GM-14938. I proposed using a syntax like @max( "Attr1", perLayer ), which seems suggestive of the intent. No guarantees when work on it will be scheduled, but someone should report back here when it's ready.

    Best regards,

    ~Jeff