Table of Contents
Scripts > ClipGeotTiffAndExportAsBmp
Script contents// Author: A. Torpy // Updated: 14 Jul 2011 // create and initialise a file selector filesel FS filesel.Init &FS true NULL "GeoTIFF files (*.tif)|*.tif|All files (*.*)|*.*|" "tif" NULL // ask user for input filename using file selector if <not <EditUI &FS "Select GeoTIFF file">> echo "Script aborted by user" return false endif // load the map file map InputHF if <not <map.LoadFile2 &InputHF <filesel.GetPathA &FS> 20 true true>> echo "Cannot load file" return false endif // get the map size int nx ny set nx <map.GetWidth &InputHF> set ny <map.GetHeight &InputHF> if <not <and nx ny>> echo "Invalid map size" return false endif // prepare a coordinate list for user to edit varlist ls int ls.x1 ls.x2 ls.y1 ls.y2 set ls.x1 0 set ls.x2 <sub nx 1> set ls.y1 0 set ls.y2 <sub ny 1> // edit coordinate list if <not <EditUI &ls "Enter clipping region">> echo "Script aborted by user" return false endif // retrieve coordinates from list (for shorthand) int x1 x2 y1 y2 set x1 ls.x1 set x2 ls.x2 set y1 ls.y1 set y2 ls.y2 // validate coordinates assert <not <or <islt x1 0> <isgt x1 <sub nx 1>>>> "Invalid x1 coordinate" assert <not <or <islt x2 0> <isgt x2 <sub nx 1>>>> "Invalid x2 coordinate" assert <not <or <islt y1 0> <isgt y1 <sub ny 1>>>> "Invalid y1 coordinate" assert <not <or <islt y2 0> <isgt y2 <sub ny 1>>>> "Invalid y2 coordinate" assert <not <isgt x1 x2>> "Invalid coordinates: x1>x2" assert <not <isgt y1 y2>> "Invalid coordinates: y1>y2" // get output map size int cx cy set cx <add <sub x2 x1> 1> set cy <add <sub y2 y1> 1> // initialise output map map OutputHF //if <not <map.Init &OutputHF cx cy 20 1 false>> // echo "Cannot initialise heightfield" // return false //endif if <not <calc.map.CopyArea &InputHF x1 y1 cx cy &OutputHF 0 0 0x01>> echo "Invalid map size" return false endif // re-initialise file selector filesel.Init &FS false NULL "Bitmap images (*.bmp)|*.bmp|All files (*.*)|*.*|" "bmp" NULL // ask user for output filename using file selector if <not <EditUI &FS "Enter output filename">> echo "Script aborted by user" return false endif if <not <map.SaveFile2 &OutputHF <filesel.GetPathA &FS> false true>> echo "Cannot save heightfield" return false endif MessageBox "Success!" 0x40 return true CommentsNone. Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
|