Why is my VAR_LOOP counter not incrementing
Hi All,
First off I would like to say that my experience with Global Mapper scripting has been very positive, very easy to learn and effective for all of my uses so far. That being said, I am *somewhat* new to scripting with global mapper and I am encountering a problem, probably missing something basic here but on the chance I am not I'd like to reach out for some help. I have done some forum and google search combing, and haven't quite come up with a possible solution. And as far as I can see in the Global Mapper Scripting Reference, it doesn't provide any more details about the counter attribute of VAR_LOOP.
Basically, I have a set of 1000 *.las files I want to import and make an elevation grid out of and export to a GeoTiff. I use our own separate program to tile them up into our company tilescheme. I already reprojected them to WGS84 with another global mapper script. Since my workstation does not have the RAM to import all 1000 las files, create a giant elevation grid out of it and then export it I decided to make 50 smaller GeoTiffs and will use gdalmerge to stitch them together later. I am using some nested looping, but my counters do not seem to be incrementing. I have added logging to track the steps, the behavior right now is that it seems to get stuck in the inner-most loop and exceeds more than 20 file imports (passing my VAL_STOP=20 that I defined).
The logic I desire is:
Loop over reproject_dir -> import the first 20 files -> create an elevation grid -> export elevation as geotiff -> unload all -> import next 20 files -> create elevation grid -> etc etc...
I think maybe it is a problem with where my DIR_LOOP_END statement is placed, but I want it to import 20 files do some things and then continue with the next 20 files. Wouldn't nesting the DIR_LOOP inside of the innermost VAR_LOOP not remember where previous DIR_LOOP last left off?
Any help would be greatly appreciated!
Script ( I am not sure how to embed the script contents, Script also attached as TXT. GMS not allowed to upload ):
GLOBAL_MAPPER_SCRIPT VERSION="1.00" LOG_TO_COMMAND_PROMPT="YES" ENABLE_PROGRESS=YES
First off I would like to say that my experience with Global Mapper scripting has been very positive, very easy to learn and effective for all of my uses so far. That being said, I am *somewhat* new to scripting with global mapper and I am encountering a problem, probably missing something basic here but on the chance I am not I'd like to reach out for some help. I have done some forum and google search combing, and haven't quite come up with a possible solution. And as far as I can see in the Global Mapper Scripting Reference, it doesn't provide any more details about the counter attribute of VAR_LOOP.
Basically, I have a set of 1000 *.las files I want to import and make an elevation grid out of and export to a GeoTiff. I use our own separate program to tile them up into our company tilescheme. I already reprojected them to WGS84 with another global mapper script. Since my workstation does not have the RAM to import all 1000 las files, create a giant elevation grid out of it and then export it I decided to make 50 smaller GeoTiffs and will use gdalmerge to stitch them together later. I am using some nested looping, but my counters do not seem to be incrementing. I have added logging to track the steps, the behavior right now is that it seems to get stuck in the inner-most loop and exceeds more than 20 file imports (passing my VAL_STOP=20 that I defined).
The logic I desire is:
Loop over reproject_dir -> import the first 20 files -> create an elevation grid -> export elevation as geotiff -> unload all -> import next 20 files -> create elevation grid -> etc etc...
I think maybe it is a problem with where my DIR_LOOP_END statement is placed, but I want it to import 20 files do some things and then continue with the next 20 files. Wouldn't nesting the DIR_LOOP inside of the innermost VAR_LOOP not remember where previous DIR_LOOP last left off?
Any help would be greatly appreciated!
Script ( I am not sure how to embed the script contents, Script also attached as TXT. GMS not allowed to upload ):
GLOBAL_MAPPER_SCRIPT VERSION="1.00" LOG_TO_COMMAND_PROMPT="YES" ENABLE_PROGRESS=YES
SET_LOG_FILE FILENAME="C:\GlobalMapperScripts\loop_export_log.txt"
//Define Directory Paths
DEFINE_VAR NAME="LOOP_IMPORT_DIR" VALUE="\\tezcatlipoca\data0\vsource\lidarsource\lasFiles"
DEFINE_VAR NAME="REPROJECT_DIR" VALUE="\\tezcatlipoca\data0\vsource\lidarsource\reproject"
DEFINE_VAR NAME="EXPORT_DIR" VALUE="\\tezcatlipoca\data0\vsource\lidarsource\geoTiff_export\CA_DayFire"
//Define file names to process loop over
DEFINE_VAR NAME="FILE_TO_PROC" VALUE="*.las"
LOG_MESSAGE %DATE% %TIME% Script <%SCRIPT_FILENAME%> started
LOG_MESSAGE %DATE% %TIME% Starting batch import of reprojected files
DIR_LOOP_START DIRECTORY="%REPROJECT_DIR%" FILENAME_MASKS="%FILE_TO_PROC%"
VAR_LOOP_START VAL_START=1 VAL_STOP=50 VAL_STEP=1 VAR_NAME="%BATCH_NUM%"
VAR_LOOP_START VAL_START=1 VAL_STOP=20 VAL_STEP=1 VAR_NAME="%LOOP_NUM%"
IMPORT FILENAME="%FNAME_W_DIR%" TYPE=LIDAR_LAS SAMPLING_METHOD=BILINEAR ELEV_FIELD=ELEVATION ELEV_UNITS=METERS
LOG_MESSAGE %DATE% %TIME% Done importing %FNAME% ; Took %TIME_SINCE_LAST_LOG%
LOG_MESSAGE Batch: %BATCH_NUM% Loop: %LOOP_NUM%
DIR_LOOP_END
VAR_LOOP_END
LOG_MESSAGE %DATE% %TIME% Creating elvation grid....
GENERATE_ELEV_GRID ELEV_UNITS=METERS GRID_ALG=BIN_MIN GRID_SAVE_TIN=YES LIDAR_FILTER="ALL" LIDAR_RETURN_FILTER="ALL"
LOG_MESSAGE %DATE% %TIME% Done creating elevation grid ; Took %TIME_SINCE_LAST_LOG%
LOG_MESSAGE %DATE% %TIME% Exporting elevation grid
EXPORT_ELEVATION FILENAME="%EXPORT_DIR%\CA_DayFire_%BATCH_NUM%.tif" TYPE=GEOTIFF ELEV_UNITS=METERS
SAMPLING_METHOD=BICUBIC BYTES_PER_SAMPLE=4
SAMPLING_METHOD=BICUBIC BYTES_PER_SAMPLE=4
LOG_MESSAGE %DATE% %TIME% Done exporting elevation grid ; Took %TIME_SINCE_LAST_LOG%
LOG_MESSAGE %DATE% %TIME% Batch %BATCH_NUM% of 50 complete
LOG_MESSAGE --------------------------------------------------------------
UNLOAD_ALL
VAR_LOOP_END
LOG_MESSAGE %DATE% %TIME% Total script run time %TIME_SINCE_START%
Tagged:
Comments
-
Hello,
You are correct that your DIR_LOOP_END is in the wrong place. When you nest loops, the ends must be reverse order of the starts. When Global Mapper is processing a script, the VAR_LOOP_END command is what causes your loop variable to be incremented. For example:DIR_LOOP_START
Note that the way you have your loops nested, the two VAR_LOOPs will run in their entirety for every file in the DIR_LOOP. The commands inside the DIR_LOOP get run for every file in the loop.
VAR_LOOP_START
VAR_LOOP_START
// Do stuff here
VAR_LOOP_END
VAR_LOOP_END
DIR_LOOP_END
Cheers,
Bob -
Hi Bob,
Thanks for getting a reply so quickly. I originally had my DIR_LOOP_END in the place you suggested. If my DIR_LOOP_END is outside of the VAR_LOOP, the VAR_LOOP increments 20 times over the same file because DIR_LOOP never moves on to the next file. So if I take this script to completion, it will do 20 import loops over the same file, create and export the elevation grid, and repeat all of that 50 times. Basically, it will do 1000 loops on each file before incrementing to the next one in the DIR_LOOP.
Any suggestion on where to go from here?
Thanks
-
Hello,
Have you tried using a Map Catalog? It is useful when you need to handle large numbers of files. When you export tiles, it only loads the data required for the tiles being exported, so you don't need to worry about having enough memory to load all of the files at the same time. Look for "Map Catalog" in the Help index for more information.
Cheers,
Bob -
Hi Bob,
Looks like the Map Catalog option will work for this, I have run through our process a few times and I am getting the desired output.
I reworked the script to add all the reprojected files to the map catalog. This works great, but when the script reaches the point where it wants to add the *las files to the catalog it prompts me to specify the lidar import options. I simply apply to all files and the script continues, but is there a way for me to bypass that prompt?
My command is below ( \ = line continuation):
EDIT_MAP_CATALOG FILENAME="%MAPCATALOG_DIR%\%MAPCATALOG_FILE%.gmc" \ CREATE_IF_EMPTY=YES ADD_FILE="%REPROJECT_DIR%\%FILE_TO_PROC%" \ ZOOM_DISPLAY="PERCENT,0.10,0"
My %FILE_TO_PROC% value is "*.las".
I tried adding a TYPE=LIDAR_LAS to the EDIT_MAP_CATALOG but I am still prompted for the lidar import options.
Thanks for your help
-
airborne_ronin said:I reworked the script to add all the reprojected files to the map catalog. This works great, but when the script reaches the point where it wants to add the *las files to the catalog it prompts me to specify the lidar import options. I simply apply to all files and the script continues, but is there a way for me to bypass that prompt?
Cheers,
Bob -
I've added support for adding LOAD_FLAGS to the EDIT_MAP_CATALOG to pass along flags for any load options so you can skip the load prompt for Lidar LAS/LAZ files. To see the LOAD_FLAGS value to use, load a LAS file in Global Mapper and select the options you want, then save a .gmw file. Load the .gmw file in Notepad and copy out the LOAD_FLAGS value and use it with your EDIT_MAP_CATALOG command.
I have placed new builds with the latest changes at http://data.bluemarblegeo.com/downloads/global-mapper/dailybuilds/ for you to try.
Thanks,
Mike
Global Mapper Guru
geohelp@bluemarblegeo.com
http://www.bluemarblegeo.com/
Categories
- 12.8K All Categories
- 5.7K Features Discussion
- 346 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 639 GM Script Language
- 54 User Scripts
- 115 GPS Features
- 417 Projection Questions
- 829 Raster Data
- 1.3K Vector Data
- 6.6K Support
- 179 Announcement and News
- 922 Bug Report
- 559 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 573 Other Discussion
- 131 GIS Data Sources
- 27 Global Mapper Showcase
- 241 How I use Global Mapper
- 108 Global Mapper Forum Website