Global Mapper Pro

Scripting - Assign "Feature Name"

Roger Edrinn
Roger Edrinn Global Mapper UserTrusted User
edited June 2010 in Technical Support
I'm learning and using the powerful GM script language. At the bottom of the HTML How to is this example:
GLOBAL_MAPPER_SCRIPT VERSION=1.00

// Import the file to modify
IMPORT FILENAME="C:\Temp\export test\tiger_wyandotte_sample.gmp"

// Assign the type "railroad" to all features with a CFCC attribute with a value of A41
// and a display label with '74' in it somewhere.
ASSIGN_TYPE LINE_TYPE="RAILROAD" COMPARE_STR="CFCC=A41" COMPARE_STR="<Feature Name>=*74*"

As I understand the example, I can use the compare_str function to find a string, then assign a line type to all examples where the criteria is met. However, I cannot do a "double search" and assign a Feature name to those found lines where the Feature name = unknown.

Basically I'm trying to use generic lines types to define more than one feature by assigning a Feature name in addition to the line color/pattern. Same for areas. I'm not adding new line/area types because the MP code is so restricted.

If I can already do this, please point the way. If not, can this be added to the script language set?

Thanks

Comments

  • global_mapper
    global_mapper Administrator
    edited May 2010
    There isn't currently a way to assign feature names based on a search via the scripting language, but I can probably add that within too much trouble. I'll let you know when I have a new build with this capability.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • global_mapper
    global_mapper Administrator
    edited June 2010
    Roger,

    I have a new ASSIGN_ATTR command ready for you to test (note that I haven't fully tested it yet, so it might not work at all) that allows assigning new attribute and/or label values based on matches against other attributes (similar to the ASSIGN_TYPE command). I have placed a new build at http://www.globalmapper.com/global_mapper11.zip with the change for you to try. Simply download that file and extract the contents into your existing v11.xx installation folder to give it a try. If you are using the 64-bit version, there is a new build available at http://www.globalmapper.com/global_mapper11_64bit.zip .

    Here is the documentation for the new command:

    ASSIGN_ATTR

    The ASSIGN_ATTR command allows you to assign feature attributes and/or labels based on one or more attribute or label values. You can choose to add/update multiple attributes and/or label values with a single operation. You can also supply multiple COMPARE_STR parameters to apply multiple criteria, all of which must be true, in order to assign an attribute/label.

    The following parameters are supported by the command:

    * FILENAME - filename of the layer to assign attributes/labels to. If an empty value is passed in, all loaded vector layers will be updated. You can also pass in the value 'USER CREATED FEATURES' when running a script in the context of the main map view or loading a workspace to have the 'User Created Features' layer updated.
    * ATTR_VAL - specifies a the attribute value to updated and what value to assign to it. The format is attr_name=attr_value. For example if you want to set the value of an attribute named CFCC to A34, use ATTR_VAL="CFCC=A34". You can add multiple ATTR_VAL parameters to a single command to provide multiple attribute/value pairs (or labels) to add/update. If you would like to update the feature label rather than an attribute, use <Feature Name> for your attribute name.
    * COMPARE_STR - specifies a comparison operation to perform to see if a feature is one that needs to be updated. The format is attr_name=attr_value. For example if you have an attribute named CFCC and you want to match when the value of that attribute starts with an 'A', you can use COMPARE_STR="CFCC=A*" as your parameter. You can add multiple COMPARE_STR parameters to a single command to combine multiple criteria for your search. If you would like to compare against a feature label rather than an attribute, use <Feature Name> for your attribute name. To compare against a feature type name rather than an attribute, use <Feature Type> for your attribute name. To compare against the feature description, use <Feature Desc> for your attribute name.
    * CASE_SENSITIVE - specifies whether or not text comparisons are case sensitive or not. Use CASE_SENSITIVE=YES to enable, by default comparisons are not case sensitive.

    For an example of how to use the ASSIGN_ATTR command, see the sample at the bottom of this document.
    Update Feature Attributes and Labels Based on an Attribute Value

    GLOBAL_MAPPER_SCRIPT VERSION=1.00

    // Import the file to modify
    IMPORT FILENAME="C:\Temp\export test\tiger_wyandotte_sample.gmp"

    // Assign the name "Burlington Northern Railroad" to all features with a CFCC attribute with a value of A41
    ASSIGN_ATTR ATTR_VAL="<Feature Name>=Burlington Northern Railroad" COMPARE_STR="CFCC=A41"

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Roger Edrinn
    Roger Edrinn Global Mapper User Trusted User
    edited June 2010
    Looking forward to trying this, a new leap forward in scripting for me. Thanks for the example too. I'll let you know later tomorrow. I'll post something in the new script sub-forum.

    One thing I've learned about using scripts, not only faster but more accurate once you've debugged the script.

    Thanks
Sign In or Register to comment.