I'm posting this question here instead of gis.stackexchange.com because I think this is more of a programming question than a GIS question.
The proj migration guide explains how to convert code to proj 6 and later by turning code that looked like this (error handling omitted for brevity):
projPJ pj_longlat = pj_init_plus(source);
projPJ pj_merc = pj_init_plus(target);
pj_transform(pj_longlat, pj_merc, ...)
into code that looks like this:
PJ *P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, source, target, NULL);
proj_trans(P, PJ_FWD, ...);
This is what was done in several projects including mapnik but there is one downside: with the new code, both source
and target
must be a CRS or otherwise proj_create_crs_to_crs
will fail with:
proj_create_operations: source_crs is not a CRS
This means that some applications (for example I successfully used mapnik rendering with a +proj=pipeline
projection, which is not a CRS) are not possible anymore.
In a proj issue report a developer points out that it should be possible to avoid proj_create_crs_to_crs
by using proj_create
manually. But if I understand it correctly, then to create a PJ
object that transforms from source
to target
(and vice-versa) I need a pipeline but if one of my projections contains a pipeline, then this will not work because I cannot have nested pipelines.
So how would I convert code from the PROJ 4 to PROJ 6 API but without removing the ability to input arbitrary transformations, even those that are not a CRS?
Edit
I asked the same question on the PROJ mailing list and got this very helpful reply from Even Rouault. I'll use that to try and implement a solution.