questions about generating contours with script
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
-
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
-
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
-
An example would be very helpful, thank you!
-
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
-
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
-
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!
Categories
- 12.8K All Categories
- 5.7K Features Discussion
- 345 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 636 GM Script Language
- 54 User Scripts
- 114 GPS Features
- 417 Projection Questions
- 825 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 178 Announcement and News
- 912 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 569 Other Discussion
- 131 GIS Data Sources
- 27 Global Mapper Showcase
- 238 How I use Global Mapper
- 107 Global Mapper Forum Website