Global Mapper Pro

Can Loops Be Nested In Other Loops?

kbellis
kbellis Global Mapper UserTrusted User
edited October 2013 in GM Script Language
With many thanks to Tim & Mike, I think I'm inching closer to a solution to the question posted earlier.
GLOBAL_MAPPER_SCRIPT VERSION=1.00
// Tuesday, October 15, 2013, 10:01 AM, VKB - Filtered Export Scripting - Is It Possible?
// Answer: Yes, but not wholly from Global Mapper; will require successive steps and other software
//
// Where should we go to get our data?
// 
DEFINE_VAR NAME="INPUT" VALUE="c:\mcctests\data" 

// First load the unclassified lidar data into their own group
DIR_LOOP_START \
    DIRECTORY="%INPUT%" \
    FILENAME_MASKS="*.LAS" \
    RECURSE_DIR=NO
    
    IMPORT FILENAME="%FNAME_W_DIR%" TYPE="LIDAR_LAS" LAYER_GROUP="unclassified" \
         LOAD_FLAGS="1048576,6.000,0,2~0~0~0~0~0~0~0,,4294967295,0.00,5.00,1" \
         LIDAR_POINT_SIZE="1"
    
DIR_LOOP_END

// Next load the data classified as ground into their own group
DIR_LOOP_START \
    DIRECTORY="%INPUT%" \
    FILENAME_MASKS="*.LAS" \
    RECURSE_DIR=NO
    
    IMPORT FILENAME="%FNAME_W_DIR%" TYPE="LIDAR_LAS" LAYER_GROUP="ground" \
         LOAD_FLAGS="1048576,6.000,0,4~0~0~0~0~0~0~0,,4294967295,0.00,5.00,1" \
         LIDAR_POINT_SIZE="1"
    
DIR_LOOP_END

// Now we prepare the text file for final winnowing in TextPad - WildEdit before bringing into OpenOffice Calc
EXPORT_METADATA FILENAME="*.las" METADATA_FILENAME="%INPUT%.txt"

This sets the scene for the next bit and the question: Can loops be nested?

The concept being, for example, running the bit above for all folders under c:\mcctests; i.e.,
Directory of C:\mcctests

10/12/2013  09:59 AM    <DIR>          data
10/11/2013  05:53 PM    <DIR>          s10t03m
10/11/2013  05:42 PM    <DIR>          s11t03m
10/11/2013  05:32 PM    <DIR>          s12t03m
10/11/2013  05:11 PM    <DIR>          s13t03m
10/11/2013  05:02 PM    <DIR>          s14t03m
10/11/2013  04:52 PM    <DIR>          s15t03m

And the net result being, for example:
data.txt
s10t03m.txt
s11t03m.txt
s12t03m.txt
s13t03m.txt
s14t03m.txt
s15t03m.txt

