Run modulus formula in GMS 16.2.2
George Chandeep Corea
Global Mapper UserTrusted User
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
In QGIS I run the following in my script
CASE WHEN "elevation" % 1 THEN 'minor'
WHEN "elevation" % 5 THEN 'moderate'
ELSE 'major'
END
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"
ELSE
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?
Tagged:
Answers
-
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?
-
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.
-
Thanks @bmg_bob
Here's what I used./create modulus columns for 1m and 5m
CALC_ATTR_FORMULA NEW_ATTR="modulus1m" FORMULA="MOD(ELEVATION,1)"
CALC_ATTR_FORMULA NEW_ATTR="modulus5m" FORMULA="MOD(ELEVATION,5)"
/ 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"
Categories
- 13K All Categories
- 5.8K Features Discussion
- 350 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 652 GM Script Language
- 56 User Scripts
- 115 GPS Features
- 421 Projection Questions
- 835 Raster Data
- 1.4K Vector Data
- 6.7K Support
- 181 Announcement and News
- 939 Bug Report
- 562 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 579 Other Discussion
- 132 GIS Data Sources
- 27 Global Mapper Showcase
- 244 How I use Global Mapper
- 110 Global Mapper Forum Website

