X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 15 May 2017 02:09 PM by  MariM
How to batch convert ENVI file to GeoTiff format using IDL?
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Chen Bangqian



New Member


Posts:17
New Member


--
04 May 2017 06:50 PM
    I have large amount of ENVI format file, but wander to convert to Geotiff. How can I do that using IDL?

    David Starbuck



    Basic Member


    Posts:143
    Basic Member


    --
    05 May 2017 11:04 AM
    You can read the data into IDL using the GetData method. An example how this can be achieved can be found using the following help page:
    https://www.harrisgeospatial.com/docs/enviRaster__GetData.html

    You can then use the WRITE_TIFF routine to generate a geoTIFF file. An example of how to write a GeoTIFF file can be found on the following help page (Example 4):
    https://www.harrisgeospatial.com/docs/write_tiff.html

    Alternatively, you can use the ChipToFile ENVI method to generate a geoTIFF from an ENVI view:
    https://www.harrisgeospatial.com/docs/ENVIView__ChipToFile.html

    -David
    Harris GS

    Chen Bangqian



    New Member


    Posts:17
    New Member


    --
    07 May 2017 08:07 AM
    Hi, David,

    Thank you for your response. I have followed the documents you posted to convert ENVI file to Geotiff format. A key step for the conversion was to set the GeoTiff parameter of WRITE_TIFF API. Few of the parameter was come from the *.tfw file associated with the Geotif file that I manually convrted in ENVI. The following codes can convert ENVI file to corresponding Geotiff file. However, I am not sure the parameter is suitable for all files in different regions, since I can not test on all of them. Can you comment on this?

    ...
    ENVI_FILE_OPEN, file, R_FID=fId
    ENVI_FILE_QUERY,fId,DIMS=dims,NS=ns,NL=nl,NB=nb,BNAMES=bandNames,FILE_TYPE=fileType,DATA_TYPE=datType;
    mapInfo = ENVI_GET_MAP_INFO(FID = fId);
    prj = ENVI_GET_PROJECTION(FID=fId,PIXEL_SIZE=ps,UNITS=unit);
    data = INDGEN(nb,ns,nl);
    FOR j = 0L, nb-1 DO BEGIN ; Multiple bands
    data[j,*,*] = ENVI_GET_DATA(FID=fId,POS=j,DIMS=dims);
    ENDFOR

    g_tags = { $
    ModelPixelScaleTag: [ps[0], ps[1], 0d], $
    ModelTiepointTag:[0.00000000000000000, 0.00000000000000000, 0.00000000000000000, mapInfo.MC[2], mapInfo.MC[3], 0.00000000000000000],$
    GTModelTypeGeoKey: 2, $ ; (ModelTypeProjected)
    GTRasterTypeGeoKey: 1, $ ; (RasterPixelIsArea)
    GeographicTypeGeoKey: 4326, $ ; (GCS_NAD27)
    ProjectionGeoKey: 32767, $ ; (user-defined)
    ProjLinearUnitsGeoKey: 9001, $ ; (Linear_Meter)
    GEOGLINEARUNITSGEOKEY:9102 $
    }
    fileBaseName = FileBaseName(fileName);
    outFile = 'D:\PALSAR-2-V2\Geotiff\'+fileBaseName+'.tif';
    WRITE_TIFF,outFile,data,/LONG,GEOTIFF=g_tags;
    ; Delete memory file
    ENVI_FILE_MNG,ID=fId,/DELETE;


    MariM



    Veteran Member


    Posts:2396
    Veteran Member


    --
    15 May 2017 02:09 PM
    If you have ENVI, then you could also use ENVI's API to export to geoTIFF. You could use ENVI Classic's ENVI_OUTPUT_TO_EXTERNAL_FORMAT:

    https://www.harrisgeospatial.com/docs/ENVI_OUTPUT_TO_EXTERNAL_FORMAT.html

    or use the new API to export the raster object:
    https://www.harrisgeospatial.com/docs/enviraster__export.html

    These routines will export the appropriate geoTIFF tags to the file. However not all metadata that is supported for an ENVI raster is supported in geoTIFF. For example, metadata such as acquisition time, RPCs, and other custom items are not supported in geotiff tags.
    You are not authorized to post a reply.