Comments

  • global_mapper
    global_mapper Administrator
    edited October 2013
    You can use RECURSE_DIR=YES to recurse through the entire directory tree, or you can also nest the DIR_LOOP_START...DIR_LOOP_END to do different operations. The special loop variables (%FNAME_W_DIR%, %DIR%, etc.) for DIR_LOOP_START will refer to the most nested loop you are in. If you need to access the values from a higher level loop you should use DEFINE_VAR to assign it to a variable before nesting down into a new DIR_LOOP_START...DIR_LOOP_END. Then you can use that variable in the nested loops.

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • kbellis
    kbellis Global Mapper User Trusted User
    edited October 2013
    Cool!

    I think I understand ... and this seems to almost work like I'd envisioned; except for the name of the file which neatly lands in each sub-directory is simply named .txt - the intended idea was for it was that it would be named for the directory to which it related; e.g.,
    Directory of C:\mcctests\data
    
    10/15/2013  07:00 PM    <DIR>          .
    10/15/2013  07:00 PM    <DIR>          ..
    10/15/2013  07:00 PM             9,702 [B].txt[/B] [COLOR=#b22222]<- this should have come out as [B]data.txt[/B][/COLOR]
    03/02/2011  07:29 PM        31,699,314 19_05604899.las
    03/02/2011  07:28 PM        34,042,746 19_05604900.las
    03/02/2011  07:31 PM        26,899,442 19_05614899.las
    03/02/2011  07:31 PM        49,980,122 19_05614900.las
    03/03/2011  06:00 PM        34,887,000 19_05624899.las
    03/03/2011  06:00 PM        11,176,572 19_05624900.las
    
    
     Directory of C:\mcctests\s10t03m
    
    10/15/2013  07:15 PM    <DIR>          .
    10/15/2013  07:15 PM    <DIR>          ..
    10/15/2013  07:00 PM            10,295 [B].txt[/B] [COLOR=#b22222]<- this should have come out as [B]s10t03m.txt[/B][/COLOR]
    10/11/2013  05:44 PM        31,699,314 19_05604899.las-out.las
    10/11/2013  05:46 PM        34,042,746 19_05604900.las-out.las
    10/11/2013  05:47 PM        26,899,442 19_05614899.las-out.las
    10/11/2013  05:49 PM        49,980,122 19_05614900.las-out.las
    10/11/2013  05:51 PM        34,887,000 19_05624899.las-out.las
    10/11/2013  05:53 PM        11,176,572 19_05624900.las-out.las
    

    What am I missing in order to get the name right?

    GLOBAL_MAPPER_SCRIPT VERSION=1.00
    // Tuesday, October 15, 2013, 6:41 PM, VKB - Filtered Export Scripting - Is It Possible?
    // Answer: Yes, but not wholly from Global Mapper; will require successive steps and other software
    //
    // Where should we go to get our data?
    // 
    
    
    // First crack at nesting loops
    DEFINE_VAR NAME="PARENT" VALUE="c:\mcctests" 
    
    DIR_LOOP_START \
        DIRECTORY="%PARENT%" \
        RECURSE_DIR=YES
    
    DEFINE_VAR NAME="INPUT" VALUE="%DIR%" 
    
    // First load the unclassified lidar data into their own group
    DIR_LOOP_START \
        DIRECTORY="%INPUT%" \
        FILENAME_MASKS="*.LAS" \
        RECURSE_DIR=NO
        
        IMPORT FILENAME="%FNAME_W_DIR%" TYPE="LIDAR_LAS" LAYER_GROUP="unclassified" \
             LOAD_FLAGS="1048576,6.000,0,2~0~0~0~0~0~0~0,,4294967295,0.00,5.00,1" \
             LIDAR_POINT_SIZE="1"
        
    DIR_LOOP_END
    
    // Next load the data classified as ground into their own group
    DIR_LOOP_START \
        DIRECTORY="%INPUT%" \
        FILENAME_MASKS="*.LAS" \
        RECURSE_DIR=NO
        
        IMPORT FILENAME="%FNAME_W_DIR%" TYPE="LIDAR_LAS" LAYER_GROUP="ground" \
             LOAD_FLAGS="1048576,6.000,0,4~0~0~0~0~0~0~0,,4294967295,0.00,5.00,1" \
             LIDAR_POINT_SIZE="1"
        
    DIR_LOOP_END
    
    // Now we prepare the text file for final winnowing in TextPad - WildEdit before bringing into OpenOffice Calc
    EXPORT_METADATA FILENAME="*.las" METADATA_FILENAME="%INPUT%.txt"
    
    // Clean it out and start over in next subdirectory
    UNLOAD_ALL
    
    DIR_LOOP_END
    
  • global_mapper
    global_mapper Administrator
    edited October 2013
    You are just specifying the path to the export metadata filename then .txt as the filename. So if the path is 'c:\mcctests\data', your METADATA_FILENAME would be 'c:\mcctests\data\.txt'. You want to use the following:

    EXPORT_METADATA FILENAME="*.LAS" METADATA_FILENAME="%INPUT%%PARENT_DIR%.txt"

    Thanks,

    Mike
    Global Mapper Guru
    geohelp@bluemarblegeo.com
    Blue Marble Geographics for Coordinate Conversion, Image Reprojection and Vector Translation
  • kbellis
    kbellis Global Mapper User Trusted User
    edited October 2013
    Like a charm - it worked :)

    Perfect - thanks for the help Mike.

    Kelly
Sign In or Register to comment.