Global Mapper v25.0

questions about generating contours with script

JSL
JSL Global Mapper UserTrusted User

I have layers of DEMs that I want to create contours from. I used the loop command in a script to generate contours separately on successive layers, but each resulting contour layer ends up being created from all the DEMs open in the workspace instead of just the DEM in the selected layer. How do I set the contour command to just work on the selected layer?

I also was wondering if there is a way to make the output contour layers take the file name of the DEM layer from which they were created.

Thanks for any help.

Best Answer

  • mcsmoother
    mcsmoother Global Mapper User
    Answer ✓

    I'm glad it worked. The key is that we moved the newly created contours from the "GENERATED CONTOURS" layer each time that we made them from each dem layer with the flag, MOVE_TO_NEW_LAYER. This was necessary since Mapper will only send newly created contours to that layer only.

    You are correct, the name came from the flag, NEW_LAYER_NAME, and the %LAYER_DESC%_CONTOURS is a combination of the layer description of the current layer we are on in the loop, and then we add the "_CONTOURS" to that. You can refer to the LAYER_LOOP_START command in the scripting reference to see these built-in variables.

Answers

  • mcsmoother
    mcsmoother Global Mapper User

    I use scripting to handle such a case. Just loop over the dem layers, hiding all layers first and then in the loop, show the layer you want the contours generated over. Then hide it as the last command in the loop. Rinse and repeat. You can of course create the contours on a new layer, with the DEM's layer name as the name. If you need examples, just ask and I will provide.


    ~Mark

  • JSL
    JSL Global Mapper User Trusted User

    An example would be very helpful, thank you!

  • mcsmoother
    mcsmoother Global Mapper User

    GLOBAL_MAPPER_SCRIPT VERSION="1.00"

    //Assumes that you have the DEM files on separate layers and only those loaded into the workspace, no other layers


    SET_LAYER_OPTIONS FILENAME="*" HIDDEN=YES

    LAYER_LOOP_START FILENAME="*"

      SET_LAYER_OPTIONS FILENAME="%LAYER_DESC%" HIDDEN=NO

    //Generate the contours. Add your parameters

      GENERATE_CONTOURS

      SET_LAYER_OPTIONS FILENAME="%LAYER_DESC%" HIDDEN=YES

    LAYER_LOOP_END

    SET_LAYER_OPTIONS FILENAME="*" HIDDEN=YES

    LAYER_LOOP_START FILENAME="*"

      SET_LAYER_OPTIONS FILENAME="%LAYER_DESC%" HIDDEN=NO

    //Export the contours as an image, change as you need. Just an example

      EXPORT_RASTER FILENAME="C:\Contours\%LAYER_DESC%".png

      SET_LAYER_OPTIONS FILENAME="%LAYER_DESC%" HIDDEN=YES

    LAYER_LOOP_END      

  • mcsmoother
    mcsmoother Global Mapper User

    I remembered that the output from the generate contours command cannot be placed on a new layer. So here is a version that attempts to move the freshly generated contours to a new layer each time it loops. This is untested, just off the top of my head.


    GLOBAL_MAPPER_SCRIPT VERSION="1.00"

    //Assumes that you have the DEM files on separate layers and only those loaded into the workspace, no other layers

    SET_LAYER_OPTIONS FILENAME="*" HIDDEN=YES

    LAYER_LOOP_START FILENAME="*"

      SET_LAYER_OPTIONS FILENAME="%LAYER_DESC%" HIDDEN=NO

    //Generate the contours. Add your parameters

      GENERATE_CONTOURS FILENAME="%LAYER_DESC%"

      EDIT_VECTOR FILENAME="GENERATED CONTOURS"/

    MOVE_TO_NEW_LAYER=YES NEW_LAYER_NAME="%LAYER_DESC%_CONTOURS"

    //You could place an export command here, use the layer name of "%LAYER_DESC%_CONTOURS"

    //for the layer to export from 

    SET_LAYER_OPTIONS FILENAME="%LAYER_DESC%" HIDDEN=YES

    LAYER_LOOP_END    

  • JSL
    JSL Global Mapper User Trusted User

    Wow, that worked beautifully! I copied your script above and pasted it into a Notepad++ doc and then saved it as a gms.

    I did have to change the forward slash after the command line "EDIT_VECTOR FILENAME="GENERATED CONTOURS"/" to a back slash because the script editor said, "WARNING: Unknown command<MOVE_TO_NEW_LAYER=YES> ignored. It looks like a valid parameter though. Did you forget a line continuation character (\)?"

    So I take it that the command EDIT_VECTOR FILENAME="GENERATED CONTOURS"\MOVE_TO_NEW_LAYER=YES NEW_LAYER_NAME="%LAYER_DESC%" is the key to assigning the filename of the DEM to the generated contours?

    Thanks so much, I never would have been able to come up with that by myself. That will save my mousing arm a lot of clicking!