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

Pierluigi Guasqui guasqui at actgate.com
Tue Dec 1 03:00:23 PST 2020


Even,

thank you so much for your reply.

My intent here is just to replicate the PROJ 4 API behavior of:

//------------------------------------------------
const char *pj_carto_string = "+proj=ortho +datum=WGS84 +ellps=WGS84
+lat_0=60 +lon_0=90";
pj_cart = pj_init_plus( pj_carto_string );
projPJ pj_ll = pj_latlong_from_proj( pj_cart );
char *pj_ll_string = pj_get_def( pj_ll, 0 );
//------------------------------------------------
I am only interested in getting the geographic coordinate string
*pj_ll_string* underlying the input cartographic projection
*pj_carto_string*. So, in this context, I am not interested in performing
any transformation with those projection strings.

Thank you so much!
Pierluigi

On Mon, Nov 30, 2020 at 9:00 PM Even Rouault <even.rouault at spatialys.com>
wrote:

> 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
>


-- 
Pierluigi Guasqui
Software Engineer

Applied Coherent Technology Corporation (ACT)
www.actgate.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20201201/9322d3fd/attachment.html>


More information about the PROJ mailing list