Skip to content

Commit

Permalink
OGRCoordinateTransformation::Transform(): change nCount parameter to …
Browse files Browse the repository at this point in the history
…size_t (C++ API only for now) (fixe OSGeo#9074)
  • Loading branch information
rouault committed Jan 13, 2024
1 parent 4daa319 commit 7dc586b
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 73 deletions.
4 changes: 2 additions & 2 deletions apps/gdal_footprint_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@ class GeoTransformCoordinateTransformation final
return nullptr;
}

int Transform(int nCount, double *x, double *y, double * /* z */,
int Transform(size_t nCount, double *x, double *y, double * /* z */,
double * /* t */, int *pabSuccess) override
{
for (int i = 0; i < nCount; ++i)
for (size_t i = 0; i < nCount; ++i)
{
const double X = m_gt[0] + x[i] * m_gt[1] + y[i] * m_gt[2];
const double Y = m_gt[3] + x[i] * m_gt[4] + y[i] * m_gt[5];
Expand Down
9 changes: 6 additions & 3 deletions apps/gdalwarp_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4700,11 +4700,14 @@ class CutlineTransformer : public OGRCoordinateTransformation
GDALDestroyTransformer(hSrcImageTransformer);
}

virtual int Transform(int nCount, double *x, double *y, double *z,
virtual int Transform(size_t nCount, double *x, double *y, double *z,
double * /* t */, int *pabSuccess) override
{
return GDALGenImgProjTransform(hSrcImageTransformer, TRUE, nCount, x, y,
z, pabSuccess);
CPLAssert(nCount <=
static_cast<size_t>(std::numeric_limits<int>::max()));
return GDALGenImgProjTransform(hSrcImageTransformer, TRUE,
static_cast<int>(nCount), x, y, z,
pabSuccess);
}

virtual OGRCoordinateTransformation *Clone() const override
Expand Down
17 changes: 11 additions & 6 deletions apps/ogr2ogr_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <cstring>

#include <algorithm>
#include <limits>
#include <map>
#include <memory>
#include <set>
Expand Down Expand Up @@ -1127,14 +1128,18 @@ class GCPCoordTransformation : public OGRCoordinateTransformation
return poSRS;
}

virtual int Transform(int nCount, double *x, double *y, double *z,
virtual int Transform(size_t nCount, double *x, double *y, double *z,
double * /* t */, int *pabSuccess) override
{
CPLAssert(nCount <=
static_cast<size_t>(std::numeric_limits<int>::max()));
if (bUseTPS)
return GDALTPSTransform(hTransformArg, FALSE, nCount, x, y, z,
return GDALTPSTransform(hTransformArg, FALSE,
static_cast<int>(nCount), x, y, z,
pabSuccess);
else
return GDALGCPTransform(hTransformArg, FALSE, nCount, x, y, z,
return GDALGCPTransform(hTransformArg, FALSE,
static_cast<int>(nCount), x, y, z,
pabSuccess);
}

Expand Down Expand Up @@ -1214,7 +1219,7 @@ class CompositeCT : public OGRCoordinateTransformation
poCT2->SetEmitErrors(bEmitErrors);
}

virtual int Transform(int nCount, double *x, double *y, double *z,
virtual int Transform(size_t nCount, double *x, double *y, double *z,
double *t, int *pabSuccess) override
{
int nResult = TRUE;
Expand Down Expand Up @@ -1280,10 +1285,10 @@ class AxisMappingCoordinateTransformation : public OGRCoordinateTransformation
return nullptr;
}

virtual int Transform(int nCount, double *x, double *y, double * /*z*/,
virtual int Transform(size_t nCount, double *x, double *y, double * /*z*/,
double * /*t*/, int *pabSuccess) override
{
for (int i = 0; i < nCount; i++)
for (size_t i = 0; i < nCount; i++)
{
if (pabSuccess)
pabSuccess[i] = true;
Expand Down
4 changes: 2 additions & 2 deletions frmts/vrt/vrtwarped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,10 @@ class GDALWarpCoordRescaler : public OGRCoordinateTransformation
return nullptr;
}

virtual int Transform(int nCount, double *x, double *y, double * /*z*/,
virtual int Transform(size_t nCount, double *x, double *y, double * /*z*/,
double * /*t*/, int *pabSuccess) override
{
for (int i = 0; i < nCount; i++)
for (size_t i = 0; i < nCount; i++)
{
x[i] *= m_dfRatioX;
y[i] *= m_dfRatioY;
Expand Down
15 changes: 9 additions & 6 deletions ogr/ogr_spatialref.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,8 @@ class CPL_DLL OGRCoordinateTransformation
*
* This method is the same as the C function OCTTransformEx().
*
* @param nCount number of points to transform.
* @param nCount number of points to transform (`size_t` type since 3.9,
* `int` in previous versions).
* @param x array of nCount X vertices, modified in place. Should not be
* NULL.
* @param y array of nCount Y vertices, modified in place. Should not be
Expand All @@ -814,15 +815,16 @@ class CPL_DLL OGRCoordinateTransformation
* @return TRUE if some or all points transform successfully, or FALSE if
* if none transform.
*/
int Transform(int nCount, double *x, double *y, double *z = nullptr,
int Transform(size_t nCount, double *x, double *y, double *z = nullptr,
int *pabSuccess = nullptr);

/**
* Transform points from source to destination space.
*
* This method is the same as the C function OCTTransform4D().
*
* @param nCount number of points to transform.
* @param nCount number of points to transform (`size_t` type since 3.9,
* `int` in previous versions).
* @param x array of nCount X vertices, modified in place. Should not be
* NULL.
* @param y array of nCount Y vertices, modified in place. Should not be
Expand All @@ -835,15 +837,16 @@ class CPL_DLL OGRCoordinateTransformation
* @return TRUE if some or all points transform successfully, or FALSE if
* if none transform.
*/
virtual int Transform(int nCount, double *x, double *y, double *z,
virtual int Transform(size_t nCount, double *x, double *y, double *z,
double *t, int *pabSuccess) = 0;

/**
* Transform points from source to destination space.
*
* This method is the same as the C function OCTTransform4DWithErrorCodes().
*
* @param nCount number of points to transform.
* @param nCount number of points to transform (`size_t` type since 3.9,
* `int` in previous versions).
* @param x array of nCount X vertices, modified in place. Should not be
* NULL.
* @param y array of nCount Y vertices, modified in place. Should not be
Expand All @@ -857,7 +860,7 @@ class CPL_DLL OGRCoordinateTransformation
* if none transform.
* @since GDAL 3.3, and PROJ 8 to be able to use PROJ public error codes
*/
virtual int TransformWithErrorCodes(int nCount, double *x, double *y,
virtual int TransformWithErrorCodes(size_t nCount, double *x, double *y,
double *z, double *t,
int *panErrorCodes);

Expand Down
Loading

0 comments on commit 7dc586b

Please sign in to comment.