# Transforming the default projection system

**URL:** <https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908>\
**Category:** CMAQ-POST\
**Created:** [November 12, 2020, 8:31pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908 "2020-11-12T20:31:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadia](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@Sadia](https://forum.cmascenter.org/u/Sadia)\
**Post date:** [November 12, 2020, 8:31pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/1 "2020-11-12T20:31:02Z")

</div>

Hi,

Good afternoon. I have a NetCDF file of daily PM2.5 concentration. The file is projected in Lambert Conformal Conic projection, and now I want to project it into WGS84. I am wondering is there any post-processing tool/ioapi script exists that allows converting a NetCDF file into another projection. Or, some sort of script, which can convert the latitude and longitude of a given projection (csv, netcdf or other format) to others.

I would highly appreciate it if you could share your knowledge to help me came out of this issue.

Thanks,  
Sadia

---

<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:** [November 12, 2020, 10:01pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/2 "2020-11-12T22:01:44Z")

</div>

See:

- [https://cjcoats.github.io/ioapi/GRIDS.html](https://cjcoats.github.io/ioapi/GRIDS.html) for grid and coordinate conventions for the modeling
- [https://cjcoats.github.io/ioapi/AA.html#coordstuff](https://cjcoats.github.io/ioapi/AA.html#coordstuff) for routines related to coordinate transformations
- [https://cjcoats.github.io/ioapi/AA.html#tools](https://cjcoats.github.io/ioapi/AA.html#tools) for related programs, incluiding programs for converting from one grid to another.

You don’t have things quite right in your question: **WGS84** is a **geodetic spheroid** , a particular choice of representing the Earth’s surface as an oblate ellipsoid; WGS-84 os one of these and the WRF-Sphere is another.  
**Lambert Conformal Conic** is a **map projection** , a scheme for putting 2-D Cartesian _X-Y_ coordinates on a (portion of) the Earth’s surface (the transformation equations assume that you have already chosen a geodetic spheroid, btw. Different spheroids may well give differences in coordinates as large as 25KM at CONUS scales.)

**Grids** are defined in terms of a map projection: given the projection, specify the lower-left corner coordinates, the cell-sizes **DX** in the _X_ direction and **DY** in the _Y_ direction, and the numbers **NCOLS** of grid-columns and **NROWS** of grid-rows in order to specify a grid.

Various of the _m3tools_ programs can be used to transform gridded data from one grid to another (each of which has potentially its own map-projection. Program _m3cple_ does linear interpolation, which is appropriate for going from a coarse (large-cells) grid to a find (small-cells) grid. The pair of programs _ **mtxcalc+mtxcple** _ does re-sampling and re-aggregation, appropriate for going from a finer grid to a coarser grid (or grids of about the same cell-size); it also works for going from coarser to finer.

**BEWARE** that coordinate- **transformations for emissions data** have a piece of non-obvious trickiness: as per the usual conventions, _emissions data is not given in terms of standard MKS units_, but instead has an extra (implicit) per-grid-cell qualifier to the units: units recorded as _Kg/sec_ really mean Kg/sec/grid-cell, so in doing transforms of emissions data you need also to adjust for the ratio of the output-grid grid-cell area to the input-grid grid-cell area. Program _mtxcalc_ has an option for doing this adjustment, so you need to use _ **mtxcalc+mtxcple** _ for re-gridding emissions data.

---

<div class="post-metadata">

**Author:** ![Sadia](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@Sadia](https://forum.cmascenter.org/u/Sadia)\
**Post date:** [November 13, 2020, 7:25pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/3 "2020-11-13T19:25:39Z")

</div>

Hi,

Thank you so much for your reply. It was really very helpful post. Thanks for your time for pointing to some helpful resources and making the concept clear to me.

Regards,  
Sadia

---

<div class="post-metadata">

**Author:** ![Sadia](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@Sadia](https://forum.cmascenter.org/u/Sadia)\
**Post date:** [November 18, 2020, 10:10pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/4 "2020-11-18T22:10:14Z")

</div>

Hi Carlie,

Sorry for bothering you again. I was reading the link([https://cjcoats.github.io/ioapi/GRIDS.html](https://cjcoats.github.io/ioapi/GRIDS.html)) you shared. I have a question. If now I understand correctly, " Grids are defined in terms of a map projection", for my case it is “Lambert Conformal Conic”. But I didn’t understand the significance of the parameter “GCTP projection 4”. Also, how can I know which “geodetic spheroid” has been chosen? Is there any way to know that? I would appreciate your help in this regard. Thanks again for clarifying my concept on projection.

Regards,  
Sadia

---

<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:** [November 18, 2020, 11:23pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/5 "2020-11-18T23:23:20Z")

</div>

OK. let’s take it from the top.

The I/O API coordinate system treatment is based upon the USGS Geographic Coordinate Transform Package (GCTP), which at the time we started the project was the easiest high-quality publicly-available geographic package for us to use. Its original manual is at [https://cjcoats.github.io/ioapi/GCTP.pdf](https://cjcoats.github.io/ioapi/GCTP.pdf) and many of the I/O API coordinate concepts and parameters come from it.

The Earth is approximately an ellipsoid, in particular, because of the force of the Earth’s rotation it is a “flattened” spheroid – the rotation causes the diameter to “stretch” in the plane of the Equator (so that the diameter across the Equator is greater than the diameter pole-to-pole. A **spheroid** is such a description of the Earth; there have been many such descriptions proposed and used; the most common, together with their GCTP code-numbers are

- Clarke 1866: GCTP uses 0 as its index-number
- GRS 1980: 8
- WGS 84: 12
- perfect sphere: 19 (in which case we have to specify the radius elsewhere)  
Generally the more recent GRS 80 or WGS 84 ellipsoids are what GIS people use; meteorologists tend to use perfect spheres since doing proper equations of motion on a more-general ellipsoid is quite “hairy” mathematics. I have seen some older data given in terms of Clarke 1866…

A **map projection** is a way of putting Cartesian X-Y coordinates on ellipsoids (and so needs a ellipsoid-specification to complete its definition). A **Lambert Conformal Conic** , for example (I/O API projection code 2, GCTP projection code 4), has the geometric algorithm:

- Form a cone that intersects the ellipsoid at two latitudes _alpha_ and _beta_ (and has central axis the same as the rotational N-S axis of the Earth).
- Project a geometric ray from the center of the Earth through both its surface and the surface of the cone. Map the Earth-surface intersection-point of that ray to the cone’s intersection point. If you do the arithmetic for this you’ll get into some rather messy trigonometry 🙂
- Slice the cone diametrically opposite “central longitude” gamma and unroll it flat, with the longitude-_gamma’s_ image on the cone in the N-S, or _Y_ direction.
- Find the point on the unrolled-cone where “origin-point” latitude-longitude _(LATORIG,LONORIG)_ winds up, and start measuring X and Y coordinates from there – Y parallel to the longitude-_gamma’s_ line. Usually one chooses _LONORIG=gamma_, and _LATORIG_ somewhere between _alpha_ and _beta_ (but not always;-( )  
Because of how this works, choosing different ellipsoids to represent the Earth will give somewhat-different X-Y coordinate systems; if you use Lambert projections with _alpha_=30, \*beta=\*60, and _gamma_=90, _LONORIG_=-90 (note the minus-sign, for longitudes west of the Prime Meridian _LON_=0), and _LATORIG_=45, then the Cartesian origin X=Y=0 somewhere in Illinois no matter which ellipsoid you use, but the coordinates for Portland Maine will be different by about 20 KM between choosing a spherical ellipsoid and the WGS84 ellipsoid.

Note that because of round-off problems in all the map-projection arithmetic, it is best to do everything in REAL_8 (DOUBLE PRECISION) rather than in REAL_4, which doesn’t have enough significant digits to be sure of giving the “right” answer…

And the I/O API’s coordinate transform routines generally do this work for you, given descriptions you don’t need to worry much about the messy mathematics.

The worst problem you’re likely to encounter is transforming back and forth between grid-cell columns and rows and Cartesian X-Y coordinates:  
Suppose you have a grid with lower-left corner _(X0,Y0)_ and cell-size _(DX,DY)_, and a point _(X,Y)_ with _X≥X0, Y≥Y0._ Then the column-  
and row-numbers _(C,R)_ for the point are  
_C=1+INT((X-X0)/DX), R=1+INT((Y-Y0)/DY)_.  
Beware that computer-languages “convert to integer” operators tend to “do the wrong thing” from a mathematical point of view: _INT(-0.5)_ and _INT(0.5)_ are both 0 ;-( so you have to do explicit checks for _X≥X0, Y≥Y0_ and say “the point is off the grid” if either one fails.

---

<div class="post-metadata">

**Author:** ![Sadia](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@Sadia](https://forum.cmascenter.org/u/Sadia)\
**Post date:** [November 19, 2020, 4:58am UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/6 "2020-11-19T04:58:37Z")

</div>

Thank you so much for your step by step explanation. I appreciate your time to make these things clear to me. Though I am still struggling with my issues, many things are clear to me now.

So, in summary, as my GCTP projection code is 4 according to [https://cjcoats.github.io/ioapi/GRIDS.html](https://cjcoats.github.io/ioapi/GRIDS.html), I can say that the sphere used for projection is “4. International 1909” [[https://cjcoats.github.io/ioapi/GCTP.pdf](https://cjcoats.github.io/ioapi/GCTP.pdf)].

Since I need to know the latitude and longitude associated with WGS 84 ellipsoid (12. WGS 84) from my GRIDDESC file. I was trying the following programs:

…GRIDDESC…  
‘LCCPROJ’ 2 33.000 45.000 -97.000 -97.000 40.000  
‘4NC3’ ‘LCCPROJ’ 960000.000 -660000.000 4000.000 4000.000 237 153 1  
…GRIDDESC…

`-->setenv GRIDDESC /home/safrin/GRIDDESC`  
`-->setenv IOAPI_ISPH 12`  
`-->setenv GRIDDED /home/safrin/gridded_file`  
`-->setenv BOUNDARY "NONE"`  
`-->latlon GRIDDESC GRIDDED BOUNDARY >& summary`

But, I am getting the following error.  
“latlon: error while loading shared libraries: libnetcdf.so.11: cannot open shared object file: No such file or directory”

If I am on the right track, do I need to install another version of NetCDF?

I am feeling really very sorry for bothering you a lot.

Thanks,  
Sadia

---

<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:** [November 19, 2020, 12:26pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/7 "2020-11-19T12:26:06Z")

</div>

Where did your copy of the program _latlon_ come from?

Did you build it yourself (or did someone build it for you) according to the directions in [https://cjcoats.github.io/ioapi/AVAIL.html#build](https://cjcoats.github.io/ioapi/AVAIL.html#build)?

Those instructions told you how to build a statically linked executable, that would not need that shared-object file.

---

<div class="post-metadata">

**Author:** ![Sadia](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@Sadia](https://forum.cmascenter.org/u/Sadia)\
**Post date:** [November 19, 2020, 9:37pm UTC](https://forum.cmascenter.org/t/transforming-the-default-projection-system/1908/8 "2020-11-19T21:37:29Z")

</div>

No, I have not built the latlon ([https://cjcoats.github.io/ioapi/LATLON.html](https://cjcoats.github.io/ioapi/LATLON.html)). Thanks for the link. I will follow the instructions.

Regards,

Sadia
