Commit 56a64a85 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Proj 4 to 6 API Migration.

parent 065aeede
......@@ -19,7 +19,7 @@
#endif
#ifdef HAVE_LIBPROJ
#include "proj_api.h"
#include "proj.h"
#endif
#include <stdio.h>
......@@ -71,30 +71,30 @@ gen_param(const char *fmt, ...)
}
static void
proj_fwd_xyvals(projPJ &proj, size_t nvals, double *xvals, double *yvals)
proj_fwd_xyvals(PJ *proj, size_t nvals, double *xvals, double *yvals)
{
projUV p;
PJ_COORD p;
for (size_t i = 0; i < nvals; i++)
{
p.u = xvals[i] * DEG_TO_RAD;
p.v = yvals[i] * DEG_TO_RAD;
p = pj_fwd(p, proj);
xvals[i] = p.u;
yvals[i] = p.v;
p.uv.u = proj_torad(xvals[i]);
p.uv.v = proj_torad(yvals[i]);
p = proj_trans(proj, PJ_FWD, p);
xvals[i] = p.uv.u;
yvals[i] = p.uv.v;
}
}
static void
proj_inv_xyvals(projPJ &proj, size_t nvals, double *xvals, double *yvals)
proj_inv_xyvals(PJ *proj, size_t nvals, double *xvals, double *yvals)
{
projUV p;
PJ_COORD p;
for (size_t i = 0; i < nvals; i++)
{
p.u = xvals[i];
p.v = yvals[i];
p = pj_inv(p, proj);
xvals[i] = p.u * RAD_TO_DEG;
yvals[i] = p.v * RAD_TO_DEG;
p.uv.u = xvals[i];
p.uv.v = yvals[i];
p = proj_trans(proj, PJ_INV, p);
xvals[i] = proj_todeg(p.uv.u);
yvals[i] = proj_todeg(p.uv.v);
}
}
......@@ -103,13 +103,13 @@ do_proj_fwd(const char *params, size_t nvals, double *xvals, double *yvals)
{
if (Options::cdoVerbose) cdoPrint("Proj fwd: %s", params);
projPJ proj = pj_init_plus(params);
const int status = proj ? 0 : -1;
PJ *proj = proj_create(PJ_DEFAULT_CTX, params);
const int status = proj_errno(proj);
if (status == 0)
{
proj_fwd_xyvals(proj, nvals, xvals, yvals);
pj_free(proj);
proj_destroy(proj);
}
return status;
......@@ -120,13 +120,13 @@ do_proj_inv(const char *params, size_t nvals, double *xvals, double *yvals)
{
if (Options::cdoVerbose) cdoPrint("Proj inv: %s", params);
projPJ proj = pj_init_plus(params);
const int status = proj ? 0 : -1;
PJ *proj = proj_create(PJ_DEFAULT_CTX, params);
const int status = proj_errno(proj);
if (status == 0)
{
proj_inv_xyvals(proj, nvals, xvals, yvals);
pj_free(proj);
proj_destroy(proj);
}
return status;
......@@ -214,10 +214,10 @@ proj_lonlat_to_lcc(double missval, double lon_0, double lat_0, double lat_1, dou
const int status = do_proj_fwd(params.c_str(), nvals, xvals, yvals);
#else
const int status = -1;
const int status = 1;
#endif
if (status == -1) set_xyvals(missval, nvals, xvals, yvals);
if (status == 1) set_xyvals(missval, nvals, xvals, yvals);
return status;
}
......@@ -228,9 +228,9 @@ lonlat_to_lcc(double missval, double lon_0, double lat_0, double lat_1, double l
{
const int status = proj_lonlat_to_lcc(missval, lon_0, lat_0, lat_1, lat_2, a, rf, nvals, xvals, yvals);
#ifdef HAVE_LIBPROJ
if (status == -1) cdoAbort("proj library error: %s", pj_strerrno(pj_errno));
if (status) cdoAbort("proj library error: %s", proj_errno_string(status));
#else
if (status == -1) cdoAbort("proj library support not compiled in!");
if (status) cdoAbort("proj library support not compiled in!");
#endif
}
......@@ -266,10 +266,10 @@ proj_lcc_to_lonlat(double missval, double lon_0, double lat_0, double lat_1, dou
const int status = do_proj_inv(params.c_str(), nvals, xvals, yvals);
#else
const int status = -1;
const int status = 1;
#endif
if (status == -1) set_xyvals(missval, nvals, xvals, yvals);
if (status == 1) set_xyvals(missval, nvals, xvals, yvals);
return status;
}
......@@ -280,9 +280,9 @@ lcc_to_lonlat(double missval, double lon_0, double lat_0, double lat_1, double l
{
const int status = proj_lcc_to_lonlat(missval, lon_0, lat_0, lat_1, lat_2, a, rf, x_0, y_0, nvals, xvals, yvals);
#ifdef HAVE_LIBPROJ
if (status == -1) cdoAbort("proj library error: %s", pj_strerrno(pj_errno));
if (status) cdoAbort("proj library error: %s", proj_errno_string(status));
#else
if (status == -1) cdoAbort("proj library support not compiled in!");
if (status == 1) cdoAbort("proj library support not compiled in!");
#endif
}
......@@ -359,10 +359,10 @@ proj_lonlat_to_stere(double missval, double lon_0, double lat_ts, double lat_0,
const int status = do_proj_fwd(params.c_str(), nvals, xvals, yvals);
#else
const int status = -1;
const int status = 1;
#endif
if (status == -1) set_xyvals(missval, nvals, xvals, yvals);
if (status == 1) set_xyvals(missval, nvals, xvals, yvals);
return status;
}
......@@ -372,9 +372,9 @@ lonlat_to_stere(double missval, double lon_0, double lat_ts, double lat_0, doubl
{
const int status = proj_lonlat_to_stere(missval, lon_0, lat_ts, lat_0, a, nvals, xvals, yvals);
#ifdef HAVE_LIBPROJ
if (status == -1) cdoAbort("proj library error: %s", pj_strerrno(pj_errno));
if (status) cdoAbort("proj library error: %s", proj_errno_string(status));
#else
if (status == -1) cdoAbort("proj library support not compiled in!");
if (status == 1) cdoAbort("proj library support not compiled in!");
#endif
}
......@@ -408,10 +408,10 @@ proj_stere_to_lonlat(double missval, double lon_0, double lat_ts, double lat_0,
const int status = do_proj_inv(params.c_str(), nvals, xvals, yvals);
#else
const int status = -1;
const int status = 1;
#endif
if (status == -1) set_xyvals(missval, nvals, xvals, yvals);
if (status == 1) set_xyvals(missval, nvals, xvals, yvals);
return status;
}
......@@ -422,9 +422,9 @@ stere_to_lonlat(double missval, double lon_0, double lat_ts, double lat_0, doubl
{
const int status = proj_stere_to_lonlat(missval, lon_0, lat_ts, lat_0, a, x_0, y_0, nvals, xvals, yvals);
#ifdef HAVE_LIBPROJ
if (status == -1) cdoAbort("proj library error: %s", pj_strerrno(pj_errno));
if (status) cdoAbort("proj library error: %s", proj_errno_string(status));
#else
if (status == -1) cdoAbort("proj library support not compiled in!");
if (status == 1) cdoAbort("proj library support not compiled in!");
#endif
}
......@@ -503,7 +503,7 @@ cdo_sinu_to_lonlat(size_t nvals, double *xvals, double *yvals)
params += gen_param("+ellps=WGS84 ");
const int status = do_proj_inv(params.c_str(), nvals, xvals, yvals);
if (status == -1) cdoAbort("proj library error: %s", pj_strerrno(pj_errno));
if (status) cdoAbort("proj library error: %s", proj_errno_string(status));
check_xyvals(nvals, xvals, yvals);
#else
......@@ -598,7 +598,7 @@ cdo_laea_to_lonlat(int gridID, size_t nvals, double *xvals, double *yvals)
if (IS_NOT_EQUAL(y_0, 0)) params += gen_param("+y_0=%g ", y_0);
const int status = do_proj_inv(params.c_str(), nvals, xvals, yvals);
if (status == -1) cdoAbort("proj library error: %s", pj_strerrno(pj_errno));
if (status) cdoAbort("proj library error: %s", proj_errno_string(status));
check_xyvals(nvals, xvals, yvals);
#else
......@@ -611,7 +611,7 @@ cdo_proj_to_lonlat(char *proj_params, size_t nvals, double *xvals, double *yvals
{
#ifdef HAVE_LIBPROJ
const int status = do_proj_inv(proj_params, nvals, xvals, yvals);
if (status == -1) cdoAbort("proj library error: %s", pj_strerrno(pj_errno));
if (status) cdoAbort("proj library error: %s", proj_errno_string(status));
check_xyvals(nvals, xvals, yvals);
#else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment