3

I am very much new to R programming kindly someone tell how can i read the MTL file which is archived with landsat satellite data.

3 Answers 3

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

3

For standard MTL file provided with Landsat scenes obtained from EarthExplorer or Glovis sevices, you could simply do:

mtl <- read.delim('L71181068_06820100518_MTL.txt', sep = '=', stringsAsFactors = F)

So, for something starting like this:

GROUP = L1_METADATA_FILE  GROUP = METADATA_FILE_INFO...

You may use this:

> mtl[grep("LMAX",mtl$GROUP),]
                  GROUP L1_METADATA_FILE
64          LMAX_BAND1           293.700
66          LMAX_BAND2           300.900
68          LMAX_BAND3           234.400
70          LMAX_BAND4           241.100
72          LMAX_BAND5            47.570
74         LMAX_BAND61            17.040
76         LMAX_BAND62            12.650
78          LMAX_BAND7            16.540
80          LMAX_BAND8           243.100
84       QCALMAX_BAND1             255.0
86       QCALMAX_BAND2             255.0
88       QCALMAX_BAND3             255.0
90       QCALMAX_BAND4             255.0
92       QCALMAX_BAND5             255.0
94      QCALMAX_BAND61             255.0
96      QCALMAX_BAND62             255.0
98       QCALMAX_BAND7             255.0
100      QCALMAX_BAND8             255.0

There are dictionaries provided by each service, found here and here.

Information from MTL may be critical for applying atmospheric and radiometric correction. By the way, landsat package allows you to run some of more typical correction using DOS() and radiocorr() functions.

You will also need standard calibration values provided by Chander et al. (2009).

For more complex approaches this may be a good start.

1

The MTL file contains only metadata (I hope you knew that :-)) and is a plain text file, so you could just read it in and parse as desired. If you are reasonably familiar with Matlab, you could port this tool http://www.mathworks.com/matlabcentral/fileexchange/39073 , converting it into R code.

EDIT: I can't tell from your comments what you actually need. Here's an example MTL.txt file I pulled off the net: http://landsat.usgs.gov/images/squares/processing_level_of_the_Landsat_scene_I_have_downloaded1.jpg

If you look at it, you can see the names and values of the data items. If those are what you want, perhaps the easiest way to get them would be to run the command

mtl.values <- read.table('filename.txt' , sep='=')  

Which will give you a 2-column dataframe, with names in first column and values in the second.

8
  • Yeap i knew it dear but i want to read it so that if i have to calculate NDVI, the tool will read info from MTL file only and do it from itself, no need to give bands and no need to create stack in that case...if you can help on that because i don't have much knowledge on matlab cause i am very much new in programming. Feb 8, 2013 at 7:38
  • Ok, -- if you can edit your question to specify which fields (data items) you want to extract from the header, we can probably write a 'filter' function to get you the right data. Feb 8, 2013 at 12:28
  • okay, like i want to stack the image first and on the whole image i have to calculate NDBI, NDWI, and some other indices from the data, for which i think i should need bands information only.... Feb 9, 2013 at 6:14
  • Please post a sample MTL file that you are using and I'll put up some code to pull the items of interest for you. Feb 9, 2013 at 21:25
  • I was using this but you can take anyone you are having i just need to how can we call and thank you for your reponses. You are really helpful thanks!!:) L5146040_04020110305_MTL Feb 10, 2013 at 17:40
0

for reading Mtl file along with your images (stack image) you can do the following:

  1. Give the directory of you Mtl file. For example

    mtlFile<- "\\LE07_L1TP_165035_20090803_20161220_01_T1_MTL.txt"
    
  2. Read metadata

      metaData <- readMeta(mtlFile)
      metaData
    
  3. Load rasters based on the metadata file

     lsat <- (stackMeta(mtlFile, quantity = "all", category = "image", 
     + allResolutions = FALSE))
     lsat
     plot(lsat)
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.