[PROJ] [PROJ 6.0.0] Cannot create a Prime Meridian with proj_create_from_wkt

Didier Richard Didier.Richard at ign.fr
Tue Apr 30 05:41:54 PDT 2019


Hi all,

Still testing the library, it seams that the prime meridian creation with a call to proj_create_from_wkt() leads to getting an error. Is it a feature (cause one can create an ellipsoid using proj_create_from_wkt()) ?

Digging into the code, it looks like wkt2_grammar.y as no entry 'prime_meridian' in the entry point 'input".
A fast glance at OGC 18-010r5 does not answer to that fact (neither to the fact that creating an ellipsoid is allowed).

By the way, the warnings and errors thrown by proj_create_from_wkt() are not "merged" into the error handling API : proj_context_errno() returns NULL. Why not pushing back these messages to the error handling API ?

Any thoughts ?

The code :

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "proj.h"

int main ( int argc, char *argv[] ) {
    PJ_CONTEXT *c;
    PJ *pm, *pm2;
    double l, r;
    char *u;
    char *opts[] = {"MULTILINE=NO","OUTPUT_AXIS=AUTO",NULL};
    const char *wkt;
    PROJ_STRING_LIST w, g;

    c = proj_context_create();
    pm = proj_create_from_database(c,"EPSG","8901",PJ_CATEGORY_PRIME_MERIDIAN, 0,NULL);
    if (pm == NULL) {
        fprintf(stderr,"Error : %s\n", proj_errno_string(proj_context_errno(c)));
        return 1;
    }
    if (proj_prime_meridian_get_parameters(c,pm,&l,&r,(const char **)&u)) {
        fprintf(stderr,"l: %10.2f\n", l);
        fprintf(stderr,"r: %10.2f\n", r);
        fprintf(stderr,"u: %10s\n", u);
    }
    wkt = proj_as_wkt(c,pm,PJ_WKT2_2015,(const char * const *)opts);
    fprintf(stderr,"WKT:\n%s\n", wkt);

    pm2 = proj_create_from_wkt(c,wkt,NULL,&w,&g);
    if (pm2 == NULL) {
        PROJ_STRING_LIST m;
        size_t l = 0;
        char *msg;
        fprintf(stderr,"Error : %s\n", proj_errno_string(proj_context_errno(c)));
        if (w) {
            for (m= w;*m;m++) {
                l += strlen(*m);
            }
            msg = (char *)malloc(l+1);
            msg[0] = '\0';
            for (m= w;*m;m++) {
                msg = strcat(msg,*m);
            }
            fprintf(stderr,"Warning (wkt parser): %s\n", msg);
            free(msg);
            proj_string_list_destroy(w);
        }
        l = 0;
        if (g) {
            for (m= g;*m;m++) {
                l += strlen(*m);
            }
            msg = (char *)malloc(l+1);
            msg[0] = '\0';
            for (m= g;*m;m++) {
                msg = strcat(msg,*m);
            }
            fprintf(stderr,"Error   (wkt parser): %s\n", msg);
            free(msg);
            proj_string_list_destroy(g);
        }
        return 2;
    }

    if (w) { proj_string_list_destroy(w); }
    if (g) { proj_string_list_destroy(g); }
    proj_destroy(pm2);
    proj_destroy(pm);
    proj_context_destroy(c); /* may be omitted in the single threaded case */
    return 0;
}

The output:

l:       0.00
r:       0.02
u:     degree
WKT:
PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]
Error : (null)
Error   (wkt parser): unhandled keyword: PRIMEM

Regards,
--
RICHARD Didier - Chef du Centre de Compétences Technologies des Systèmes d'Information
http://fr.linkedin.com/pub/didier-richard/98/2a3/a8/ - https://www.osgeo.org/member/didier/
IGN/Direction des Sciences et Technologies de l'Information/ENSG Géomatique
6/8 avenue Blaise Pascal - BP Champs-sur-Marne - 77455 MARNE-LA-VALLÉE CEDEX 2
Tél : +33 (0) 1 43 98 83 23



More information about the PROJ mailing list