Extracting latitude/longitude metadata from LANDSAT Earth Explorer

10 views (last 30 days)
I am just starting to use MATLAB. My assignment for work is to calculate the mean of a surface temperature matrix for each cell with dimensions 1 degree latitude by 1 degree longitude. I downloaded, read, converted data types, and calculated the mean of the surface temperature matrix.
My issue is with reading latitude/longitude data as an array/matrix. I found the latitude/longitude data for a tile in its metadata and downloaded its metadata as an xml and html file. I'm not sure what the steps are for reading it into MATLAB, though. Here is the latitude/longitude data I want to convert into a matrix:
<CORNER_UL_LAT_PRODUCT>39.23687</CORNER_UL_LAT_PRODUCT>
<CORNER_UL_LON_PRODUCT>-103.19598</CORNER_UL_LON_PRODUCT>
<CORNER_LR_LAT_PRODUCT>37.81339</CORNER_LR_LAT_PRODUCT>
<CORNER_LR_LON_PRODUCT>-101.34833</CORNER_LR_LON_PRODUCT>
<CORNER_UL_PROJECTION_X_PRODUCT>-615585.000</CORNER_UL_PROJECTION_X_PRODUCT>
<CORNER_UL_PROJECTION_Y_PRODUCT>1814805.000</CORNER_UL_PROJECTION_Y_PRODUCT>
<CORNER_LR_PROJECTION_X_PRODUCT>-465585.000</CORNER_LR_PROJECTION_X_PRODUCT>
<CORNER_LR_PROJECTION_Y_PRODUCT>1664805.000</CORNER_LR_PROJECTION_Y_PRODUCT>
I tried parsexml('filename') and xmlread('filename') on the xml file of the metadata, and I tried extractHTMLtext('filename'), but I got "Invalid expression" errors. I'm not sure what to do.
Let me know if anything I said was unclear or if you have advice!
  2 Comments
Kojiro Saito
Kojiro Saito on 26 May 2022
Could you tell us the detail of Landsat products (Landsat Legacy? or Landsat Collections)? Not every product has .xml and .html file, some contain only .txt files.
Eric Williams
Eric Williams on 26 May 2022
Yes of course, I am using LANDSAT Collection 2 U.S. Analysis Ready Data (ARD).

Sign in to comment.

Accepted Answer

Kojiro Saito
Kojiro Saito on 27 May 2022
From R2021a, readstruct and readtable can read xml files.
I have tested with a xml file of "C2 ARD Tile Metadata Bundle" of "LANDSAT Collection 2 U.S. Analysis Ready Data".
% Read XML file as a structure
str = readstruct('LC09_AK_000010_20220521_20220526_02.xml');
% Extract TILE_METADATA -> PROJECTION_ATTRIBUTES
projAttr = str.TILE_METADATA.PROJECTION_ATTRIBUTES;
% Get values
cornerUlLatLon = [projAttr.CORNER_UL_LAT_PRODUCT, projAttr.CORNER_UL_LON_PRODUCT];
cornerLrLatLon = [projAttr.CORNER_LR_LAT_PRODUCT, projAttr.CORNER_LR_LON_PRODUCT];
cornerUlProjXY = [projAttr.CORNER_UL_PROJECTION_X_PRODUCT, projAttr.CORNER_UL_PROJECTION_Y_PRODUCT];
cornerLrProjXY = [projAttr.CORNER_LR_PROJECTION_X_PRODUCT, projAttr.CORNER_LR_PROJECTION_Y_PRODUCT];
  2 Comments
Eric Williams
Eric Williams on 31 May 2022
Thank you very much for your help! That saved me, because I used this code to get my lat/long values right before my meeting with my supervisor!
One more general question: since the values in projAttr are for the upper left corner and lower right corner, that covers the spatial extend of the entire tile, right? I just want to make sure I don't worry about the lower left and upper right corners being "missing" from projAttr.
Kojiro Saito
Kojiro Saito on 31 May 2022
Great to hear that!
projAttr contains <PROJECTION_ATTRIBUTES> tag and upper left corner and lower right corner exist in <PROJECTION_ATTRIBUTES> tag. So, I think it covers the spatial extend of the entire tile.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!