X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4886 Rate this article:
No rating

Creating Square ROIs Around Known Points in ENVI Classic

Users sometimes need to create buffer areas around points of interest.  While the buffer zone calculator in ENVI is capable of this, the result is a rounded buffer.  In the case that a user would like a square ROI, the buffer zone process is ineffective. 

The following code will create square ROIs around known points.  The point information must be contained in an ASCII file as output from the ENVI ROI Tool.  If the points are originally contained in an ASCII file of a different format, the points can be input to the ROI Tool via ROI_Type > Input Points from ASCII... and then exported via File > Output ROIs to ASCII...

pro ROI_size_def
;
; This code creates an ROI of square areas of defined side length
; around points contained in an ASCII file previously exported
; from ENVI.
;
close, /all
compile_opt IDL2
; Restore all ENVI base save files
envi, /restore_base_save_files
;
;Initialize ENVI and send all errors and warnings to the file batch.txt
envi_batch_init, log_file='batch.txt'
;
;Open ASCII points file as exported from ENVI ROI Tool:
openr, 1, 'path\pointascii.txt'
;
; Declare list for pixel coords of points:
LL=list()
;
; While there is text in file, test lines for lat/lon info and add to list:
while ~ EOF(1) do begin
   line = '' & READF, 1, line
   line = strsplit(line,' ', /EXTRACT)
   if (line[0] eq '1') then begin
    lineone=fltarr(2)
    lineone[0]=float(line[1])
    lineone[1]=float(line[2])
    LL.add, lineone
   endif
endwhile

;print, LL

;
;Open the input files
envi_open_file, 'inputimage.dat', r_fid=file1_fid
;
; Obtain file dims:
envi_file_query, file1_fid, ns=ns, nl=nl
;print, ns, nl
;
; Obtain pixel size:
map_info=envi_get_map_info(fid=file1_fid)
xsize=map_info.ps[0]
ysize=map_info.ps[1]
;print, xsize, ysize
; Units of pixel size are assumed to be meters
;
; Convert square side length / 2 to pixels:
xlen = 500./xsize
ylen = 500./ysize

;
; Create array of ROI IDs
roiids=lindgen(LL.count())

;
; Create and define ROIs for each point:
for i=0,LL.count()-1 do begin
  loc=LL[i]
  roi_id = envi_create_roi(ns=ns, nl=nl)
  xpts=[loc[0]-xlen, loc[0]+xlen, loc[0]+xlen, loc[0]-xlen, loc[0]-xlen]
  ypts=[loc[1]+ylen, loc[1]+ylen, loc[1]-ylen, loc[1]-ylen, loc[1]+ylen]
  envi_define_roi, roi_id, /polygon, xpts=xpts, ypts=ypts
  roiids[i]=roi_id
endfor

;
; Save ROIs
envi_save_rois, 'path\test.roi', roiids

;
;exit ENVI
envi_batch_exit

close, /all

end
Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »