aboutsummaryrefslogtreecommitdiff
path: root/src/grids.cpp
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-12-15 00:51:46 +0100
committerEven Rouault <even.rouault@spatialys.com>2020-12-15 01:13:43 +0100
commit244a24104ded3a4573aeffa32160af21f76cbce6 (patch)
treef3a11529172719657cf7576e062e45e0f9452db5 /src/grids.cpp
parent1e9894b0e2b161e61546672bccb85a9ef21df541 (diff)
downloadPROJ-244a24104ded3a4573aeffa32160af21f76cbce6.tar.gz
PROJ-244a24104ded3a4573aeffa32160af21f76cbce6.zip
Revise error codes to have a reduced set exposed in the public API.
Fixes #2482 And also add proj_context_errno_string() Revise gie 'expect failure errno XXXX' strings
Diffstat (limited to 'src/grids.cpp')
-rw-r--r--src/grids.cpp225
1 files changed, 128 insertions, 97 deletions
diff --git a/src/grids.cpp b/src/grids.cpp
index 871e21ed..fb5966eb 100644
--- a/src/grids.cpp
+++ b/src/grids.cpp
@@ -197,7 +197,9 @@ GTXVerticalShiftGrid *GTXVerticalShiftGrid::open(PJ_CONTEXT *ctx,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fp->read(header, sizeof(header)) != sizeof(header)) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ pj_log(ctx, PJ_LOG_ERROR, _("Cannot read grid header"));
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -222,8 +224,9 @@ GTXVerticalShiftGrid *GTXVerticalShiftGrid::open(PJ_CONTEXT *ctx,
if (xorigin < -360 || xorigin > 360 || yorigin < -90 || yorigin > 90) {
pj_log(ctx, PJ_LOG_ERROR,
- "gtx file header has invalid extents, corrupt?");
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ _("gtx file header has invalid extents, corrupt?"));
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -258,7 +261,8 @@ bool GTXVerticalShiftGrid::valueAt(int x, int y, float &out) const {
m_fp->seek(40 + sizeof(float) * (y * m_width + x));
if (m_fp->read(&out, sizeof(out)) != sizeof(out)) {
- proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return false;
}
if (IS_LSB) {
@@ -621,7 +625,7 @@ bool GTiffGrid::valueAt(uint16 sample, int x, int yFromBottom,
try {
m_buffer.resize(blockSize);
} catch (const std::exception &e) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Exception %s", e.what());
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Exception %s"), e.what());
return false;
}
}
@@ -642,7 +646,7 @@ bool GTiffGrid::valueAt(uint16 sample, int x, int yFromBottom,
m_cache.insert(m_ifdIdx, blockId, m_buffer);
} catch (const std::exception &e) {
// Should normally not happen
- pj_log(m_ctx, PJ_LOG_ERROR, "Exception %s", e.what());
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Exception %s"), e.what());
}
}
@@ -847,35 +851,35 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
TIFFGetField(m_hTIFF, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(m_hTIFF, TIFFTAG_IMAGELENGTH, &height);
if (width == 0 || height == 0 || width > INT_MAX || height > INT_MAX) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Invalid image size");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Invalid image size"));
return nullptr;
}
uint16 samplesPerPixel = 0;
if (!TIFFGetField(m_hTIFF, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel)) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Missing SamplesPerPixel tag");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Missing SamplesPerPixel tag"));
return nullptr;
}
if (samplesPerPixel == 0) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Invalid SamplesPerPixel value");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Invalid SamplesPerPixel value"));
return nullptr;
}
uint16 bitsPerSample = 0;
if (!TIFFGetField(m_hTIFF, TIFFTAG_BITSPERSAMPLE, &bitsPerSample)) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Missing BitsPerSample tag");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Missing BitsPerSample tag"));
return nullptr;
}
uint16 planarConfig = 0;
if (!TIFFGetField(m_hTIFF, TIFFTAG_PLANARCONFIG, &planarConfig)) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Missing PlanarConfig tag");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Missing PlanarConfig tag"));
return nullptr;
}
uint16 sampleFormat = 0;
if (!TIFFGetField(m_hTIFF, TIFFTAG_SAMPLEFORMAT, &sampleFormat)) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Missing SampleFormat tag");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Missing SampleFormat tag"));
return nullptr;
}
@@ -893,9 +897,8 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
else if (sampleFormat == SAMPLEFORMAT_IEEEFP && bitsPerSample == 64)
dt = TIFFDataType::Float64;
else {
- pj_log(
- m_ctx, PJ_LOG_ERROR,
- "Unsupported combination of SampleFormat and BitsPerSample values");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Unsupported combination of SampleFormat "
+ "and BitsPerSample values"));
return nullptr;
}
@@ -903,7 +906,7 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
if (!TIFFGetField(m_hTIFF, TIFFTAG_PHOTOMETRIC, &photometric))
photometric = PHOTOMETRIC_MINISBLACK;
if (photometric != PHOTOMETRIC_MINISBLACK) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Unsupported Photometric value");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Unsupported Photometric value"));
return nullptr;
}
@@ -914,19 +917,19 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
if (compression != COMPRESSION_NONE &&
!TIFFIsCODECConfigured(compression)) {
pj_log(m_ctx, PJ_LOG_ERROR,
- "Cannot open TIFF file due to missing codec.");
+ _("Cannot open TIFF file due to missing codec."));
return nullptr;
}
// We really don't want to try dealing with old-JPEG images
if (compression == COMPRESSION_OJPEG) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Unsupported compression method.");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Unsupported compression method."));
return nullptr;
}
const auto blockSize = TIFFIsTiled(m_hTIFF) ? TIFFTileSize64(m_hTIFF)
: TIFFStripSize64(m_hTIFF);
if (blockSize == 0 || blockSize > 64 * 1024 * 2014) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Unsupported block size.");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Unsupported block size."));
return nullptr;
}
@@ -942,12 +945,12 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
} else {
if (count < 4 || (count % 4) != 0) {
pj_log(m_ctx, PJ_LOG_ERROR,
- "Wrong number of values in GeoKeys tag");
+ _("Wrong number of values in GeoKeys tag"));
return nullptr;
}
if (geokeys[0] != 1) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Unsupported GeoTIFF major version");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Unsupported GeoTIFF major version"));
return nullptr;
}
// We only know that we support GeoTIFF 1.0 and 1.1 at that time
@@ -971,9 +974,9 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
extent.isGeographic = false;
} else if (geokeys[i + 3] != ModelTypeGeographic) {
pj_log(m_ctx, PJ_LOG_ERROR,
- "Only GTModelTypeGeoKey = "
- "ModelTypeGeographic or ModelTypeProjected are "
- "supported");
+ _("Only GTModelTypeGeoKey = "
+ "ModelTypeGeographic or ModelTypeProjected are "
+ "supported"));
return nullptr;
}
} else if (geokeys[i] == GTRasterTypeGeoKey) {
@@ -996,8 +999,8 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
// a GeoTransformationMatrix, since negative values in GeoPixelScale
// have historically been implementation bugs.
if (matrix[1] != 0 || matrix[4] != 0) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Rotational terms not supported in "
- "GeoTransformationMatrix tag");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Rotational terms not supported in "
+ "GeoTransformationMatrix tag"));
return nullptr;
}
@@ -1009,12 +1012,12 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
double *geopixelscale = nullptr;
if (TIFFGetField(m_hTIFF, TIFFTAG_GEOPIXELSCALE, &count,
&geopixelscale) != 1) {
- pj_log(m_ctx, PJ_LOG_ERROR, "No GeoPixelScale tag");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("No GeoPixelScale tag"));
return nullptr;
}
if (count != 3) {
pj_log(m_ctx, PJ_LOG_ERROR,
- "Wrong number of values in GeoPixelScale tag");
+ _("Wrong number of values in GeoPixelScale tag"));
return nullptr;
}
hRes = geopixelscale[0];
@@ -1023,12 +1026,12 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
double *geotiepoints = nullptr;
if (TIFFGetField(m_hTIFF, TIFFTAG_GEOTIEPOINTS, &count,
&geotiepoints) != 1) {
- pj_log(m_ctx, PJ_LOG_ERROR, "No GeoTiePoints tag");
+ pj_log(m_ctx, PJ_LOG_ERROR, _("No GeoTiePoints tag"));
return nullptr;
}
if (count != 6) {
pj_log(m_ctx, PJ_LOG_ERROR,
- "Wrong number of values in GeoTiePoints tag");
+ _("Wrong number of values in GeoTiePoints tag"));
return nullptr;
}
@@ -1059,7 +1062,7 @@ std::unique_ptr<GTiffGrid> GTiffDataset::nextGrid() {
fabs(extent.south) <= M_PI + 1e-5)) &&
extent.west < extent.east && extent.south < extent.north &&
extent.resX > 1e-10 && extent.resY > 1e-10)) {
- pj_log(m_ctx, PJ_LOG_ERROR, "Inconsistent georeferencing for %s",
+ pj_log(m_ctx, PJ_LOG_ERROR, _("Inconsistent georeferencing for %s"),
m_filename.c_str());
return nullptr;
}
@@ -1279,7 +1282,7 @@ GTiffVGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const auto subfileType = grid->subfileType();
if (subfileType != 0 && subfileType != FILETYPE_PAGE) {
if (ifd == 0) {
- pj_log(ctx, PJ_LOG_ERROR, "Invalid subfileType");
+ pj_log(ctx, PJ_LOG_ERROR, _("Invalid subfileType"));
return nullptr;
} else {
pj_log(ctx, PJ_LOG_DEBUG_MAJOR,
@@ -1325,7 +1328,7 @@ GTiffVGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
}
if (idxSample >= grid->samplesPerPixel()) {
- pj_log(ctx, PJ_LOG_ERROR, "Invalid sample index");
+ pj_log(ctx, PJ_LOG_ERROR, _("Invalid sample index"));
return nullptr;
}
@@ -1389,16 +1392,17 @@ VerticalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
auto set = std::unique_ptr<VerticalShiftGridSet>(
GTiffVGridShiftSet::open(ctx, std::move(fp), actualName));
if (!set)
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return set;
#else
pj_log(ctx, PJ_LOG_ERROR,
- "TIFF grid, but TIFF support disabled in this build");
+ _("TIFF grid, but TIFF support disabled in this build"));
return nullptr;
#endif
}
- pj_log(ctx, PJ_LOG_DEBUG_MAJOR, "Unrecognized vertical grid format");
+ pj_log(ctx, PJ_LOG_ERROR, _("Unrecognized vertical grid format"));
return nullptr;
}
@@ -1570,7 +1574,8 @@ NTv1Grid *NTv1Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fp->read(header, sizeof(header)) != sizeof(header)) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -1589,8 +1594,9 @@ NTv1Grid *NTv1Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
if (*((int *)(header + 8)) != 12) {
pj_log(ctx, PJ_LOG_ERROR,
- "NTv1 grid shift file has wrong record count, corrupt?");
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ _("NTv1 grid shift file has wrong record count, corrupt?"));
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -1607,9 +1613,10 @@ NTv1Grid *NTv1Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
fabs(extent.south) <= M_PI + 1e-5 && extent.west < extent.east &&
extent.south < extent.north && extent.resX > 1e-10 &&
extent.resY > 1e-10)) {
- pj_log(ctx, PJ_LOG_ERROR, "Inconsistent georeferencing for %s",
+ pj_log(ctx, PJ_LOG_ERROR, _("Inconsistent georeferencing for %s"),
filename.c_str());
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
const int columns = static_cast<int>(
@@ -1631,7 +1638,8 @@ bool NTv1Grid::valueAt(int x, int y, bool compensateNTConvention,
m_fp->seek(192 + 2 * sizeof(double) * (y * m_width + m_width - 1 - x));
if (m_fp->read(&two_doubles[0], sizeof(two_doubles)) !=
sizeof(two_doubles)) {
- proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return false;
}
if (IS_LSB) {
@@ -1692,7 +1700,8 @@ CTable2Grid *CTable2Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fp->read(header, sizeof(header)) != sizeof(header)) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -1716,9 +1725,10 @@ CTable2Grid *CTable2Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
memcpy(&extent.resY, header + 120, 8);
if (!(fabs(extent.west) <= 4 * M_PI && fabs(extent.south) <= M_PI + 1e-5 &&
extent.resX > 1e-10 && extent.resY > 1e-10)) {
- pj_log(ctx, PJ_LOG_ERROR, "Inconsistent georeferencing for %s",
+ pj_log(ctx, PJ_LOG_ERROR, _("Inconsistent georeferencing for %s"),
filename.c_str());
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
int width;
@@ -1726,7 +1736,8 @@ CTable2Grid *CTable2Grid::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
memcpy(&width, header + 128, 4);
memcpy(&height, header + 132, 4);
if (width <= 0 || height <= 0) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
extent.east = extent.west + (width - 1) * extent.resX;
@@ -1744,7 +1755,8 @@ bool CTable2Grid::valueAt(int x, int y, bool compensateNTConvention,
float two_floats[2];
m_fp->seek(160 + 2 * sizeof(float) * (y * m_width + x));
if (m_fp->read(&two_floats[0], sizeof(two_floats)) != sizeof(two_floats)) {
- proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return false;
}
if (!IS_LSB) {
@@ -1828,7 +1840,8 @@ bool NTv2Grid::valueAt(int x, int y, bool compensateNTConvention,
4 * sizeof(float) *
(static_cast<unsigned long long>(y) * m_width + m_width - 1 - x));
if (m_fp->read(&two_float[0], sizeof(two_float)) != sizeof(two_float)) {
- proj_context_errno_set(m_ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(m_ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return false;
}
if (m_mustSwap) {
@@ -1862,14 +1875,16 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
/* Read the header. */
/* -------------------------------------------------------------------- */
if (fpRaw->read(header, sizeof(header)) != sizeof(header)) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
constexpr int OFFSET_GS_TYPE = 56;
if (memcmp(header + OFFSET_GS_TYPE, "SECONDS", 7) != 0) {
- pj_log(ctx, PJ_LOG_ERROR, "Only GS_TYPE=SECONDS is supported");
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ pj_log(ctx, PJ_LOG_ERROR, _("Only GS_TYPE=SECONDS is supported"));
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -1899,12 +1914,14 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
for (unsigned subfile = 0; subfile < num_subfiles; subfile++) {
// Read header
if (fpRaw->read(header, sizeof(header)) != sizeof(header)) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
if (strncmp(header, "SUB_NAME", 8) != 0) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -1944,9 +1961,10 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
fabs(extent.south) <= M_PI + 1e-5 && extent.west < extent.east &&
extent.south < extent.north && extent.resX > 1e-10 &&
extent.resY > 1e-10)) {
- pj_log(ctx, PJ_LOG_ERROR, "Inconsistent georeferencing for %s",
+ pj_log(ctx, PJ_LOG_ERROR, _("Inconsistent georeferencing for %s"),
filename.c_str());
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
const int columns = static_cast<int>(
@@ -1964,9 +1982,10 @@ std::unique_ptr<NTv2GridSet> NTv2GridSet::open(PJ_CONTEXT *ctx,
memcpy(&gs_count, header + OFFSET_GS_COUNT, 4);
if (gs_count / columns != static_cast<unsigned>(rows)) {
pj_log(ctx, PJ_LOG_ERROR,
- "GS_COUNT(%u) does not match expected cells (%dx%d)",
+ _("GS_COUNT(%u) does not match expected cells (%dx%d)"),
gs_count, columns, rows);
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return nullptr;
}
@@ -2161,11 +2180,11 @@ GTiffHGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const auto subfileType = grid->subfileType();
if (subfileType != 0 && subfileType != FILETYPE_PAGE) {
if (ifd == 0) {
- pj_log(ctx, PJ_LOG_ERROR, "Invalid subfileType");
+ pj_log(ctx, PJ_LOG_ERROR, _("Invalid subfileType"));
return nullptr;
} else {
pj_log(ctx, PJ_LOG_DEBUG_MAJOR,
- "Ignoring IFD %d as it has a unsupported subfileType",
+ _("Ignoring IFD %d as it has a unsupported subfileType"),
ifd);
continue;
}
@@ -2174,11 +2193,12 @@ GTiffHGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
if (grid->samplesPerPixel() < 2) {
if (ifd == 0) {
pj_log(ctx, PJ_LOG_ERROR,
- "At least 2 samples per pixel needed");
+ _("At least 2 samples per pixel needed"));
return nullptr;
} else {
pj_log(ctx, PJ_LOG_DEBUG_MAJOR,
- "Ignoring IFD %d as it has not at least 2 samples", ifd);
+ _("Ignoring IFD %d as it has not at least 2 samples"),
+ ifd);
continue;
}
}
@@ -2223,19 +2243,21 @@ GTiffHGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
}
}
if (foundDescriptionForLatOffset && !foundDescriptionForLonOffset) {
- pj_log(ctx, PJ_LOG_ERROR,
- "Found latitude_offset channel, but not longitude_offset");
+ pj_log(
+ ctx, PJ_LOG_ERROR,
+ _("Found latitude_offset channel, but not longitude_offset"));
return nullptr;
} else if (foundDescriptionForLonOffset &&
!foundDescriptionForLatOffset) {
- pj_log(ctx, PJ_LOG_ERROR,
- "Found longitude_offset channel, but not latitude_offset");
+ pj_log(
+ ctx, PJ_LOG_ERROR,
+ _("Found longitude_offset channel, but not latitude_offset"));
return nullptr;
}
if (idxLatShift >= grid->samplesPerPixel() ||
idxLonShift >= grid->samplesPerPixel()) {
- pj_log(ctx, PJ_LOG_ERROR, "Invalid sample index");
+ pj_log(ctx, PJ_LOG_ERROR, _("Invalid sample index"));
return nullptr;
}
@@ -2249,7 +2271,7 @@ GTiffHGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
positiveEast = true;
} else {
pj_log(ctx, PJ_LOG_ERROR,
- "Unsupported value %s for 'positive_value'",
+ _("Unsupported value %s for 'positive_value'"),
positiveValue.c_str());
return nullptr;
}
@@ -2264,7 +2286,7 @@ GTiffHGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
grid->metadataItem("UNITTYPE", idxLonShift);
if (unitLatShift != unitLonShift) {
pj_log(ctx, PJ_LOG_ERROR,
- "Different unit for longitude and latitude offset");
+ _("Different unit for longitude and latitude offset"));
return nullptr;
}
if (!unitLatShift.empty()) {
@@ -2275,7 +2297,7 @@ GTiffHGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
} else if (unitLatShift == "degree") {
convFactorToRadian = M_PI / 180.0;
} else {
- pj_log(ctx, PJ_LOG_ERROR, "Unsupported unit %s",
+ pj_log(ctx, PJ_LOG_ERROR, _("Unsupported unit %s"),
unitLatShift.c_str());
return nullptr;
}
@@ -2367,16 +2389,17 @@ HorizontalShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
auto set = std::unique_ptr<HorizontalShiftGridSet>(
GTiffHGridShiftSet::open(ctx, std::move(fp), actualName));
if (!set)
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return set;
#else
pj_log(ctx, PJ_LOG_ERROR,
- "TIFF grid, but TIFF support disabled in this build");
+ _("TIFF grid, but TIFF support disabled in this build"));
return nullptr;
#endif
}
- pj_log(ctx, PJ_LOG_DEBUG_MAJOR, "Unrecognized horizontal grid format");
+ pj_log(ctx, PJ_LOG_ERROR, _("Unrecognized horizontal grid format"));
return nullptr;
}
@@ -2628,11 +2651,11 @@ GTiffGenericGridShiftSet::open(PJ_CONTEXT *ctx, std::unique_ptr<File> fp,
const auto subfileType = grid->subfileType();
if (subfileType != 0 && subfileType != FILETYPE_PAGE) {
if (ifd == 0) {
- pj_log(ctx, PJ_LOG_ERROR, "Invalid subfileType");
+ pj_log(ctx, PJ_LOG_ERROR, _("Invalid subfileType"));
return nullptr;
} else {
pj_log(ctx, PJ_LOG_DEBUG_MAJOR,
- "Ignoring IFD %d as it has a unsupported subfileType",
+ _("Ignoring IFD %d as it has a unsupported subfileType"),
ifd);
continue;
}
@@ -2703,16 +2726,17 @@ GenericShiftGridSet::open(PJ_CONTEXT *ctx, const std::string &filename) {
auto set = std::unique_ptr<GenericShiftGridSet>(
GTiffGenericGridShiftSet::open(ctx, std::move(fp), actualName));
if (!set)
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return set;
#else
pj_log(ctx, PJ_LOG_ERROR,
- "TIFF grid, but TIFF support disabled in this build");
+ _("TIFF grid, but TIFF support disabled in this build"));
return nullptr;
#endif
}
- pj_log(ctx, PJ_LOG_DEBUG_MAJOR, "Unrecognized generic grid format");
+ pj_log(ctx, PJ_LOG_ERROR, _("Unrecognized generic grid format"));
return nullptr;
}
@@ -2785,8 +2809,9 @@ ListOfGenericGrids pj_generic_grid_init(PJ *P, const char *gridkey) {
auto gridSet = GenericShiftGridSet::open(P->ctx, gridname);
if (!gridSet) {
if (!canFail) {
- if (proj_context_errno(P->ctx) != PJD_ERR_NETWORK_ERROR) {
- proj_context_errno_set(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ if (proj_context_errno(P->ctx) != PROJ_ERR_OTHER_NETWORK_ERROR) {
+ proj_context_errno_set(
+ P->ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
return {};
}
@@ -2830,8 +2855,9 @@ static ListOfHGrids getListOfGridSets(PJ_CONTEXT *ctx, const char *grids) {
auto gridSet = HorizontalShiftGridSet::open(ctx, gridname);
if (!gridSet) {
if (!canFail) {
- if (proj_context_errno(ctx) != PJD_ERR_NETWORK_ERROR) {
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ if (proj_context_errno(ctx) != PROJ_ERR_OTHER_NETWORK_ERROR) {
+ proj_context_errno_set(
+ ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
return {};
}
@@ -3067,7 +3093,7 @@ PJ_LP pj_hgrid_apply(PJ_CONTEXT *ctx, const ListOfHGrids &grids, PJ_LP lp,
HorizontalShiftGridSet *gridset = nullptr;
const auto grid = findGrid(grids, lp, gridset);
if (!grid) {
- proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(ctx, PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID);
return out;
}
if (grid->isNullGrid()) {
@@ -3083,7 +3109,7 @@ PJ_LP pj_hgrid_apply(PJ_CONTEXT *ctx, const ListOfHGrids &grids, PJ_LP lp,
}
if (out.lam == HUGE_VAL || out.phi == HUGE_VAL)
- proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(ctx, PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID);
return out;
}
@@ -3099,7 +3125,7 @@ PJ_LP pj_hgrid_value(PJ *P, const ListOfHGrids &grids, PJ_LP lp) {
HorizontalShiftGridSet *gridset = nullptr;
const auto grid = findGrid(grids, lp, gridset);
if (!grid) {
- proj_context_errno_set(P->ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(P->ctx, PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID);
return out;
}
@@ -3107,8 +3133,9 @@ PJ_LP pj_hgrid_value(PJ *P, const ListOfHGrids &grids, PJ_LP lp) {
const auto &extent = grid->extentAndRes();
if (!extent.isGeographic) {
pj_log(P->ctx, PJ_LOG_ERROR,
- "Can only handle grids referenced in a geographic CRS");
- proj_context_errno_set(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ _("Can only handle grids referenced in a geographic CRS"));
+ proj_context_errno_set(P->ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return out;
}
@@ -3131,7 +3158,7 @@ PJ_LP pj_hgrid_value(PJ *P, const ListOfHGrids &grids, PJ_LP lp) {
}
if (out.lam == HUGE_VAL || out.phi == HUGE_VAL) {
- proj_context_errno_set(P->ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(P->ctx, PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID);
}
return out;
@@ -3158,7 +3185,7 @@ static double read_vgrid_value(PJ_CONTEXT *ctx, const ListOfVGrids &grids,
}
}
if (!grid) {
- proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
+ proj_context_errno_set(ctx, PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID);
return HUGE_VAL;
}
if (grid->isNullGrid()) {
@@ -3168,8 +3195,9 @@ static double read_vgrid_value(PJ_CONTEXT *ctx, const ListOfVGrids &grids,
const auto &extent = grid->extentAndRes();
if (!extent.isGeographic) {
pj_log(ctx, PJ_LOG_ERROR,
- "Can only handle grids referenced in a geographic CRS");
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ _("Can only handle grids referenced in a geographic CRS"));
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return HUGE_VAL;
}
@@ -3200,8 +3228,8 @@ static double read_vgrid_value(PJ_CONTEXT *ctx, const ListOfVGrids &grids,
int grid_ix = static_cast<int>(lround(floor(grid_x)));
if (!(grid_ix >= 0 && grid_ix < grid->width())) {
// in the unlikely case we end up here...
- pj_log(ctx, PJ_LOG_ERROR, "grid_ix not in grid");
- proj_context_errno_set(ctx, PJD_ERR_GRID_AREA);
+ pj_log(ctx, PJ_LOG_ERROR, _("grid_ix not in grid"));
+ proj_context_errno_set(ctx, PROJ_ERR_COORD_TRANSFM_OUTSIDE_GRID);
return HUGE_VAL;
}
int grid_iy = static_cast<int>(lround(floor(grid_y)));
@@ -3268,9 +3296,10 @@ static double read_vgrid_value(PJ_CONTEXT *ctx, const ListOfVGrids &grids,
total_weight += weight;
n_weights++;
}
- if (n_weights == 0)
+ if (n_weights == 0) {
+ proj_context_errno_set(ctx, PROJ_ERR_COORD_TRANSFM_GRID_AT_NODATA);
value = HUGE_VAL;
- else if (n_weights != 4)
+ } else if (n_weights != 4)
value /= total_weight;
return value * vmultiplier;
@@ -3309,8 +3338,9 @@ ListOfVGrids pj_vgrid_init(PJ *P, const char *gridkey) {
auto gridSet = VerticalShiftGridSet::open(P->ctx, gridname);
if (!gridSet) {
if (!canFail) {
- if (proj_context_errno(P->ctx) != PJD_ERR_NETWORK_ERROR) {
- proj_context_errno_set(P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ if (proj_context_errno(P->ctx) != PROJ_ERR_OTHER_NETWORK_ERROR) {
+ proj_context_errno_set(
+ P->ctx, PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
}
return {};
}
@@ -3379,7 +3409,8 @@ bool pj_bilinear_interpolation_three_samples(
if (!extent.isGeographic) {
pj_log(ctx, PJ_LOG_ERROR,
"Can only handle grids referenced in a geographic CRS");
- proj_context_errno_set(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
+ proj_context_errno_set(ctx,
+ PROJ_ERR_INVALID_OP_FILE_NOT_FOUND_OR_INVALID);
return false;
}