Problem with formula calculation

JSL
JSL Global Mapper UserTrusted User

Help, what am I doing wrong here? I'm trying to calc attr an "if" expression comparing one attribute to 0, so I use this expression:

if(num(MAX ELEV AVG OF LAYER DIFF FROM MAX ELEV)<0,"lesser","greater")

I copied the formula directly from the "if" example in the Formula Help menu and substituted my variable names, but I'm getting this error:

"Missing '(' in function argument list"

Best Answer

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

    Hi JSL,

    Not sure why combining areas isn't directly supported in the scripting language. I was thinking that you could do this using the EDIT_VECTOR command (https://www.bluemarblegeo.com/knowledgebase/global-mapper-24/cmd/EDIT_VECTOR.htm), but couldn't come up with anything that works.

    You could try something like the following, which uses the spatial operations scripting language embedded in a Global Mapper script:

    BEGIN_SPATIAL_OPERATION

    layer "Result" = dissolve( "Areas_1.shp" )

    END_SPATIAL_OPERATION

    Hope that this helps,

    ~Jeff

Answers

  • JSL
    JSL Global Mapper User Trusted User

    I figured out the problem--the formula calculator doesn't like spaces, so I just needed to put a "_" between the words in my formula.

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

    Hi JSL,

    It's true: the formula calculator, much like most programming languages, doesn't like embedded spaces in variable names (or attribute names, in this case) -- it makes parsing a formula harder. But you should be able to enclose the name with percent characters ('%') in the formula, and that should work fine. In your case, the formula would be: if(num(%MAX ELEV AVG OF LAYER DIFF FROM MAX ELEV%)<0,"lesser","greater").

    See the online docs: https://www.bluemarblegeo.com/knowledgebase/global-mapper-24/Scripting_Reference/Formula_Calculator.htm, specifically the section Formula Reference / Values / Attributes (for the Attribute Calculator and CALC_ATTR_FORMULA command only), which discusses this specifically (i.e., buried in the fine print, a bit).

    Hope that this helps.

    Cheers,

    ~Jeff

  • JSL
    JSL Global Mapper User Trusted User

    Thanks, I always wondered what the reason was for the underscore. I'm using this knowledge to play around with scripting, and I was wondering if there was a script for combining areas? I see combining lines in the Knowledge Base, but not combining areas.

  • JSL - There's a lot of situations where I haven't been happy with the result of combining/dissolving boundaries of adjacent area features. I'll give you the workaround I use, but please check it on your end thoroughly too. The only time I do this is low-accuracy site planning, not on surveying/engineering projects.

    1. Buffer your areas by a set value (let's say +1ft). Make sure "Create rectangular buffers" is checked, along with "List all attributes...." Then, Depending on your dataset....
    2. A - You can check the box to combine overlapping buffer areas, regardless of attribute
    3. OR - Do not combine overlapping buffers. Instead, use edit_vector to merge areas that have matching attributes.
    4. Buffer your features again, using the inverse of the first value (-1ft) to return them to their original shape.

    The only reason I ever do this is because the merge/dissolve tool does not give the results I want sometimes, which I suspect is because I have a layer in a geographic coordinate system and a project in a projected coordinate system (or some combination along those lines). For what it's worth, I've had the same issue with the same datasets when using ArcGIS Pro & ArcMap.

  • JSL
    JSL Global Mapper User Trusted User

    Very clever solution. My only issue with combining buffers is that it can take a long time, depending on the number of buffers. I'll give it a shot, though.

  • gghiggini
    gghiggini Global Mapper User

    I am using the DISSOLVE

    How can I avoid to the resultant feature to have hundreds of fields with the same name and a progressive number?

    Isn't there a way to tell the DISSOLVE to get only the FIRST, LAST, MIN, MAX, etc... when building the attributes of the dissolved feature?

    Giorgio

  • JSL
    JSL Global Mapper User Trusted User

    DerrickW, just wanted to let you know that I've been able to use your buffering technique to recombine multiple area polygons which were split by a 1-m wide line. I just created 2m wide buffers on the split polygons and was able to recombine them using the standard area combination process. The extra 2m isn't enough to significantly affect the area attributes, so I didn't have to do the inverse buffering to regain the original area.

    Thanks again for your input.

  • Great, glad it worked for you!

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

    "Isn't there a way to tell the DISSOLVE to get only the FIRST, LAST, MIN, MAX, etc... when building the attributes of the dissolved feature?"

    Hi Giorgio,

    Sadly, there is none so far. Advanced attribute operations would be a great -- in fact a necessary -- addition to the spatial operations toolset, particularly in spatial scripting where the scripting language could be augmented to provide attribute operations more flexibly.

    Hopefully they Blue Marble sees the utility and adds the capability.

    Cheers,

    ~Jeff