[PROJ] Creating projection *not* from full init string?

Alan Snow alansnow21 at gmail.com
Tue Mar 9 15:24:26 PST 2021


The other answers for why things are the way they are are much better than
what I could explain. But, I can speak to this from the perspective of
pyproj and how it uses the new PROJ API. I am a big fan of the new API. It
is more complex, but it provides a lot of nice capabilities.

Using proj_create as the engine, pyproj is able to create several different
types of objects depending on what is passed in: CRS (Datum,
CoordinateOperation, etc..) (projinfo?), Proj (proj), Transformer (cs2cs,
cct). All of them are a PJ*because PJ* can represent several different
things (ref
<https://github.com/OSGeo/PROJ/blob/20295afe2f7db68006b1f29c60d22e35ba5e9ec1/src/proj.h#L730-L772>
).

When you use EPSG:4326 with the CRS class:
>>> import pyproj
>>> pyproj.CRS("EPSG:4326")
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World.
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
>>> crs.to_proj4()
<stdin>:1: UserWarning: You will likely lose important projection
information when converting to a PROJ string from another format. See:
https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
'+proj=longlat +datum=WGS84 +no_defs +type=crs'
This is useful for defining your coordinate reference system, but shouldn't
be used for transformations.

Then, there is the Proj class (equivalent of proj). You can pass in
"EPSG:4326" and it will export the CRS as a proj string using
proj_as_proj_string
<https://github.com/pyproj4/pyproj/blob/2842f1b7a9bbbd75478618c407c11b28ac590fc6/pyproj/_crs.pyx#L145>
and then stripping out the "type=crs" bit to create the equivalent
operation used by proj by passing that string back into proj_create. It is
a bit of a hack, but it works. This method was used instead of the
proj_create_crs_to_crs because it supports proj_factors (not sure why the
other method does not as I haven't dug into it).

>>> proj = pyproj.Proj("EPSG:4326")
>>> proj.definition
'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0'
>>> proj
<Other Coordinate Operation Transformer: longlat>
Description: PROJ-based coordinate operation
Area of Use:
- undefined

This is is something to use with caution as it does not take into account
datum shifts (
https://pyproj4.github.io/pyproj/stable/gotchas.html#proj-not-a-generic-latitude-longitude-to-projection-converter).
The new and improved method, mentioned by Evan and demonstrated in the
link, is to use proj_create_crs_to_crs where you explicitly define the
source CRS and the target CRS.

Hopefully this helps,
Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20210309/dd0d45f3/attachment-0001.html>


More information about the PROJ mailing list