X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 29 Oct 2015 11:24 AM by  anon
Stack rasters by Indice
 4 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
29 Oct 2015 11:24 AM
    I have 'n' number of time sequential but spatially static raster files that each have three layers, each layer is a different calculation for vegetation (fairly irrelevant to this part of the code). What I would like to do is read in all n number of raster files and output the first band from each file to a new raster that will be called Veg1 and will have n layers. So on for Veg2 and Veg3. The newest version of ENVI has a BUILD_BAND_STACK routine that will be the ticket to compiling the final three datasets, but my primary hangup is reading in the initial files. Any suggestions on how to read in or query multiple files would be immensely helpful.Thanks

    Deleted User



    New Member


    Posts:
    New Member


    --
    31 Oct 2015 01:23 PM
    <p>I don't completely understand your question, but to read files you can do something like this:</p> <p><br /> </p> <p>;location where rasters are located<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> cd, 'C:\files'</p> <p>;change .dat to extension of your files<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> files = FILE_SEARCH('*.dat', count=count)</p> <p>;initiate loop&nbsp;<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> &nbsp;foreach file, files do begin<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> &nbsp;&nbsp;<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> &nbsp; &nbsp; ;input raster&nbsp;<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> &nbsp; &nbsp; infile = file<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> &nbsp; &nbsp; infile_path = FILEPATH(infile,ROOT_DIR='C:\files')</p> <p>&nbsp; &nbsp; ;Load the input raster<br style="outline: 0px; margin: 0px; height: 1px; padding: 0px;" /> &nbsp; &nbsp; input_raster = e.OpenRaster(infile_path)</p> <p>&nbsp; &nbsp; endforeach</p> <p>end<br /> <br /> </p> <p><br /> </p>

    Deleted User



    New Member


    Posts:
    New Member


    --
    03 Nov 2015 03:49 PM
    Hi Stefano, <p>Thank you for replying.&nbsp;</p> <p>The routine you suggest does work well when I need to perform a function on each individual image. As an example its how I read in each file to do the vegetation calculations. Or as I think of it: 1 file in -&gt;do an operation-&gt; results out. What I'm trying to do is read in multiple files, anywhere from 2 to many, and take the first band, in this case the result of a vegetation calculation and make one file that is the temporal results of the veg calculation. Many files in -&gt; restack band 1-&gt;one file out. Does that help clarify my problem?</p> <p>I've been trying to find someone that used the e.openraster() function with the result being an indexed variable for each of the many inputs.&nbsp;</p> <p>Something like:&nbsp;</p> <p>;Load the input raster&nbsp;</p> <p>input_raster[0] = e.OpenRaster(infile_path)</p> <p>that with each loop through the variable input_raster would be updated with a unique number.</p> <p>Laura</p>

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    04 Nov 2015 08:51 AM
    <p>Hi Laura,</p> <p><br /> </p> <p>Expanding upon Stefano's example, I think that something like this may be what you are looking for:</p> <p>;start envi if needed<br /> e = envi(/current) ;get current session of envi<br /> if (e eq !NULL) then e = envi(/headless);if doesnt exist start new headless session<br /> <br /> ;directory with the data files<br /> dir = 'C:\some\location\with\data'<br /> ;save first directory<br /> cd, current = first_dir<br /> ;location where rasters are located<br /> cd, dir<br /> ;search current directory for specific files<br /> files = FILE_SEARCH('*.dat')<br /> nfiles = n_elements(files)<br /> ;initialize array to hold raster references<br /> rasters = objarr(nfiles)<br /> <br /> ;open each raster<br /> for i=0, nfiles -1 do begin<br /> &nbsp; &nbsp; &nbsp;rasters[i] = e.OpenRaster(file)<br /> end<br /> <br /> ;return to first directory<br /> cd, first_dir</p> <p><br /> </p> <p>Depending upon what you want to do with your data, you can always just make an array within IDL with all of your bands and you can pick pixel locations and plot it. If you want to build a time series you may be interested in the ENVIBuildTimeSeriesTask. Here is a link to the docs:</p> <p>http://www.exelisvis.com/...sTask.html</p> <p>I hope this helps!</p> <p><br /> </p>

    Deleted User



    New Member


    Posts:
    New Member


    --
    26 Jan 2016 02:55 PM
    Hi Zachary, This note feels like I wrote it forever ago! Thank you for your response. Reading in the files and using an nfiles variable worked well. based on your time series suggestion I discovered it was best to use ENVITask('RegridRasterSeriesByUnion'), because the input files did not have consistent extents and they needed to be standardized before they were read into the ENVI Layer Stack task. Thanks for the help.
    You are not authorized to post a reply.