[PROJ] proj_create_crs_to_crs_from_pj fails with no error

Eric Buddington s+proj at eric.buddington.net
Wed Jul 29 13:49:46 PDT 2020


I'm upgrading old code to use modern proj routines and use WKS strings
instead.  To handle old PROJ strings (because I don't know the correct
WKS string), I hack in an extra "+type=crs".

When I do this, the call to proj_create succeeds, but
proj_create_crs_to_crs_from_pj() returns NULL and proj_errno(NULL)
returns 0. I want an error message!

Are my expectations for error reporting wrong here?

Here's the code snippet that's failing (throws "failed with no error")
with crs_string2 =
  "+type=crs +proj=longlat +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs"

<code>
    PJptr const crs1 = proj_create (PJ_DEFAULT_CTX, crs_string2.c_str());
    if (crs1.ptr == NULL)
      throw std::runtime_error
        (std::string ("proj_create (dest):")
         + proj_errno_string (proj_errno (crs1.ptr)));
    
    PJptr const crs_ecef = proj_create (PJ_DEFAULT_CTX,
                                        "+type=crs +proj=geocent +units=m");
    if (crs_ecef.ptr == NULL)
      throw std::runtime_error
        (std::string ("proj_create (ecef):")
         + proj_errno_string (proj_errno (crs1.ptr)));
    
    PJ* proj0 = proj_create_crs_to_crs_from_pj
      (PJ_DEFAULT_CTX, crs1.ptr, crs_ecef.ptr, NULL, NULL);
    if (proj0 == NULL)
      {
        int const err_no = proj_errno (NULL);
        char const * err_str = proj_errno_string (err_no);
        if (err_str == NULL)
          throw std::runtime_error
            ("proj_create_crs_to_crs failed with no error");
        else
          throw std::runtime_error (std::string ("proj_crs_to_crs")
                                    + proj_errno_string (proj_errno (NULL)));
      }
</code>

I'd appreciate any advice!

-Eric


More information about the PROJ mailing list