Script question
Matt
Global Mapper UserTrusted User
If I want to run a script on an entire directory of files, how do I retain the file names without having a command for each file? In other words, what would I enter for the ???'s below if I just wanted to import several 100 rasters, do something to them, then export them with the same file name? Can I do that with two lines in the script? Or do I need a line for each file name?
IMPORT FILENAME="I:\_TEMP\???"
EXPORT_RASTER FILENAME="I:\_TEMP\???"
Thanks
IMPORT FILENAME="I:\_TEMP\???"
EXPORT_RASTER FILENAME="I:\_TEMP\???"
Thanks
Comments
-
I've actually just added directory looping support for the upcoming v10 release of Global Mapper to make things like this easier. I have a v9 build with this support that you can try. I have placed a new build of Global Mapper 9 with the change at http://www.globalmapper.com/global_mapper9.zip . Simply download that file and extract the contents over your existing v9.xx installation to give it a try.
Here is a sample of how to do a directory loop with the new build:
GLOBAL_MAPPER_SCRIPT VERSION=1.00
UNLOAD_ALL
// Loop over all DEM files in a folder and convert them
DIR_LOOP_START DIRECTORY="C:\DATA\SDTS_DEM\24K\" FILENAME_MASKS="*.DEM.STDS.TAR.GZ" RECURSE_DIR=NO
// Import an archived SDTS DEM file. Global Mapper will automatically
// determine that this is an archived SDTS DEM file and load it
// correctly.
IMPORT FILENAME="%FNAME_W_DIR%" ANTI_ALIAS=YES
// Generate 50 ft contours from the loaded DEM data.
GENERATE_CONTOURS INTERVAL=50 ELEV_UNITS=FEET
// Export the contours to a new DXF file. The created file will have
// 3D polyline features for the contours.
EXPORT_VECTOR FILENAME="%DIR%%FNAME_WO_EXT%_CONTOURS.DXF" TYPE=DXF GEN_PRJ_FILE=YES
// Export the contours to a 3D shape file.
EXPORT_VECTOR FILENAME="%DIR%%FNAME_WO_EXT%_CONTOURS.SHP" TYPE=SHAPEFILE \
SHAPE_TYPE=LINES GEN_3D_LINES=YES GEN_PRJ_FILE=YES
// End the loop
DIR_LOOP_END
Here is the documentation for the DIR_LOOP_START command:
The DIR_LOOP_START command begins a loop of commands over all of the folders within a directory (and optionally its subdirectories) that match one or more filename masks. This is a powerful feature allowing you to do things like easily batch convert a collection of files or perform any other supported operation over a collection of files. You end a loop over the files in a folder using the DIR_LOOP_END command. Note that it is also possible to nest loops.
For any commands found within a DIR_LOOP_START...DIR_LOOP end pair defining a loop, the following special character sequences can be used anywhere (examples of what the values will be based on a current filename of 'C:\data\my_file.dem' are listed):
%DIR% - full path to current file (value is 'C:\data\')
%FNAME_W_DIR% - full path and filename of current file (value is 'C:\data\my_file.dem')
%FNAME% - filename of current file (value is 'my_file.dem')
%FNAME_WO_EXT% - filename of current file without extension (value is 'my_file')
For a sample of the DIR_LOOP_START command in use, see the example at the bottom of this reference.
The following parameters are used by the DIR_LOOP_START command.
DIRECTORY - specifies the directory to search for files in. If you leave this blank, the operation will be based in the current folder.
FILENAME_MASKS - space-separated list of filename masks to import. If no value is provided then all files will be used.
RECURSE_DIR - specifies whether the loop operation will search subdirectories of the specified directory as well as the current one. Use RECURSE_DIR=YES to enable. The default value is to NOT search subdirectories
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Awesome, thanks. I'll give that a try.
Matt
Categories
- 12.7K All Categories
- 5.6K Features Discussion
- 342 Downloading Imagery
- 1.3K Elevation Data
- 380 Georeferencing Imagery Discussion
- 628 GM Script Language
- 53 User Scripts
- 113 GPS Features
- 414 Projection Questions
- 819 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 177 Announcement and News
- 908 Bug Report
- 558 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 562 Other Discussion
- 129 GIS Data Sources
- 27 Global Mapper Showcase
- 233 How I use Global Mapper
- 107 Global Mapper Forum Website