Internal: How To Convert Map Projections In ENVI Batch Mode
Anonym
Topic:
I have many files which I need to convert into the same map projection. How can I use Batch Mode to automate the task?
Discussion:
Large amounts of repetitive processing, such as map reprojections, is one of the best uses of ENVI Batch Mode.
The basic steps for reprojecting a file would include:
- Starting ENVI batch mode.
- Select the file(s) for reprojection.
- Get necessary information about the file using ENVI_FILE_QUERY and ENVI_GET_PROJECTION.
- Create the desired projection for output using ENVI_TRANSLATE_PROJECTION_NAME and ENVI_PROJ_CREATE.
- Set the parameters for the conversion, such as output name and warp points.
- Convert the file using ENVI_CONVERT_FILE_MAP_PROJECTION.
- Closing ENVI batch mode.
While working within ENVI's batch mode, a properly structured FOR loop will allow for as many files to be processed as necessary.
Following is an example of a programmatic reprojection of the ENVI sample data, a Landsat TM scene of Bighorn Basin, Wyoming. The program opens, queries, reprojects the file into a Miller Cylindrical projection, and saves the result as a GeoTIFF.
DISCLAIMER
This additional functionality is provided free of charge as a service for our ENVI users; however, this procedure is not supported by Research Systems Technical Support. The procedure reproj_demo.pro has been been tested and we believe that it works correctly, but it is in no way guaranteed.
--------------------------------------------------------------------------------
pro reproj_demo
; This is a demonstration of ENVI's batch reprojection capabilities
; Research Systems, Inc.
; A Kodak Company
; Always include this line to account for early IDL code not distinguishing
; between ( ) and [ ] for array indexing. Note that this means you must
; properly use square brackets, [ ], to index your arrays.
compile_opt STRICTARR
; Initiate ENVI in batch mode
envi, /restore_base_save_files
envi_batch_init
; Open your data file for reprojection.
filename = 'C:\bhtmref.img'
ENVI_OPEN_FILE, filename, r_fid=fid
; Always try to account for errors that may arise. Here we're
; allowing a return if no input file is found.
if (fid eq -1) then begin
print, 'Could not find input file. Ending.'
envi_batch_exit
return
endif
; Collect some necessary information about the input file.
ENVI_FILE_QUERY, fid, ns=ns, nl=nl, nb=nb, bnames=bnames
; Use the information from ENVI_FILE_QUERY to set up several
; necessary parameters.
dims = [-1L, 0, ns-1, 0, nl-1]
pos= lindgen(nb)
; Here we use the ENVI_GET_PROJECTION routine to obtain the original
; pixel size of the input file.
i_proj=ENVI_GET_PROJECTION(fid=fid, pixel_size=o_pixel_size)
; The necessary parameters for any desired projection are specified in Appendix D
; of the User's Guide. Here, we're specifying 'r', 'lon0', 'x0', and 'y0'.
bhtmref_params = dblarr(15)
bhtmref_params[0]= 6378137.0D
bhtmref_params[1]= -107.6899300D
bhtmref_params[2]= 0.0D
bhtmref_params[3]= 0.0D
; ENVI tracks projections by numeric identifiers. For user convenience,
; the ENVI_TRANSLATE_PROJECTION_NAME routine allows the
; conversion between the string name of the projection (as found in the
; map_proj.txt file) and the ENVI identifier.
proj_type=ENVI_TRANSLATE_PROJECTION_NAME('Miller Cylindrical')
; Because users have full control over the parameters of a projection, they must
; be specified in creating the desired output projection (stored as a structure
; variable). The ENVI_PROJ_CREATE routine allows users to create the
; appropriate projection structure.
o_proj=ENVI_PROJ_CREATE(type = proj_type, params = bhtmref_params, $
name='Bighorn Miller Cylindrical', datum = 'NAD 83')
; Be sure to specify the name of the output file. The full path must also be included.
out_name='C:\bhtm_reproj.dat'
; ENVI allows the user to specify how densely the GCPs (warp points) will be
; spaced in developing the warp model for reprojection. Here, we specify the
; points to be every 25 pixels in both the x and y directions.
grid = [25,25]
; Finally, the actual projection conversion routine. All of the above input parameters are
; now required as keyword inputs.
ENVI_CONVERT_FILE_MAP_PROJECTION, fid=fid, dims=dims, pos=pos, degree=1, $
background = 0, grid=grid, o_pixel_size=o_pixel_size, warp_method=0, $
out_bname=bnames, o_proj=o_proj , resampling=1, out_name=out_name, r_fid=o_fid
; The following section also outputs the result as a TIFF file.
out_name='C:\bhtm_reproj.tif'
; Of course, the file dimensions after reprojection are different than the original input file
; dimensions. We need to find those new dimensions to have the correct size TIFF output.
ENVI_FILE_QUERY, o_fid, ns=ns, nl=nl, nb=nb
dims = [-1L,0,ns-1, 0, nl-1]
pos = lindgen(nb)
ENVI_OUTPUT_TO_EXTERNAL_FORMAT, dims=dims, fid=o_fid, out_name=out_name, $
pos=pos, /tiff
; Don't forget to close out the batch mode.
ENVI_BATCH_EXIT
end