/*----------------------------------------------------------------------------*/ /* ProcessImageryExtractRegionFromMrSID */ /*----------------------------------------------------------------------------*/ // Macro declaration and variables for property sheet. macro ProcessImageryExtractRegionFromMrSID( string output_file_path, string batch_file_name, string sid_application_name, string input_sid_file, string high_output_prefix, string low_output_prefix, string output_file_identifier, int width_of_sid_file, int height_of_sid_file, int start_upper_left_x, int start_upper_left_y, int output_tile_width_x, int output_tile_height_y, int output_cols, int output_rows, string gdal_application_name, int gdal_output_tile_width, int gdal_output_tile_height ) // Command header, category, GUID, and image. [ Category="Application Commands", Guid="{C2B9DB5F-9D84-48B0-BEE2-2E24B35885A2}", Image=".\\icons\\generic_script_icon.bmp"] // Main loop { //////////////////////////////////////////////////////////////////////////////// // MRSIDGEODECODE_WIN.EXE Application Variables // string output_file_path; /* Path where output files are written. */ // string batch_file_name; /* Name of batch file written to disk. */ // string sid_application_name; /* Name of command line executable to run. */ string flag_i = "-i "; /* Input file flag. Leave alone. */ string flag_o = "-o "; /* Output file flag. Leave alone. */ string flag_ulxy = " -ulxy "; /* Upper left corner flag. Leave alone. */ string flag_f = "-of tifg "; /* Output file format. Leave alone. */ string flag_wh = " -wh "; /* Width/Height flag. Leave alone. */ // string input_sid_file; /* Actual MrSID image file name. */ // string high_output_name; /* Modifier for high-resolution file name. */ // string output_file_identifier; /* Modifier for file name. */ string output_file_extension = ".tif"; /* Output file extension. Leave alone. */ string output_scale = " -s 4"; /* Can be 0, 2 or 4. Leave alone. */ //////////////////////////////////////////////////////////////////////////////// // Input Variables That Control Resizing Start/End // int width_of_sid_file; /* Width of MrSid image in pixels. */ // int height_of_sid_file; /* Height of MrSid image in pixels. */ // int start_upper_left_x; /* Upper left corner X position in pixels. */ // int start_upper_left_y; /* Upper left corner Y position in pixels. */ // int output_tile_width_x; /* Width of each tile in pixels along x. */ // int output_tile_height_y; /* Height of each tile in pixels along x. */ // int output_cols; /* Number of output columns. */ // int output_rows; /* Number of output rows. */ // int gdal_output_tile_width; /* Resolution along x of low resolution tiles. */ // int gdal_output_tile_height; /* Resolution along y of low resolution tiles. */ //////////////////////////////////////////////////////////////////////////////// // GDAL_TRANSLATE.EXE Application Variables // string gdal_application_name; /* Name of command line executable to run. */ string gdal_output_format = "-of GTiff "; /* Name of output format using GDAL command line terminology. Leave alone. */ string gdal_scalar_flag = "-outsize "; /* Name of GDAL scaling flag to use. Leave alone. */ // string low_output_name; /* Modifier for low-resolution file name. */ //////////////////////////////////////////////////////////////////////////////// // Initialize a few variables correctly for offsets. Sort of a hack but keeps this loop very simple. :-) Leave this alone! start_upper_left_x = start_upper_left_x - output_tile_width_x; start_upper_left_y = start_upper_left_y - output_tile_height_y; output_cols = output_cols + 1; output_rows = output_rows + 1; //////////////////////////////////////////////////////////////////////////////// // Inner/Outer Loop // Validate property editor inputs. If missing, warn and return to property editor. if ( output_file_path == "" ) { Application.MessageBox( 0, "You did not specify an output file path!", "Warning" ); return; } if ( sid_application_name == "" ) { Application.MessageBox( 0, "You did not specify a name for the batch file!", "Warning" ); return; } if ( sid_application_name == "" ) { Application.MessageBox( 0, "You did not specify a MrSID executable!", "Warning" ); return; } if ( input_sid_file == "" ) { Application.MessageBox( 0, "You did not specify a MrSID file!", "Warning" ); return; } if ( width_of_sid_file == 0 ) { Application.MessageBox( 0, "You did not specify the width of the MrSID file!", "Warning" ); return; } if ( height_of_sid_file == 0 ) { Application.MessageBox( 0, "You did not specify the height of the MrSID file!", "Warning" ); return; } if ( output_tile_width_x == 0 ) { Application.MessageBox( 0, "You did not specify the Output Tile Width!", "Warning" ); return; } if ( output_tile_height_y == 0 ) { Application.MessageBox( 0, "You did not specify the Output Tile Height!", "Warning" ); return; } if ( output_cols == 0 ) { Application.MessageBox( 0, "You did not specify the number of columns!", "Warning" ); return; } if ( output_rows == 0 ) { Application.MessageBox( 0, "You did not specify the number of rows!", "Warning" ); return; } if ( gdal_application_name == "" ) { Application.MessageBox( 0, "You did not specify a GDAL executable!", "Warning" ); return; } if ( gdal_output_tile_width == 0 ) { Application.MessageBox( 0, "You did not specify the GDAL Output Tile Width!", "Warning" ); return; } if ( gdal_output_tile_height == 0 ) { Application.MessageBox( 0, "You did not specify the GDAL Output Tile Height!", "Warning" ); return; } int validate_subdivision_coordinates_x = ( start_upper_left_x + ( output_cols * output_tile_width_x ) ); int validate_subdivision_coordinates_y = ( start_upper_left_y + ( output_rows * output_tile_height_y ) ); if ( validate_subdivision_coordinates_x > width_of_sid_file || validate_subdivision_coordinates_x < 0 ) { Application.MessageBox( 0, "Your subdivision parameters are outside the boundary of the MrSID file!", "Warning" ); return; } if ( validate_subdivision_coordinates_y > height_of_sid_file || validate_subdivision_coordinates_y < 0 ) { Application.MessageBox( 0, "Your subdivision parameters are outside the boundary of the MrSID file!", "Warning" ); return; } string dir_output_file = output_file_path + "dir_temp.txt"; string dir_command = "cmd /c \"dir " + output_file_path + "\*.sid /B > " + dir_output_file + "\""; Application.RunProgram( dir_command, "Generating File List...", 1, 1 ); TextFile imagery_list_file = new TextFile; if ( !imagery_list_file.Open( dir_output_file, true ) ) { Application.MessageBox( 0, "Imagery list file could not be opened.", "Warning" ); return; } string batch_file_full_path = output_file_path + "\\" + batch_file_name; TextFile batch_file = new TextFile; if ( ! batch_file.Open ( batch_file_full_path, false ) ) { Application.MessageBox( 0, "Batch file could not be written!", "Warning" ); return; } int imagery_file_count = 0; while( 1 ) { if( imagery_list_file.IsEndOfFile() ) { break; } string imagery_file_name = imagery_list_file.ReadLine(); //output_file_identifier ++imagery_file_count; string cur_output_file_delimiter = output_file_identifier + imagery_file_count; for ( int cols = 1; cols < output_cols; ++cols ) { for ( int rows = 1; rows < output_rows; ++rows ) { // Create the string that creates the image tile by using MRSIDGEODECODE_WIN.EXE and GDAL_TRANSLATE.EXE. Move the files as well. string sid_command_line = output_file_path + sid_application_name + " " + flag_i + output_file_path + imagery_file_name + " " + flag_f + flag_o + output_file_path + high_output_prefix + "_" + cur_output_file_delimiter + "_" + cols + "x" + rows + output_file_extension + flag_ulxy + ( start_upper_left_x + output_tile_width_x * cols ) + " " + ( start_upper_left_y + output_tile_height_y * rows ) + flag_wh + output_tile_width_x + " " + output_tile_height_y + "\n" + output_file_path + gdal_application_name + " " + gdal_output_format + gdal_scalar_flag + gdal_output_tile_width + " " + gdal_output_tile_height + " " + output_file_path + high_output_prefix + "_" + cur_output_file_delimiter + "_" + cols + "x" + rows + output_file_extension + " " + output_file_path + low_output_prefix + "_" + cur_output_file_delimiter + "_" + cols + "x" + rows + output_file_extension + "\n" + "move " + output_file_path + "h*.tif \"C:\\Scenomics\\Exercises\\lewis_county\\high_resolution_processed_imagery\"" + "\n" + "move " + output_file_path + "l*.tif \"C:\\Scenomics\\Exercises\\lewis_county\\low_resolution_processed_imagery\"" + "\n"; batch_file.Write( sid_command_line ); } } } delete batch_file; Application.RunProgram ( batch_file_full_path, "Image: SID subdivision underway...", 1, 0 ); }