X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 22 Nov 2015 12:53 PM by  anon
VectorMaskRaster not executing
 5 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
22 Nov 2015 12:53 PM
    <p>I am masking an image based on 50 some vector shapefiles using the following code:</p> <p>pro CIR_vector<br /> <br /> &nbsp; e=ENVI()<br /> &nbsp; &nbsp; cd, current = first_dir<br /> &nbsp;&nbsp;<br /> &nbsp; &nbsp; ;location where NAIP image is located<br /> &nbsp; &nbsp; cd, 'F:\Sheyenne\NDVI_comparison\mosaic'<br /> &nbsp; &nbsp; files = FILE_SEARCH('*.dat', count=count)<br /> &nbsp; &nbsp; cd, first_dir<br /> &nbsp;&nbsp;<br /> &nbsp; &nbsp; ;output location to save roi subsets to<br /> &nbsp; &nbsp; thisdir = 'F:\Sheyenne\NDVI_comparison\Subset'<br /> &nbsp;&nbsp;<br /> &nbsp; &nbsp; ;initiate loop on VI files<br /> &nbsp; &nbsp; foreach file, files do begin<br /> &nbsp;&nbsp;<br /> &nbsp; &nbsp; &nbsp; ;input raster<br /> &nbsp; &nbsp; &nbsp; infile = file<br /> &nbsp; &nbsp; &nbsp; infile_path = FILEPATH(infile,ROOT_DIR='F:\Sheyenne\NDVI_comparison\mosaic')<br /> &nbsp;&nbsp;<br /> &nbsp; &nbsp; &nbsp; ;save the date located within filename for later use<br /> &nbsp; &nbsp; &nbsp; date = strmid(infile_path,15,7, /REVERSE_OFFSET)</p> <p > &nbsp; &nbsp; &nbsp; ; &nbsp; &nbsp;Load the input raster<br /> &nbsp; &nbsp; &nbsp; input_raster = e.OpenRaster(infile_path)</p> <p > &nbsp; &nbsp; &nbsp; ;set new pathway where roi files are located<br /> &nbsp; &nbsp; &nbsp; cd, 'F:\Sheyenne\NDVI_comparison\polygons'<br /> &nbsp; &nbsp; &nbsp; files2 = FILE_SEARCH('*.shp', count=count)</p> <p > &nbsp; &nbsp; &nbsp; foreach file, files2 do begin<br /> &nbsp;&nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; ;input roi<br /> &nbsp; &nbsp; &nbsp; &nbsp; infile2=file<br /> &nbsp; &nbsp; &nbsp; &nbsp; infile_path2=FILEPATH(infile2, ROOT_DIR='F:\Sheyenne\NDVI_comparison\polygons')</p> <p > &nbsp; &nbsp; &nbsp; &nbsp; ;set name and location for output file which is the subseted data<br /> &nbsp; &nbsp; &nbsp; &nbsp; ;get the name of the roi without extension for later use<br /> &nbsp; &nbsp; &nbsp; &nbsp; allotment=strmid(infile2, 0, strpos(infile2,'.'))</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;outfile = 'NDVI_CIR_' + allotment + '.dat'</p> <p> &nbsp; &nbsp; &nbsp; &nbsp; outfile_path = thisdir + path_sep() + outfile<br /> &nbsp; &nbsp; &nbsp; &nbsp; ;load input roi<br /> &nbsp; &nbsp; &nbsp; &nbsp; rois=e.OpenVector(infile_path2)<br /> &nbsp; &nbsp; &nbsp; &nbsp; rasterWithMask=ENVIVectorMaskRaster(input_raster,rois)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; ; &nbsp; &nbsp; &nbsp;;save the file<br /> &nbsp; &nbsp; &nbsp; &nbsp; rasterWithMask.Export,outfile_path, 'ENVI'<br /> &nbsp; &nbsp; &nbsp; endforeach<br /> &nbsp; &nbsp; endforeach<br /> &nbsp;print, "Done"<br /> &nbsp;end</p> <p><br /> </p> <p>the code executes but the output is not actually masked. &nbsp;Each output is just an identical copy of the input_raster. &nbsp;The input raster is a 2009 CIR NAIP 1 meter resolution image. &nbsp;I have used the same code on Landsat images and they are masked just fine, so I am not sure why the NAIP image is acting any differently. &nbsp;</p> <p><br /> </p>

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    30 Nov 2015 01:05 PM
    Are you using ENVI 5.3? The masked areas are associated with the 'pixel_state' of the pixel and in order to export where the pixels are masked, you need to use the data_ignore_value keyword to the raster.export. For example: e = ENVI() ; Open an input file file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, $ SUBDIRECTORY = ['data']) raster = e.OpenRaster(file) ; select input rois fileName = Filepath('qb_boulder_roi.xml', SUBDIR=['data'], $ ROOT_DIR=e.Root_Dir) rois = e.OpenRoi(fileName) ; create a masked raster based on the water ROI. ; Pixels outside of the ROI are masked. mask = ENVIRoiMaskRaster(raster, rois[2]) ; Save the masked raster to disk outFile = 'c:\temp\masked.dat' mask.Export, outFile, 'ENVI', DATA_IGNORE_VALUE=0

    Deleted User



    New Member


    Posts:
    New Member


    --
    30 Nov 2015 01:50 PM
    I am using 5.3. I have tried this and it still gives me the same result with the DATA_IGNORE_VALUE. When I add the pixel state of 2 it says it is out of range, so this is probably where the problem is occurring? I should state I am not trying to create an actual mask with my roi's, but just subset my data based on them. I want to retain the original values, not just 1's and 0's.

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    02 Dec 2015 07:24 AM
    If you want to subset using ROIs, then I would use ENVIROI::GetExtent. There is an example there on how to subset using the extents of an ROI. Then you will have to apply the masking (if needed).

    Deleted User



    New Member


    Posts:
    New Member


    --
    08 Dec 2015 12:51 PM
    I havent seen an example of how to use the extent of the ROI. In the example here, http://www.exelisvis.com/docs/ENVIRoi..., it seems that an roi is being created and then the data variable is defining the extent. How would I switch the data to be the extent of my vector?

    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    08 Dec 2015 01:33 PM
    The extent is derived from the ROIs and then you would use this in the SubsetRaster as the sub_rect. I don't know of a way to do this with a vector but the vector can be converted to an ROI.
    You are not authorized to post a reply.