Fill Color of Areas with Scripting

Hi

I have some areas that i would like to apply fill color to. Basically i want to do the same as a manual "feature style" modification but in the script. I have tried the following but nothing happens, and no error is shown in the output window.

STYLE_ATTR="AREA_STYLE=SOLID" STYLE_ATTR="FILL_COLOR=RGB(0,255,0)"

I used this in the SET_LAYER_OPTIONS call.

Thanks in advance.

Answers

  • Hi

    Can someone help me with this as its doing my head in. This is something so simple yet no options seem to work. I have tried


    EDIT_VECTOR FILENAME="Layer" STYLE_ATTR="FILL_STYLE=SOLID" STYLE_ATTR="FILL_COLOR=RGB(100,255,0)" CLOSED="YES" 

    EDIT_VECTOR FILENAME="Layer" STYLE_ATTR="FILL_STYLE=SOLID" STYLE_ATTR="FILL_COLOR=RGB(100,255,0)" CLOSED="TRUE"

    SET_LAYER_OPTIONS FILENAME="Layer" SHOW_LABELS="NO" STYLE_ATTR="FILL_STYLE=SOLID" STYLE_ATTR="FILL_COLOR=RGB(100,255,0)"


    Via define layer style

    DEFINE_LAYER_STYLE NAME="DEEP" TYPE="AREA"

    BORDER_COLOR=RGB(0,0,0)

    BORDER_STYLE=Null

    FILL_COLOR=RGB(100,255,0)

    FILL_STYLE=Solid Fill

    CLOSED=YES

    END_DEFINE_LAYER_STYLE


    SET_LAYER_OPTIONS FILENAME="Layer" SHOW_LABELS="NO" AREA_STYLE_NAME="xxxxx"


    I cant even change the color of any line in the script.

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User

    The EDIT_VECTOR command would be the proper way to do this.

    What output does the script show when you run it in the File->Run Script dialog?

    The FILENAME in the EDIT_VECTOR command must reference an already loaded layer (either by filename or layer description). So the following command would update the loaded layer with the description 'Layer'. All features would have their style updated based on the new attributes:

    FILL_STYLE=SOLID

    FILL_COLOR=RGB(100,255,0)

    Since these are fill styles, only area features would be affected. They should be set to a solid fill of that color. The CLOSED="YES" parameter wouldn't do anything and should generate a warning about an unknown parameter.

    EDIT_VECTOR FILENAME="Layer" STYLE_ATTR="FILL_STYLE=SOLID" STYLE_ATTR="FILL_COLOR=RGB(100,255,0)" CLOSED="YES" 

    After that, the features in the loaded layer should now draw with that style in Global Mapper. The file itself isn't updated. You would need to use an EXPORT_VECTOR command to write the data out to a new file.

  • Hi Mike,

    Thats basically the code i used, I can confirm that the FILENAME is a loaded layer. The dialog also shows no errors and says the layer was updated. However it does jack.


    Editing vector features...

    Updated 1 features.


    Does it require a DEFINE_something in the header of the script? Shall i get the hammer out the toolbox?

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User

    What type of features do you have loaded? I just ran the script below in the context of the main map view with a vector layer loaded and it made all of the area features render as solid green in the main view:

    EDIT_VECTOR STYLE_ATTR="FILL_STYLE=SOLID" STYLE_ATTR="FILL_COLOR=RGB(100,255,0)"

    Note that leaving off the FILENAME parameter means that all loaded layers are used.

  • Ok, i think something is overriding the results. I just took off the FILENAME and not one feature updated. It says it ran and with out errors. I have vector layers, raster layers, contours (all closed) and nothing happened.


    Editing vector features...

    Updated 37 features.

    I dont see anything strange in the header.

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User

    Are they any area features in your vector layers? The FILL_STYLE / FILL_COLOR parameter will only affect the style of area features, they would not affect the style of line features (like contour lines).

    If you want to change what line features look like, you would use something like:

    EDIT_VECTOR STYLE_ATTR="LINE_STYLE=SOLID" STYLE_ATTR="LINE_COLOR=RGB(100,255,0)"

    See https://www.bluemarblegeo.com/knowledgebase/global-mapper-23/ASCII_Field_Options.htm for documentation of the recognized style attributes.

  • Yes, i have area features in various layers and none of them update. i also tried the LINE_ scripting and again the output windows show no errors, but no updates are made to any lines.

    Could it be something to do with MAP_LAYOUT, SET_SHADER_OPTS or others?

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User

    This could also be affected by settings on the Area Styles tab of the Options dialog for the layer. If this is set to anything other than 'Use Default Style Based on Classification or Custom Style', then your changes to the Custom Style of features won't show anything.

    The DEFINE_LAYER_STYLE and SET_LAYER_OPTIONS AREA_STYLE is how that could be reset if that is the problem. I think a DEFINE_LAYER_STYLE like below would work:

    DEFINE_LAYER_STYLE NAME="AREA_STYLE" TYPE="AREA"

    LayerStyle=0

    Type=0

    END_DEFINE_LAYER_STYLE

  • I tried the DEFINE_LAYER_STYLE statement and it allowed me to change the line style color only. However, the area filling it does not make a change.

    I can also confirm that the "Use Default Style Based on Classification or Custom Style" is set correctly in the options of the layer. However, if i double click the feature and open the "Modify Feature Info" the Feature Style is set to "Specify Style to Use When Rendering Feature", not the same default. Is there a way to force the feature info to use a style?

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User

    Is it possible for you to provide me the data you are working with so I can try this for myself? You can either attach a .zip here or email to mikec@bluemarblegeo.com .

    This should be worked based on what you are describing.

    Also note if you want really advanced control of styling and now how to write Python code, you can write a Python script and run it in Global Mapper Pro. That will give you access to ever individual feature in code with a way to set the style however you please. This is a lot more complex than a traditional GM script though.

  • Thanks Mike. My conclusion is that FILL_STYLE=SOLID is not valid perhaps due to the CLOSED=YES or CLOSED =TRUE not being recognised in the EDIT_VECTOR command. I have tried this on mutiple areas and it wont fill. On lines it works perfectly.

  • bmg_mike
    bmg_mike Global Mapper Guru Moderator, Trusted User

    The CLOSED= parameter should be completely ignored as that is not a valid parameter for any script command. It is a style attribute used at load time for text files to differentiate between area and line features. You should be seeing a warning about it being unknown.

    After the EDIT_VECTOR is run and the style edited for matching features, when you edit that feature it should be marked as 'Specify Style to Use When Rendering Feature' with the assigned style from the attributes. The one exception is if the style that you specified happened to match the default style for the assigned type, in which case the 'Use Default Style' option would be highlighted.