[PROJ] How to map pj_latlong_from_proj to PROJ ver 7 API

Even Rouault even.rouault at spatialys.com
Mon Nov 30 12:00:32 PST 2020


Pierluigi,

> I've successfully compiled PROJ ver 7.2.0 on Windows 10 (build 19041.630)
> and I am trying to port my code from PROJ ver 4 API to PROJ ver 7 API but I
> can't find a clear matching between the old version 4 API
> *pj_latlong_from_proj* routine and version 7 API code.
> 
> I tried the suggested function mapping as specified here
> https://proj.org/development/migration.html#function-mapping-from-old-to-new
> -api, but I am consistently getting a NULL pointer returned by the
> *proj_crs_get_horizontal_datum()*. Here is my sample code:
> 
> //------------------------------------------------
> #include <iostream>
> #include <proj.h>
> 
> int main()
> {
>    PJ *proj_test = proj_create(PJ_DEFAULT_CTX, "+proj=ortho +datum=WGS84
> +ellps=WGS84 +lat_0=60 +lon_0=90");

The above is instanciated as a coordinate operation, not a CRS, so you can't 
use CRS related API on it. You likely need to add " +type=crs" to the PROJ 
string

>    PJ *datum = proj_crs_get_horizontal_datum(PJ_DEFAULT_CTX, proj_test);

You'll rather want to use proj_get_source_crs() to extract the geographic CRS 
from the projected CRS ( proj_crs_get_geodetic_crs() would also do the job 
here ).

The resulting PJ* object will be a CRS too, so as you likely want to do a 
coordinate operation from your projected CRS to the base geographic CRS, 
you'll need to create a coordinate operation object with:

	proj_create_crs_to_crs_from_pj(PJ_DEFAULT_CTX, proj_test, geog_crs, NULL, 
NULL)

and then you can use proj_trans() on the resulting object.


Another option is to use proj_crs_get_coordoperation(PJ_DEFAULT_CTX, 
proj_test) (with the PROJ string of proj_test having " +type=crs"), which will 
give you the coordinate operation to convert from the base geographic CRS of 
the projected CRS to the projected CRS.
You can use proj_trans() on it (in the reverse direction, if you want to go 
from projected to geographic)

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the PROJ mailing list