Run modulus formula in GMS 16.2.2

George Chandeep CoreaGeorge Chandeep Corea Global Mapper UserPosts: 62Trusted User
edited December 2015 in GM Script Language
I need to create a contour_type field for major (5m intervals), moderate (1m intervals) and minor (others).

In QGIS I run the following in my script
CASE WHEN "elevation" % 1 THEN 'minor'
 WHEN "elevation" % 5 THEN 'moderate'
 ELSE 'major'

How do I do the same in GMS?

I think it will be something like

// Create new contour_type attribute
IF COMPARE_STR="elevation%1"= 0
CALC_ATTR_FORMULA NEW_ATTR="contour_type2" FORMULA="moderate"
ELSE IF COMPARE_STR="elevation%5"= 0
CALC_ATTR_FORMULA NEW_ATTR="contour_type2" FORMULA="major"
CALC_ATTR_FORMULA NEW_ATTR="contour_type2" FORMULA="minor"

So if the contour is 

-1.25m then modulus for 1 and 5 is not 0 (no remainder) and is therefore minor

-2m then modulus for 1 is 0 but not for 5 so it is moderate

-10m modulus for 5 is 0 but not for 1 so it is major

Also how do I move the elevation field and the new contour_type fields to be the first and second columns in the table?

Best Answer

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,218
    edited December 2015 Answer ✓
    The DEFINE_VAR and  CALC_ATTR_FORMULA script commands support calculation of the remainder via the MOD function.  See the description for the FORMULA parameter, and a link to the Formula Calculator Reference.


  • George Chandeep CoreaGeorge Chandeep Corea Global Mapper User Posts: 62Trusted User
    Should I change how this is asked? In python and other languages the operator is % or mod.

    If GMS can't do this is there an alternative way of getting the remainder?
  • George Chandeep CoreaGeorge Chandeep Corea Global Mapper User Posts: 62Trusted User
    Thanks @bmg_bob ;

    Here's what I used.
    /create modulus columns for 1m and 5m
    / Create new contour_type attribute
    EDIT_VECTOR COMPARE_STR="modulus1m=0" ATTR_VAL="contour_type=moderate"
    EDIT_VECTOR COMPARE_STR="modulus5m=0" ATTR_VAL="contour_type=major"
    EDIT_VECTOR COMPARE_STR="modulus1m!=0" ATTR_VAL="contour_type=minor"

Sign In or Register to comment.