# Shape file of CMAQ 12km grid cell for USA

**URL:** <https://forum.cmascenter.org/t/shape-file-of-cmaq-12km-grid-cell-for-usa/1462>\
**Category:** CMAQ\
**Created:** [April 30, 2020, 12:40pm UTC](https://forum.cmascenter.org/t/shape-file-of-cmaq-12km-grid-cell-for-usa/1462 "2020-04-30T12:40:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadaf](https://avatars.discourse-cdn.com/v4/letter/n/8dc957/32.png) [@nadaf](https://forum.cmascenter.org/u/nadaf)\
**Post date:** [April 30, 2020, 12:40pm UTC](https://forum.cmascenter.org/t/shape-file-of-cmaq-12km-grid-cell-for-usa/1462/1 "2020-04-30T12:40:07Z")

</div>

I am wondering how the grid cells at 12 km resolution are defined in CMAQ. I searched the CMAS center and Data Clearinghouse but I couldn’t find the shape file of 12 km grid cell used in CMAQ for Texas or USA.

I was wondering if you have any clue on where to find the shape file. I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![barronh](https://avatars.discourse-cdn.com/v4/letter/b/85e7bf/32.png) [@barronh](https://forum.cmascenter.org/u/barronh)\
**Post date:** [April 30, 2020, 3:58pm UTC](https://forum.cmascenter.org/t/shape-file-of-cmaq-12km-grid-cell-for-usa/1462/2 "2020-04-30T15:58:53Z")

</div>

I don’t know if there is an official repository for such shapefiles, but creating them is fun and easy with GDAL. I am sure there are other ways, but here is how I do it.

1. Create an ASCII gridded XYZ file using centroids in grid units.
2. Add the projection information via VRT/Proj4 with grid units (`gdalbuildvrt`).
3. Polygonize it to shapefile (`gdal_polygonize.py`).
4. Check the results.

More details on each step are below.

## Step 1: Make a gridded XYZ file

You could do this in excel, but I like python.

```auto
python -c "
rows = [j for j in range(0, 299)]
cols = [i for i in range(0, 459)]
outfile = open('test.csv', 'w')
for row in rows[::-1]:
    for col in cols:
        print('{},{},{}'.format(col + 0.5, row + 0.5, col * 1000 + row), file=outfile)

outfile.close()
"

```

## Step 2: Create a virtual dataset with projection information.

Here I have translated the IOAPI meta data into the PROJ4 definition including adjusting the units. This is important because we didn’t use sizes in the CSV above.

```auto
gdalbuildvrt -srcnodata 1 -a_srs "+proj=lcc +lat_1=33.0 +lat_2=45.0 +lat_0=40.0 +lon_0=-97.0 +y_0=1728000.0 +x_0=2556000.0 +a=6370000.0 +b=6370000.0 +to_meter=12000.0 +no_defs" test.vrt test.csv

```

## Step 3: Convert the virtual raster into a Shapefile

```auto
gdal_polygonize.py test.vrt testout

```

## Step 4: Spot check

I always compare the results to the lower left and upper right corners LOND and LATD in GRIDDOT2D.

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [April 30, 2020, 4:03pm UTC](https://forum.cmascenter.org/t/shape-file-of-cmaq-12km-grid-cell-for-usa/1462/3 "2020-04-30T16:03:01Z")

</div>

…and watch out for which geodetic spheroid you use. MM5, WRF=ARW, and CMAQ usually use a perfect sphere with radius R=6370000 meters.
