<p>The latitude and longitude of each pixel is not stored in the HDF file. But using</p>

<p>metadata=hdfinfo('file_name.hdf');</p>

<p>You can get the info to generate those latitudes and longitudes. In metadata.Attibutes you will find this among other things:</p>

<pre><code>    GridName="MOD_CMG_Snow_5km"
    XDim=7200
    YDim=3600
    UpperLeftPointMtrs=(-180000000.000000,90000000.000000)
    LowerRightMtrs=(180000000.000000,-90000000.000000)
    Projection=GCTP_GEO
</code></pre>

<p>If you rather a more human-readable format, check the <a href="https://nsidc.org/data/mod10c2" rel="nofollow noreferrer">product specifications for MOD10C2</a>.</p>

<p>There it say:</p>

<blockquote>
  <p><strong>Projection</strong></p>
  
  <p>MODIS CMG data sets are produced in a Geographic Lat/Lon
  projection. This simple projection treats geographical longitude and
  latitude degrees as if they were x- and y-coordinates in a plane.
  Figure 1 shows the geographical lat/lon projection known as Plate
  Carrée, which plots longitude and latitude degrees as coordinates on
  the x and y axes, respectively:</p>
  
  <p><a href="https://i.sstatic.net/FnIpR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FnIpR.png" alt="enter image description here"></a></p>
  
  <p>Figure 1: Plate Carrée projection.</p>
  
  <p><strong>Grid</strong></p>
  
  <p>The MODIS CMG consists of 7200 columns by 3600 rows. Each cell
  has a resolution of 0.05 degrees (approximately 5 km). The upper-left
  corner of the upper-left cell is -180.00 degrees longitude, 90.00
  degrees latitude. The lower-right corner of the lower right cell is
  -180.00 degrees longitude, -90.00 degrees latitude...</p>
</blockquote>

<p>With that you have more than enough information to generate the latitude and longitude vectors. Now you have to decide if you will store the center of each pixel, or one of the corners.</p>

<p>Assuming you will store the center of each pixel you can generate the latitude and longitude vectors like this:</p>

<pre><code>gridSize=0.05 % arc degrees
lat=-90+(gridSize/2):0.05:90-(gridSize/2);
lon=-180+(gridSize/2):0.05:180-(gridSize/2);
</code></pre>

<p>And if you want instead matrices with the coordinates of the center of each individual pixel, you do</p>

<blockquote>
  <p>[lonGrid,latGrid]=meshgrid(lon,lat);</p>
</blockquote>

CC BY-SA 4.0
2019-02-07T01:45:35.090Z
Is there a way to get average/mean of whole pixel beside targeting the centre and corner?
irfan
CC BY-SA 4.0
2019-02-07T02:04:45.467Z
What do you mean? The pixel is already the average of snow cover in an area of 0.05x0.05 degrees, and to geolocate it you need its four corners. However, knowing its size you just need to store one corner or the center.
Camilo Rada
CC BY-SA 4.0
2019-02-06T15:08:27.920Z
2019-02-06T15:08:27.920Z
Camilo Rada
<p>We can import and read all given bands/parameters of MOD10C2, lat and lon is not given as separate band rather embedded with other bands. How we can extract from MOD10C2 hdf data in matlab.</p>

<p><a href="https://stackoverflow.com/questions/51557613/lat-lon-information-from-hdf-file-python">Similar question found here for python</a></p>

CC BY-SA 4.0
2019-02-06T15:10:36.560Z
I've answered here, but this should be migrated to GIS SE, if you have more questions like this I would recommend you to post them there.
Camilo Rada
CC BY-SA 4.0
2019-02-07T01:42:11.743Z
Initially I just generated the lat lon in a simple way lat = -90:0.05:90; and 
lon = -180:0.05:180; then subsetted the data with had lead to error (possibly).
irfan
CC BY-SA 4.0
2019-02-07T01:57:21.670Z
Yes, because those lat/lon have one element more than the real data. Thos would ne 3601x1 and 7201x1 respectively.
Camilo Rada
<remote-sensing><snow><gis><matlab>
How to extract lat-lon from MOD10C2 hdf data in matlab?
irfan
# How to extract lat-lon from MOD10C2 hdf data in matlab?

(Asked by: username_0 on 2019-02-06)

We can import and read all given bands/parameters of MOD10C2, lat and lon is not given as separate band rather embedded with other bands. How we can extract from MOD10C2 hdf data in matlab.

[Similar question found here for python](https://stackoverflow.com/questions/51557613/lat-lon-information-from-hdf-file-python)

**Tags:** remote-sensing, snow, gis, matlab

> **Comments:**
> **username_1**: I've answered here, but this should be migrated to GIS SE, if you have more questions like this I would recommend you to post them there.  
> **username_0**: Initially I just generated the lat lon in a simple way lat = -90:0.05:90; and  lon = -180:0.05:180; then subsetted the data with had lead to error (possibly).  
> **username_1**: Yes, because those lat/lon have one element more than the real data. Thos would ne 3601x1 and 7201x1 respectively.  

---

## 1 answers

### Answer by username_1 on 2019-02-06. Score: 3 | Accepted answer

The latitude and longitude of each pixel is not stored in the HDF file. But using

metadata=hdfinfo('file\_name.hdf');

You can get the info to generate those latitudes and longitudes. In metadata.Attibutes you will find this among other things:

```
    GridName="MOD_CMG_Snow_5km"
    XDim=7200
    YDim=3600
    UpperLeftPointMtrs=(-180000000.000000,90000000.000000)
    LowerRightMtrs=(180000000.000000,-90000000.000000)
    Projection=GCTP_GEO

```

If you rather a more human-readable format, check the [product specifications for MOD10C2](https://nsidc.org/data/mod10c2).

There it say:

> **Projection**
>
> MODIS CMG data sets are produced in a Geographic Lat/Lon
> projection. This simple projection treats geographical longitude and
> latitude degrees as if they were x- and y-coordinates in a plane.
> Figure 1 shows the geographical lat/lon projection known as Plate
> Carrée, which plots longitude and latitude degrees as coordinates on
> the x and y axes, respectively:
>
> [![enter image description here](https://i.sstatic.net/FnIpR.png)](https://i.sstatic.net/FnIpR.png)
>
> Figure 1: Plate Carrée projection.
>
> **Grid**
>
> The MODIS CMG consists of 7200 columns by 3600 rows. Each cell
> has a resolution of 0.05 degrees (approximately 5 km). The upper-left
> corner of the upper-left cell is -180.00 degrees longitude, 90.00
> degrees latitude. The lower-right corner of the lower right cell is
> -180.00 degrees longitude, -90.00 degrees latitude...

With that you have more than enough information to generate the latitude and longitude vectors. Now you have to decide if you will store the center of each pixel, or one of the corners.

Assuming you will store the center of each pixel you can generate the latitude and longitude vectors like this:

```
gridSize=0.05 % arc degrees
lat=-90+(gridSize/2):0.05:90-(gridSize/2);
lon=-180+(gridSize/2):0.05:180-(gridSize/2);

```

And if you want instead matrices with the coordinates of the center of each individual pixel, you do

> [lonGrid,latGrid]=meshgrid(lon,lat);

> **Comments:**
> **username_0**: Is there a way to get average/mean of whole pixel beside targeting the centre and corner?  
> **username_1**: What do you mean? The pixel is already the average of snow cover in an area of 0.05x0.05 degrees, and to geolocate it you need its four corners. However, knowing its size you just need to store one corner or the center.  

---

