[PROJ] Migrating to proj API 6+ without forcing crs input

Johannes Schauer Marin Rodrigues josch at mister-muffin.de
Thu Apr 14 09:55:05 PDT 2022


Hi Even,

Quoting Even Rouault (2022-04-14 17:41:05)
> I already answered (I admit I more and more terse with years) in 
> https://github.com/OSGeo/PROJ/issues/3161#issuecomment-1094238124
> 
> So for your case where you don't have a CRS but a pipeline, and assuming 
> it serves the role of the source, you'd need an alternate code path that 
> would do
> 
> PJ* P = proj_create(ctxt, "+proj=pipeline " + 
> your_pipeline_without_proj_equal_pipeline_and_with_steps_in_reverse_order_and_with_+inv_qualifier_added_when_absent_or_removed_when_present 
> + " +step " + proj_string_of_target )
> 
> proj_trans(P, PJ_FWD, ...);
> 
> so yes, there's a bunch of PROJ string manipulation to do.

thanks for your reply! So you suggest that projects that are upgrading to proj
API 6+ and want to continue supporting non-CRS user-supplied strings should
resort to implementing their own proj string parser and transformation code? Is
there not something that can be provided by proj itself to make this easier?
If proj would add some code to support this, then this would also prevent a
number of differently buggy proj parsing and transformation codebases to be
implemented by every project that cares about non-CRS input. It seems odd to me
that with upgrading to a new API version, the use-case of using proj for
non-CRS input is now so hard where before it just worked out-of-the box.

If there are no plans to add some helper function for this use-case, can you
confirm that the right solution would be something like (some error checking
omitted for brevity):

    PJ *P;
    PJ *source = proj_create(ctx, source_string);
    PJ *target = proj_create(ctx, target_string);
    if(proj_is_crs(source) && proj_is_crs(target)) {
        P = proj_create_crs_to_crs_from_pj(ctx, source, target, NULL, NULL);
        // continue with proj_normalize_for_visualization according to the migration guide
    } else {
        /* 1. if source is a pipeline:
                 1.1. parse the pipeline string and remove
                 1.2. reverse steps
                 1.3. invert +inv
           2. if target is a pipeline, keep the order and +inv as is
         */
        P = proj_create(ctx, "+proj=pipeline +step " +
              /* result of (1.) without leading +proj=pipeline */
              + " +step " +
              /* result of (2.) without leading +proj=pipeline */
        );
    }

What to do if source or target is not a CRS and also not a pipeline?

Thanks again!

cheers, josch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: signature
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20220414/8e539385/attachment.sig>


More information about the PROJ mailing list