X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 30 Jul 2012 12:30 PM by  anon
Conversion Error Message While Subsetting Image
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
30 Jul 2012 12:30 PM
    Below is the code that we have written to pull the data from the Geo-referenced (lat/long based) subset of a full size image using an EVF. It is running, but returning the error message "Type conversion error: Unable to convert given STRING to Float. Detected at: ENVI_DATA_TYPE_WRITE". I'm not sure what I'm doing wrong here - any suggestions? PRO DrCrkRsz COMPILE_OPT strictarr ;Restore all the base save files ENVI, /restore_base_save_files ;Initialize ENVI and send all errors and warnings to the file batch_log ENVI_BATCH_INIT, log_file='batch_log' ;Change directory to the Folder with Deer Creek dir='D:\IDLTest\Full_Size_Data' ; for full size files CD, dir ;Counts the number of available files. ;Open a Base image and associated ROI. ;This is done to convert the ROI in lat/long ;to pixel coords in the target files (loaded below) BaseFileName='01_BaseImage19850831' ENVI_OPEN_FILE, BaseFileName, R_FID=Bfid ENVI_FILE_QUERY, Bfid, dims=Bdims, ns=Bns, nl=Bnl, nb=Bnb ;print, 'these are the base data', Bns, Bnl, Bnb T_fid=lonarr(Bnb)+Bfid ; array with the band list plus the file id of the base file pos=lindgen(Bnb) ; array with the band numbers ; ; ; Open the vector file that contains the rectangle that includes Deer Creek DrcrkRec='DrcrkRec.evf' DrcrkRec_id=ENVI_EVF_OPEN(DrcrkRec) ;get the vector information from file ENVI_EVF_INFO, DrcrkRec_id, num_recs=num_recs, data_type=data_type, projection=projection, $ layer_name=layer_name ;Print, 'vecto info', num_recs, data_type, projection, layer_name ; create a variable to contain the records in the vector file (for us this should be 1) record=ENVI_EVF_READ_RECORD(DrcrkRec_id, 0) Xmap=record[0,*] Ymap=record[1,*] ; ; files=FILE_SEARCH('*Visible.hdr',COUNT=numfiles) ; for full size files counter=0 WHILE(counter LT numfiles) DO BEGIN name = files[counter] namesplit = STRSPLIT(name, '.', /EXTRACT) namefile = namesplit[0] ;Open the input file ENVI_OPEN_FILE, namefile, R_FID=fid IF (fid EQ -1) THEN BEGIN ENVI_BATCH_EXIT RETURN ENDIF PRINT, namefile ; print name of file ENVI_FILE_QUERY, fid, DIMS = dims, NB = nb, DATA_TYPE=data_type ; Get the size of the image array. print, 'datatype = ', data_type ENVI_CONVERT_FILE_COORDINATES,fid, xf, yf, Xmap, Ymap dims[0]=-1L ; type of dimensions long float dims[1]=min(xf)-1 ; lower x corner - 0 based dims[2]=max(xf)-1 ; uppper x corner - 0 based dims[3]=min(yf)-1 ; same for y dims[4]=max(yf)-1 ; again ;Use ENVI write file to save with new file name outname = namefile +'_' + string(counter,FORMAT='(I2.2)') print, outname ENVI_WRITE_ENVI_FILE,namefile, DIMS=dims,OUT_NAME=outname, R_FID=fid, OUT_DT=4 ; the following section uses numeric coordinates to ; create an output name for each file with numbers ;pos = LINDGEN(nb) ;outnametxt = 'TestFile_' + string(counter) + '.txt' ;OPENW, 100, 'TestOut.txt' ;ENVI_OUTPUT_TO_EXTERNAL_FORMAT, OUT_NAME=outnametxt, DIMS=dims, /ASCII, FID=fid, POS=pos CLOSE, fid counter=counter+1 ENDWHILE END

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    31 Jul 2012 08:03 AM
    Have a look at the example code i this forum post on how to subset an image with an EVF file. This might make your code much more simple: http://www.exelisvis.com/...020/scope/posts.aspx

    Deleted User



    New Member


    Posts:
    New Member


    --
    31 Jul 2012 01:17 PM
    Thank you for that - it was a helpful example. I am very close to getting exactly what I want out of my code, with one exception: One code example that I found used the routine "ENVI_GET_DATA" I used this and got the right subset, but only one band. Is there some keyword or routine that will allow me to get data from all 6 of my bands? Thank you for your help.

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    31 Jul 2012 01:37 PM
    You would have to loop through each band to use ENVI_GET_DATA. Are you trying to read your data into an IDL variable? Because that is what ENVI_GET_DATA is doing. You will then need to write it back out to a new file.
    You are not authorized to post a reply.