How to find minimum/maximum value of an attribute

falqnfalqn Global Mapper UserPosts: 123Trusted User
Hi,
For example, I have 10 area features with attribute named 'WIDTH' in metres, I want to find the minimum value and use it as a variable. How to find the minimum value?
My idea was to create area feature which covers all of my 10 features and then use COPY_ATTRS, using MULTI_AREA=ALL_SORT. Then I will be able to CLIP minimum/maximum value (first/last) using CALC_ATTR_FORMULA. But MULTI_AREA=ALL_SORT is not working, why?
Better option will be possibility to use COPY_ATTRS with MULTI_AREA=MIN - can you add MULTI_AREA=MIN to COPY_ATTRS command?

Another option will be creation of special option to find min/max values of an attribute, something like SEARCH_VECTOR_DATA command.

In User Interface we have Search Vector Data dialog which allows to find whatever we want (even sorting), it will be very usefull to create similar possibilities in scripting language.

Regards
Wojtek 

Best Answer

Answers

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,007
    Although it is not documented, using MULTI_AREA=MIN or MULTI_AREA=MAX should get you the minimum or maximum value, respectively, from the ATTR_TO_COPY in the enclosed features.
  • falqnfalqn Global Mapper User Posts: 123Trusted User
    Hi Bob,
    When I try to copy attributes from AREAS to AREAS nothing is working... I'm not able to copy anything using script. I'm attaching workspace and script files, please take a look.
    I'm using v17.1, 64bit.

    Regards
    Wojtek

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,007
    When you use COPY_ATTRS to copy attributes from AREAS to AREAS, the "from" area is the container, and the "to" area is the contained area.  In your example, your "from" layer (LAYER1_FILENAME) should be area2 and your "to" layer (LAYER2_FILENAME) should be area1.  This is the opposite of what your script is doing, which is why no attributes are being copied.
  • falqnfalqn Global Mapper User Posts: 123Trusted User
    Hi Bob,
    I want to copy attributes "from" small areas "to" one big area containing all small areas - like I wrote in script. Analising your answer i have realised that to do so I have to put in to the script:
    AREA_COVERAGE=PARTIAL
    and now copying is working, but script always copy all of the atributes divided with 'comma' sign.
    Adding MULTI_AREA=MAX or MIN changes nothing - parameter is not working. Here is updated script, please take a look:

    GLOBAL_MAPPER_SCRIPT
    COPY_ATTRS \
    LAYER1_FILENAME="area1" \
    LAYER2_FILENAME="area2" \
    FROM_TYPE=AREAS \
    TO_TYPE=AREAS \
    AREA_COVERAGE=PARTIAL \
    MULTI_AREA=MIN \
    ATTR_TO_COPY=ATTR1

    Regards
    Wojtek
  • gghigginigghiggini Global Mapper User Posts: 9
    Hi,
    I have the same problem today.
    Wouldn't be possible to use

    CALC_ATTR_FORMULA NEW_ATTR="newattr_2" FORMULA="Min(existingattr_1)"

    Regards
    Giorgio
  • gghigginigghiggini Global Mapper User Posts: 9
    I tried and it does not work.

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,007
    gghiggini said:
    Wouldn't be possible to use 

    CALC_ATTR_FORMULA NEW_ATTR="newattr_2" FORMULA="Min(existingattr_1)"

    Hi Giorgio,

    The Max and Min functions used in the CALC_ATTR_FORMULA command do not operate on the entire data set. They return a result from the items in the list. For example, 
    CALC_ATTR_FORMULA NEW_ATTR="newattr_2" FORMULA="Min(existing_1, existing_2, existing_3)"
    will return the minimum value of the three attributes in the list. 

    If you are using the COPY_ATTRS command, MULTI_AREA=MIN or MULTI_AREA=MAX would copy the smallest or largest value of the attribute when multiple features intersect the area being copied.

    Cheers,
    Bob

    gghiggini
  • JeffH@BMGJeffH@BMG Global Mapper Developer Posts: 322Trusted User
    Bob is correct about the min() and max() functions: they operate on individual features, so any parameters to these function will use the attributes associated with a particular feature. We do have an existing ticket, #23260, that would add aggregate functions to the formula calculator that would operate across all of the attributes for the features under consideration. The proposed functions would allow for  min, max, sum, average, median, standard deviation, variance, etc. calculations. This new feature hasn't been scheduled yet, but I'll add a note to reference this forum thread.

    Best regards,

    ~Jeff
Sign In or Register to comment.