aboutsummaryrefslogtreecommitdiff
path: root/src/transformations
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-12-16 15:12:51 +0100
committerGitHub <noreply@github.com>2020-12-16 15:12:51 +0100
commit5e077729274f5d28e137e1a41f7d3350146614ef (patch)
treed1ef799526f06828328b58ce8ee92c028f723b6a /src/transformations
parent8b1ef9504d0bcfbd8433df943e307bbd1aa30c4f (diff)
parenta27c0255e7b8e6aab1b91e49fd7870d1ee4e1a80 (diff)
downloadPROJ-5e077729274f5d28e137e1a41f7d3350146614ef.tar.gz
PROJ-5e077729274f5d28e137e1a41f7d3350146614ef.zip
Merge pull request #2487 from rouault/error_mgt_improvements
Error management: revise error codes and expose them to the public API
Diffstat (limited to 'src/transformations')
-rw-r--r--src/transformations/affine.cpp6
-rw-r--r--src/transformations/defmodel.cpp48
-rw-r--r--src/transformations/deformation.cpp42
-rw-r--r--src/transformations/helmert.cpp32
-rw-r--r--src/transformations/hgridshift.cpp8
-rw-r--r--src/transformations/horner.cpp74
-rw-r--r--src/transformations/molodensky.cpp54
-rw-r--r--src/transformations/tinshift.cpp20
-rw-r--r--src/transformations/vgridshift.cpp8
-rw-r--r--src/transformations/xyzgridshift.cpp14
10 files changed, 165 insertions, 141 deletions
diff --git a/src/transformations/affine.cpp b/src/transformations/affine.cpp
index 43fd8642..e6a94f1e 100644
--- a/src/transformations/affine.cpp
+++ b/src/transformations/affine.cpp
@@ -154,7 +154,7 @@ static void computeReverseParameters(PJ* P)
const double det = a * A + b * B + c * C;
if( det == 0.0 || Q->forward.tscale == 0.0 ) {
if (proj_log_level(P->ctx, PJ_LOG_TELL) >= PJ_LOG_DEBUG) {
- proj_log_debug(P, "Affine: matrix non invertible");
+ proj_log_debug(P, "matrix non invertible");
}
P->inv4d = nullptr;
P->inv3d = nullptr;
@@ -176,7 +176,7 @@ static void computeReverseParameters(PJ* P)
PJ *TRANSFORMATION(affine,0 /* no need for ellipsoid */) {
struct pj_opaque_affine *Q = initQ();
if (nullptr==Q)
- return pj_default_destructor(P, ENOMEM);
+ return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
P->opaque = (void *) Q;
P->fwd4d = forward_4d;
@@ -227,7 +227,7 @@ PJ *TRANSFORMATION(affine,0 /* no need for ellipsoid */) {
PJ *TRANSFORMATION(geogoffset,0 /* no need for ellipsoid */) {
struct pj_opaque_affine *Q = initQ();
if (nullptr==Q)
- return pj_default_destructor(P, ENOMEM);
+ return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
P->opaque = (void *) Q;
P->fwd4d = forward_4d;
diff --git a/src/transformations/defmodel.cpp b/src/transformations/defmodel.cpp
index 3d0f2a58..0d9f6690 100644
--- a/src/transformations/defmodel.cpp
+++ b/src/transformations/defmodel.cpp
@@ -68,8 +68,7 @@ struct Grid : public GridPrototype {
if (!checkedHorizontal) {
const auto samplesPerPixel = realGrid->samplesPerPixel();
if (samplesPerPixel < 2) {
- pj_log(ctx, PJ_LOG_ERROR,
- "defmodel: grid %s has not enough samples",
+ pj_log(ctx, PJ_LOG_ERROR, "grid %s has not enough samples",
realGrid->name().c_str());
return false;
}
@@ -90,15 +89,14 @@ struct Grid : public GridPrototype {
}
}
if (foundDesc && (!foundDescX || !foundDescY)) {
- pj_log(ctx, PJ_LOG_ERROR,
- "defmodel: grid %s : Found band description, "
- "but not the ones expected",
+ pj_log(ctx, PJ_LOG_ERROR, "grid %s : Found band description, "
+ "but not the ones expected",
realGrid->name().c_str());
return false;
}
const auto unit = realGrid->unit(sampleX);
if (!unit.empty() && unit != expectedUnit) {
- pj_log(ctx, PJ_LOG_ERROR, "defmodel: grid %s : Only unit=%s "
+ pj_log(ctx, PJ_LOG_ERROR, "grid %s : Only unit=%s "
"currently handled for this mode",
realGrid->name().c_str(), expectedUnit.c_str());
return false;
@@ -130,8 +128,7 @@ struct Grid : public GridPrototype {
if (samplesPerPixel == 1) {
sampleZ = 0;
} else if (samplesPerPixel < 3) {
- pj_log(ctx, PJ_LOG_ERROR,
- "defmodel: grid %s has not enough samples",
+ pj_log(ctx, PJ_LOG_ERROR, "grid %s has not enough samples",
realGrid->name().c_str());
return false;
}
@@ -148,17 +145,15 @@ struct Grid : public GridPrototype {
}
}
if (foundDesc && !foundDescZ) {
- pj_log(ctx, PJ_LOG_ERROR,
- "defmodel: grid %s : Found band description, "
- "but not the ones expected",
+ pj_log(ctx, PJ_LOG_ERROR, "grid %s : Found band description, "
+ "but not the ones expected",
realGrid->name().c_str());
return false;
}
const auto unit = realGrid->unit(sampleZ);
if (!unit.empty() && unit != STR_METRE) {
- pj_log(ctx, PJ_LOG_ERROR,
- "defmodel: grid %s : Only unit=metre currently "
- "handled for this mode",
+ pj_log(ctx, PJ_LOG_ERROR, "grid %s : Only unit=metre currently "
+ "handled for this mode",
realGrid->name().c_str());
return false;
}
@@ -256,8 +251,7 @@ struct EvaluatorIface : public EvaluatorIfacePrototype<Grid, GridSet> {
std::unique_ptr<GridSet> open(const std::string &filename) {
auto realGridSet = NS_PROJ::GenericShiftGridSet::open(ctx, filename);
if (!realGridSet) {
- pj_log(ctx, PJ_LOG_ERROR, "defmodel: cannot open %s",
- filename.c_str());
+ pj_log(ctx, PJ_LOG_ERROR, "cannot open %s", filename.c_str());
return nullptr;
}
return std::unique_ptr<GridSet>(
@@ -390,7 +384,7 @@ PJ *TRANSFORMATION(defmodel, 1) {
// Pass a dummy ellipsoid definition that will be overridden just afterwards
auto cart = proj_create(P->ctx, "+proj=cart +a=1");
if (cart == nullptr)
- return destructor(P, ENOMEM);
+ return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
/* inherit ellipsoid definition from P to Q->cart */
pj_inherit_ellipsoid_def(P, cart);
@@ -402,14 +396,14 @@ PJ *TRANSFORMATION(defmodel, 1) {
const char *model = pj_param(P->ctx, P->params, "smodel").s;
if (!model) {
- proj_log_error(P, "defmodel: +model= should be specified.");
- return destructor(P, PJD_ERR_NO_ARGS);
+ proj_log_error(P, _("+model= should be specified."));
+ return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
auto file = NS_PROJ::FileManager::open_resource_file(P->ctx, model);
if (nullptr == file) {
- proj_log_error(P, "defmodel: Cannot open %s", model);
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("Cannot open %s"), model);
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
file->seek(0, SEEK_END);
unsigned long long size = file->tell();
@@ -417,23 +411,23 @@ PJ *TRANSFORMATION(defmodel, 1) {
// that could be a denial of service risk. 10 MB should be sufficiently
// large for any valid use !
if (size > 10 * 1024 * 1024) {
- proj_log_error(P, "defmodel: File %s too large", model);
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("File %s too large"), model);
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
file->seek(0);
std::string jsonStr;
jsonStr.resize(static_cast<size_t>(size));
if (file->read(&jsonStr[0], jsonStr.size()) != jsonStr.size()) {
- proj_log_error(P, "defmodel: Cannot read %s", model);
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("Cannot read %s"), model);
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
try {
Q->evaluator.reset(new Evaluator<Grid, GridSet, EvaluatorIface>(
MasterFile::parse(jsonStr), Q->evaluatorIface, P->a, P->b));
} catch (const std::exception &e) {
- proj_log_error(P, "defmodel: invalid model: %s", e.what());
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("invalid model: %s"), e.what());
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
P->fwd4d = forward_4d;
diff --git a/src/transformations/deformation.cpp b/src/transformations/deformation.cpp
index 8ce02bee..1a04d0f5 100644
--- a/src/transformations/deformation.cpp
+++ b/src/transformations/deformation.cpp
@@ -100,7 +100,7 @@ static bool get_grid_values(PJ* P,
}
const auto samplesPerPixel = grid->samplesPerPixel();
if( samplesPerPixel < 3 ) {
- proj_log_error(P, "deformation: grid has not enough samples");
+ proj_log_error(P, "grid has not enough samples");
return false;
}
int sampleE = 0;
@@ -119,7 +119,7 @@ static bool get_grid_values(PJ* P,
}
const auto unit = grid->unit(sampleE);
if( !unit.empty() && unit != "millimetres per year" ) {
- proj_log_error(P, "deformation: Only unit=millimetres per year currently handled");
+ proj_log_error(P, "Only unit=millimetres per year currently handled");
return false;
}
@@ -179,8 +179,8 @@ static PJ_XYZ get_grid_shift(PJ* P, const PJ_XYZ& cartesian) {
shift.lp = pj_hgrid_value(P, Q->hgrids, geodetic.lp);
shift.enu.u = pj_vgrid_value(P, Q->vgrids, geodetic.lp, 1.0);
- if (proj_errno(P) == PJD_ERR_GRID_AREA)
- proj_log_debug(P, "deformation: coordinate (%.3f, %.3f) outside deformation model",
+ if (proj_errno(P) == PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID)
+ proj_log_debug(P, "coordinate (%.3f, %.3f) outside deformation model",
proj_todeg(geodetic.lpz.lam), proj_todeg(geodetic.lpz.phi));
/* grid values are stored as mm/yr, we need m/yr */
@@ -261,7 +261,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) {
if (Q->dt == HUGE_VAL) {
out = proj_coord_error(); /* in the 3D case +t_obs must be specified */
- proj_log_debug(P, "deformation: +dt must be specified");
+ proj_log_debug(P, "+dt must be specified");
return out.xyz;
}
@@ -308,7 +308,7 @@ static PJ_LPZ reverse_3d(PJ_XYZ in, PJ *P) {
if (Q->dt == HUGE_VAL) {
out = proj_coord_error(); /* in the 3D case +t_obs must be specified */
- proj_log_debug(P, "deformation: +dt must be specified");
+ proj_log_debug(P, "+dt must be specified");
return out.lpz;
}
@@ -358,7 +358,7 @@ PJ *TRANSFORMATION(deformation,1) {
// Pass a dummy ellipsoid definition that will be overridden just afterwards
Q->cart = proj_create(P->ctx, "+proj=cart +a=1");
if (Q->cart == nullptr)
- return destructor(P, ENOMEM);
+ return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
/* inherit ellipsoid definition from P to Q->cart */
pj_inherit_ellipsoid_def (P, Q->cart);
@@ -369,8 +369,8 @@ PJ *TRANSFORMATION(deformation,1) {
/* Build gridlists. Both horizontal and vertical grids are mandatory. */
if ( !has_grids && (!has_xy_grids || !has_z_grids)) {
- proj_log_error(P, "deformation: Either +grids or (+xy_grids and +z_grids) should be specified.");
- return destructor(P, PJD_ERR_NO_ARGS );
+ proj_log_error(P, _("Either +grids or (+xy_grids and +z_grids) should be specified."));
+ return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG );
}
if( has_grids )
@@ -378,22 +378,22 @@ PJ *TRANSFORMATION(deformation,1) {
Q->grids = pj_generic_grid_init(P, "grids");
/* Was gridlist compiled properly? */
if ( proj_errno(P) ) {
- proj_log_error(P, "deformation: could not find required grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_log_error(P, _("could not find required grid(s).)"));
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
}
else
{
Q->hgrids = pj_hgrid_init(P, "xy_grids");
if (proj_errno(P)) {
- proj_log_error(P, "deformation: could not find requested xy_grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_log_error(P, _("could not find requested xy_grid(s)."));
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
Q->vgrids = pj_vgrid_init(P, "z_grids");
if (proj_errno(P)) {
- proj_log_error(P, "deformation: could not find requested z_grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_log_error(P, _("could not find requested z_grid(s)."));
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
}
@@ -403,8 +403,8 @@ PJ *TRANSFORMATION(deformation,1) {
}
if (pj_param_exists(P->params, "t_obs")) {
- proj_log_error(P, "deformation: +t_obs parameter is deprecated. Use +dt instead.");
- return destructor(P, PJD_ERR_MISSING_ARGS);
+ proj_log_error(P, _("+t_obs parameter is deprecated. Use +dt instead."));
+ return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
Q->t_epoch = HUGE_VAL;
@@ -413,13 +413,13 @@ PJ *TRANSFORMATION(deformation,1) {
}
if (Q->dt == HUGE_VAL && Q->t_epoch == HUGE_VAL) {
- proj_log_error(P, "deformation: either +dt or +t_epoch needs to be set.");
- return destructor(P, PJD_ERR_MISSING_ARGS);
+ proj_log_error(P, _("either +dt or +t_epoch needs to be set."));
+ return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
if (Q->dt != HUGE_VALL && Q->t_epoch != HUGE_VALL) {
- proj_log_error(P, "deformation: +dt or +t_epoch are mutually exclusive.");
- return destructor(P, PJD_ERR_MUTUALLY_EXCLUSIVE_ARGS);
+ proj_log_error(P, _("+dt or +t_epoch are mutually exclusive."));
+ return destructor(P, PROJ_ERR_INVALID_OP_MUTUALLY_EXCLUSIVE_ARGS);
}
P->fwd4d = forward_4d;
diff --git a/src/transformations/helmert.cpp b/src/transformations/helmert.cpp
index 99aa74a4..f9bb45e0 100644
--- a/src/transformations/helmert.cpp
+++ b/src/transformations/helmert.cpp
@@ -478,7 +478,7 @@ static PJ_COORD helmert_reverse_4d (PJ_COORD point, PJ *P) {
static PJ* init_helmert_six_parameters(PJ* P) {
struct pj_opaque_helmert *Q = static_cast<struct pj_opaque_helmert*>(calloc (1, sizeof (struct pj_opaque_helmert)));
if (nullptr==Q)
- return pj_default_destructor (P, ENOMEM);
+ return pj_default_destructor (P, PROJ_ERR_OTHER /*ENOMEM*/);
P->opaque = (void *) Q;
/* In most cases, we work on 3D cartesian coordinates */
@@ -522,8 +522,8 @@ static PJ* read_convention(PJ* P) {
if (!Q->no_rotation) {
const char* convention = pj_param (P->ctx, P->params, "sconvention").s;
if( !convention ) {
- proj_log_error (P, "helmert: missing 'convention' argument");
- return pj_default_destructor (P, PJD_ERR_MISSING_ARGS);
+ proj_log_error (P, _("helmert: missing 'convention' argument"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
if( strcmp(convention, "position_vector") == 0 ) {
Q->is_position_vector = 1;
@@ -532,17 +532,17 @@ static PJ* read_convention(PJ* P) {
Q->is_position_vector = 0;
}
else {
- proj_log_error (P, "helmert: invalid value for 'convention' argument");
- return pj_default_destructor (P, PJD_ERR_INVALID_ARG);
+ proj_log_error (P, _("helmert: invalid value for 'convention' argument"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
}
/* historically towgs84 in PROJ has always been using position_vector
* convention. Accepting coordinate_frame would be confusing. */
if (pj_param_exists (P->params, "towgs84")) {
if( !Q->is_position_vector ) {
- proj_log_error (P, "helmert: towgs84 should only be used with "
- "convention=position_vector");
- return pj_default_destructor (P, PJD_ERR_INVALID_ARG);
+ proj_log_error (P, _("helmert: towgs84 should only be used with "
+ "convention=position_vector"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
}
}
}
@@ -578,9 +578,9 @@ PJ *TRANSFORMATION(helmert, 0) {
/* Detect obsolete transpose flag and error out if found */
if (pj_param (P->ctx, P->params, "ttranspose").i) {
- proj_log_error (P, "helmert: 'transpose' argument is no longer valid. "
- "Use convention=position_vector/coordinate_frame");
- return pj_default_destructor (P, PJD_ERR_INVALID_ARG);
+ proj_log_error (P, _("helmert: 'transpose' argument is no longer valid. "
+ "Use convention=position_vector/coordinate_frame"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
}
/* Support the classic PROJ towgs84 parameter, but allow later overrides.*/
@@ -612,9 +612,15 @@ PJ *TRANSFORMATION(helmert, 0) {
if (pj_param (P->ctx, P->params, "ts").i) {
Q->scale_0 = pj_param (P->ctx, P->params, "ds").f;
if( Q->scale_0 <= -1.0e6 )
- return pj_default_destructor (P, PJD_ERR_INVALID_SCALE);
+ {
+ proj_log_error (P, _("helmert: invalid value for s."));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
+ }
if (pj_param (P->ctx, P->params, "ttheta").i && Q->scale_0 == 0.0)
- return pj_default_destructor (P, PJD_ERR_INVALID_SCALE);
+ {
+ proj_log_error (P, _("helmert: invalid value for s."));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
+ }
}
/* Translation rates */
diff --git a/src/transformations/hgridshift.cpp b/src/transformations/hgridshift.cpp
index b28eaf48..326bbb13 100644
--- a/src/transformations/hgridshift.cpp
+++ b/src/transformations/hgridshift.cpp
@@ -155,8 +155,8 @@ PJ *TRANSFORMATION(hgridshift,0) {
P->right = PJ_IO_UNITS_RADIANS;
if (0==pj_param(P->ctx, P->params, "tgrids").i) {
- proj_log_error(P, "hgridshift: +grids parameter missing.");
- return destructor (P, PJD_ERR_NO_ARGS);
+ proj_log_error(P, _("+grids parameter missing."));
+ return destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
/* TODO: Refactor into shared function that can be used */
@@ -194,8 +194,8 @@ PJ *TRANSFORMATION(hgridshift,0) {
Q->grids = pj_hgrid_init(P, "grids");
/* Was gridlist compiled properly? */
if ( proj_errno(P) ) {
- proj_log_error(P, "hgridshift: could not find required grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_log_error(P, _("could not find required grid(s)."));
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
gMutex.lock();
diff --git a/src/transformations/horner.cpp b/src/transformations/horner.cpp
index 2c049186..7c8ad192 100644
--- a/src/transformations/horner.cpp
+++ b/src/transformations/horner.cpp
@@ -115,7 +115,7 @@ struct horner {
} // anonymous namespace
typedef struct horner HORNER;
-static PJ_UV horner_func (const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position);
+static PJ_UV horner_func (PJ* P, const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position);
static HORNER *horner_alloc (size_t order, int complex_polynomia);
static void horner_free (HORNER *h);
@@ -181,7 +181,7 @@ static HORNER *horner_alloc (size_t order, int complex_polynomia) {
/**********************************************************************/
-static PJ_UV horner_func (const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) {
+static PJ_UV horner_func (PJ* P, const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) {
/***********************************************************************
A reimplementation of the classic Engsager/Poder 2D Horner polynomial
@@ -237,7 +237,6 @@ summing the tiny high order elements first.
case PJ_INV: /* inverse */
break;
default: /* invalid */
- errno = EINVAL;
return uv_error;
}
@@ -259,7 +258,7 @@ summing the tiny high order elements first.
}
if ((fabs(n) > range) || (fabs(e) > range)) {
- errno = EDOM;
+ proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);
return uv_error;
}
@@ -297,12 +296,12 @@ summing the tiny high order elements first.
static PJ_COORD horner_forward_4d (PJ_COORD point, PJ *P) {
- point.uv = horner_func ((HORNER *) P->opaque, PJ_FWD, point.uv);
+ point.uv = horner_func (P, (HORNER *) P->opaque, PJ_FWD, point.uv);
return point;
}
static PJ_COORD horner_reverse_4d (PJ_COORD point, PJ *P) {
- point.uv = horner_func ((HORNER *) P->opaque, PJ_INV, point.uv);
+ point.uv = horner_func (P, (HORNER *) P->opaque, PJ_INV, point.uv);
return point;
}
@@ -310,7 +309,7 @@ static PJ_COORD horner_reverse_4d (PJ_COORD point, PJ *P) {
/**********************************************************************/
-static PJ_UV complex_horner (const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) {
+static PJ_UV complex_horner (PJ *P, const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) {
/***********************************************************************
A reimplementation of a classic Engsager/Poder Horner complex
@@ -337,7 +336,6 @@ polynomial evaluation engine.
case PJ_INV: /* inverse */
break;
default: /* invalid */
- errno = EINVAL;
return uv_error;
}
@@ -366,7 +364,7 @@ polynomial evaluation engine.
}
if ((fabs(n) > range) || (fabs(e) > range)) {
- errno = EDOM;
+ proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);
return uv_error;
}
@@ -387,12 +385,12 @@ polynomial evaluation engine.
static PJ_COORD complex_horner_forward_4d (PJ_COORD point, PJ *P) {
- point.uv = complex_horner ((HORNER *) P->opaque, PJ_FWD, point.uv);
+ point.uv = complex_horner (P, (HORNER *) P->opaque, PJ_FWD, point.uv);
return point;
}
static PJ_COORD complex_horner_reverse_4d (PJ_COORD point, PJ *P) {
- point.uv = complex_horner ((HORNER *) P->opaque, PJ_INV, point.uv);
+ point.uv = complex_horner (P, (HORNER *) P->opaque, PJ_INV, point.uv);
return point;
}
@@ -414,7 +412,7 @@ static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) {
buf = static_cast<char*>(calloc (strlen (param) + 2, sizeof(char)));
if (nullptr==buf) {
- proj_log_error (P, "Horner: No memory left");
+ proj_log_error (P, "No memory left");
return 0;
}
@@ -430,7 +428,7 @@ static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) {
for (i = 0; i < ncoefs; i++) {
if (i > 0) {
if ( next == nullptr || ','!=*next) {
- proj_log_error (P, "Horner: Malformed polynomium set %s. need %d coefs", param, ncoefs);
+ proj_log_error (P, "Malformed polynomium set %s. need %d coefs", param, ncoefs);
return 0;
}
init = ++next;
@@ -460,12 +458,12 @@ PJ *PROJECTION(horner) {
degree = pj_param(P->ctx, P->params, "ideg").i;
if (degree < 0 || degree > 10000) {
/* What are reasonable minimum and maximums for degree? */
- proj_log_debug (P, "Horner: Degree is unreasonable: %d", degree);
- return horner_freeup (P, PJD_ERR_INVALID_ARG);
+ proj_log_error (P, _("Degree is unreasonable: %d"), degree);
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
}
} else {
- proj_log_debug (P, "Horner: Must specify polynomial degree, (+deg=n)");
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ proj_log_error (P, _("Must specify polynomial degree, (+deg=n)"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
if (pj_param (P->ctx, P->params, "tfwd_c").i || pj_param (P->ctx, P->params, "tinv_c").i) /* complex polynomium? */
@@ -473,7 +471,7 @@ PJ *PROJECTION(horner) {
Q = horner_alloc (degree, complex_polynomia);
if (Q == nullptr)
- return horner_freeup (P, ENOMEM);
+ return horner_freeup (P, PROJ_ERR_OTHER /*ENOMEM*/);
P->opaque = Q;
if (complex_polynomia) {
@@ -483,9 +481,15 @@ PJ *PROJECTION(horner) {
n = 2*degree + 2;
if (0==parse_coefs (P, Q->fwd_c, "fwd_c", n))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing fwd_c"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
if (0==parse_coefs (P, Q->inv_c, "inv_c", n))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing inv_c"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
P->fwd4d = complex_horner_forward_4d;
P->inv4d = complex_horner_reverse_4d;
}
@@ -493,19 +497,37 @@ PJ *PROJECTION(horner) {
else {
n = horner_number_of_coefficients (degree);
if (0==parse_coefs (P, Q->fwd_u, "fwd_u", n))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing fwd_u"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
if (0==parse_coefs (P, Q->fwd_v, "fwd_v", n))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing fwd_v"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
if (0==parse_coefs (P, Q->inv_u, "inv_u", n))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing inv_u"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
if (0==parse_coefs (P, Q->inv_v, "inv_v", n))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing inv_v"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
}
if (0==parse_coefs (P, (double *)(Q->fwd_origin), "fwd_origin", 2))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing fwd_origin"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
if (0==parse_coefs (P, (double *)(Q->inv_origin), "inv_origin", 2))
- return horner_freeup (P, PJD_ERR_MISSING_ARGS);
+ {
+ proj_log_error (P, _("missing inv_origin"));
+ return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
+ }
if (0==parse_coefs (P, &Q->range, "range", 1))
Q->range = 500000;
diff --git a/src/transformations/molodensky.cpp b/src/transformations/molodensky.cpp
index bf5960d2..70cf987b 100644
--- a/src/transformations/molodensky.cpp
+++ b/src/transformations/molodensky.cpp
@@ -245,7 +245,7 @@ static PJ_XYZ forward_3d(PJ_LPZ lpz, PJ *P) {
lpz = calc_standard_params(lpz, P);
}
if( lpz.lam == HUGE_VAL ) {
- proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);
return proj_coord_error().xyz;
}
@@ -277,7 +277,7 @@ static PJ_LPZ reverse_3d(PJ_XYZ xyz, PJ *P) {
lpz = calc_standard_params(point.lpz, P);
if( lpz.lam == HUGE_VAL ) {
- proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
+ proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN);
return proj_coord_error().lpz;
}
@@ -297,10 +297,9 @@ static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
PJ *TRANSFORMATION(molodensky,1) {
- int count_required_params = 0;
struct pj_opaque_molodensky *Q = static_cast<struct pj_opaque_molodensky*>(calloc(1, sizeof(struct pj_opaque_molodensky)));
if (nullptr==Q)
- return pj_default_destructor(P, ENOMEM);
+ return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
P->opaque = (void *) Q;
P->fwd4d = forward_4d;
@@ -314,39 +313,42 @@ PJ *TRANSFORMATION(molodensky,1) {
P->right = PJ_IO_UNITS_RADIANS;
/* read args */
- if (pj_param(P->ctx, P->params, "tdx").i) {
- count_required_params ++;
- Q->dx = pj_param(P->ctx, P->params, "ddx").f;
+ if (!pj_param(P->ctx, P->params, "tdx").i)
+ {
+ proj_log_error (P, _("missing dx"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
+ Q->dx = pj_param(P->ctx, P->params, "ddx").f;
- if (pj_param(P->ctx, P->params, "tdy").i) {
- count_required_params ++;
- Q->dy = pj_param(P->ctx, P->params, "ddy").f;
+ if (!pj_param(P->ctx, P->params, "tdy").i)
+ {
+ proj_log_error (P, _("missing dy"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
+ Q->dy = pj_param(P->ctx, P->params, "ddy").f;
- if (pj_param(P->ctx, P->params, "tdz").i) {
- count_required_params ++;
- Q->dz = pj_param(P->ctx, P->params, "ddz").f;
+ if (!pj_param(P->ctx, P->params, "tdz").i)
+ {
+ proj_log_error (P, _("missing dz"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
+ Q->dz = pj_param(P->ctx, P->params, "ddz").f;
- if (pj_param(P->ctx, P->params, "tda").i) {
- count_required_params ++;
- Q->da = pj_param(P->ctx, P->params, "dda").f;
+ if (!pj_param(P->ctx, P->params, "tda").i)
+ {
+ proj_log_error (P, _("missing da"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
+ Q->da = pj_param(P->ctx, P->params, "dda").f;
- if (pj_param(P->ctx, P->params, "tdf").i) {
- count_required_params ++;
- Q->df = pj_param(P->ctx, P->params, "ddf").f;
+ if (!pj_param(P->ctx, P->params, "tdf").i)
+ {
+ proj_log_error (P, _("missing df"));
+ return pj_default_destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
+ Q->df = pj_param(P->ctx, P->params, "ddf").f;
Q->abridged = pj_param(P->ctx, P->params, "tabridged").i;
- /* We want all parameters (except +abridged) to be set */
- if (count_required_params == 0)
- return pj_default_destructor(P, PJD_ERR_NO_ARGS);
-
- if (count_required_params != 5)
- return pj_default_destructor(P, PJD_ERR_MISSING_ARGS);
-
return P;
}
diff --git a/src/transformations/tinshift.cpp b/src/transformations/tinshift.cpp
index 96e0ea4f..51e063eb 100644
--- a/src/transformations/tinshift.cpp
+++ b/src/transformations/tinshift.cpp
@@ -86,14 +86,14 @@ PJ *TRANSFORMATION(tinshift, 1) {
const char *filename = pj_param(P->ctx, P->params, "sfile").s;
if (!filename) {
- proj_log_error(P, "tinshift: +file= should be specified.");
- return destructor(P, PJD_ERR_NO_ARGS);
+ proj_log_error(P, _("+file= should be specified."));
+ return destructor(P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
auto file = NS_PROJ::FileManager::open_resource_file(P->ctx, filename);
if (nullptr == file) {
- proj_log_error(P, "tinshift: Cannot open %s", filename);
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("Cannot open %s"), filename);
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
file->seek(0, SEEK_END);
unsigned long long size = file->tell();
@@ -101,15 +101,15 @@ PJ *TRANSFORMATION(tinshift, 1) {
// that could be a denial of service risk. 10 MB should be sufficiently
// large for any valid use !
if (size > 10 * 1024 * 1024) {
- proj_log_error(P, "tinshift: File %s too large", filename);
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("File %s too large"), filename);
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
file->seek(0);
std::string jsonStr;
jsonStr.resize(static_cast<size_t>(size));
if (file->read(&jsonStr[0], jsonStr.size()) != jsonStr.size()) {
- proj_log_error(P, "tinshift: Cannot read %s", filename);
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("Cannot read %s"), filename);
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
auto Q = new tinshiftData();
@@ -119,8 +119,8 @@ PJ *TRANSFORMATION(tinshift, 1) {
try {
Q->evaluator.reset(new Evaluator(TINShiftFile::parse(jsonStr)));
} catch (const std::exception &e) {
- proj_log_error(P, "tinshift: invalid model: %s", e.what());
- return destructor(P, PJD_ERR_INVALID_ARG);
+ proj_log_error(P, _("invalid model: %s"), e.what());
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
P->destructor = destructor;
diff --git a/src/transformations/vgridshift.cpp b/src/transformations/vgridshift.cpp
index 3d9f046a..7b234517 100644
--- a/src/transformations/vgridshift.cpp
+++ b/src/transformations/vgridshift.cpp
@@ -179,8 +179,8 @@ PJ *TRANSFORMATION(vgridshift,0) {
P->reassign_context = reassign_context;
if (!pj_param(P->ctx, P->params, "tgrids").i) {
- proj_log_error(P, "vgridshift: +grids parameter missing.");
- return destructor(P, PJD_ERR_NO_ARGS);
+ proj_log_error(P, _("+grids parameter missing."));
+ return destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
/* TODO: Refactor into shared function that can be used */
@@ -227,8 +227,8 @@ PJ *TRANSFORMATION(vgridshift,0) {
/* Was gridlist compiled properly? */
if ( proj_errno(P) ) {
- proj_log_error(P, "vgridshift: could not find required grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_log_error(P, _("could not find required grid(s)."));
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
gMutex.lock();
diff --git a/src/transformations/xyzgridshift.cpp b/src/transformations/xyzgridshift.cpp
index e37e874d..c75944ba 100644
--- a/src/transformations/xyzgridshift.cpp
+++ b/src/transformations/xyzgridshift.cpp
@@ -257,7 +257,7 @@ PJ *TRANSFORMATION(xyzgridshift,0) {
// Pass a dummy ellipsoid definition that will be overridden just afterwards
Q->cart = proj_create(P->ctx, "+proj=cart +a=1");
if (Q->cart == nullptr)
- return destructor(P, ENOMEM);
+ return destructor(P, PROJ_ERR_OTHER /*ENOMEM*/);
/* inherit ellipsoid definition from P to Q->cart */
pj_inherit_ellipsoid_def (P, Q->cart);
@@ -272,14 +272,14 @@ PJ *TRANSFORMATION(xyzgridshift,0) {
// in RGF93
Q->grid_ref_is_input = false;
} else {
- proj_log_error(P, "xyzgridshift: unusupported value for grid_ref");
- return destructor (P, PJD_ERR_NO_ARGS);
+ proj_log_error(P, _("unusupported value for grid_ref"));
+ return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
}
}
if (0==pj_param(P->ctx, P->params, "tgrids").i) {
- proj_log_error(P, "xyzgridshift: +grids parameter missing.");
- return destructor (P, PJD_ERR_NO_ARGS);
+ proj_log_error(P, _("+grids parameter missing."));
+ return destructor (P, PROJ_ERR_INVALID_OP_MISSING_ARG);
}
/* multiplier for delta x,y,z */
@@ -294,8 +294,8 @@ PJ *TRANSFORMATION(xyzgridshift,0) {
Q->grids = pj_generic_grid_init(P, "grids");
/* Was gridlist compiled properly? */
if ( proj_errno(P) ) {
- proj_log_error(P, "xyzgridshift: could not find required grid(s).");
- return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_log_error(P, _("could not find required grid(s)."));
+ return destructor(P, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
}