PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ptarray_transform()

int ptarray_transform ( POINTARRAY pa,
LWPROJ pj 
)

Definition at line 257 of file liblwgeom/lwgeom_transform.c.

258 {
259  uint32_t i;
260  POINT4D p;
261  size_t n_converted;
262  size_t n_points = pa->npoints;
263  size_t point_size = ptarray_point_size(pa);
264  int has_z = ptarray_has_z(pa);
265  double *pa_double = (double*)(pa->serialized_pointlist);
266 
267  /* Convert to radians if necessary */
268  if (proj_angular_input(pj->pj, PJ_FWD))
269  {
270  for (i = 0; i < pa->npoints; i++)
271  {
272  getPoint4d_p(pa, i, &p);
273  to_rad(&p);
274  }
275  }
276 
277  if (n_points == 1)
278  {
279  /* For single points it's faster to call proj_trans */
280  PJ_XYZT v = {pa_double[0], pa_double[1], has_z ? pa_double[2] : 0.0, 0.0};
281  PJ_COORD c;
282  c.xyzt = v;
283  PJ_COORD t = proj_trans(pj->pj, PJ_FWD, c);
284 
285  int pj_errno_val = proj_errno_reset(pj->pj);
286  if (pj_errno_val)
287  {
288  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
289  return LW_FAILURE;
290  }
291  pa_double[0] = (t.xyzt).x;
292  pa_double[1] = (t.xyzt).y;
293  if (has_z)
294  pa_double[2] = (t.xyzt).z;
295  }
296  else
297  {
298  /*
299  * size_t proj_trans_generic(PJ *P, PJ_DIRECTION direction,
300  * double *x, size_t sx, size_t nx,
301  * double *y, size_t sy, size_t ny,
302  * double *z, size_t sz, size_t nz,
303  * double *t, size_t st, size_t nt)
304  */
305 
306  n_converted = proj_trans_generic(pj->pj,
307  PJ_FWD,
308  pa_double,
309  point_size,
310  n_points, /* X */
311  pa_double + 1,
312  point_size,
313  n_points, /* Y */
314  has_z ? pa_double + 2 : NULL,
315  has_z ? point_size : 0,
316  has_z ? n_points : 0, /* Z */
317  NULL,
318  0,
319  0 /* M */
320  );
321 
322  if (n_converted != n_points)
323  {
324  lwerror("ptarray_transform: converted (%d) != input (%d)", n_converted, n_points);
325  return LW_FAILURE;
326  }
327 
328  int pj_errno_val = proj_errno_reset(pj->pj);
329  if (pj_errno_val)
330  {
331  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
332  return LW_FAILURE;
333  }
334  }
335 
336  /* Convert radians to degrees if necessary */
337  if (proj_angular_output(pj->pj, PJ_FWD))
338  {
339  for (i = 0; i < pa->npoints; i++)
340  {
341  getPoint4d_p(pa, i, &p);
342  to_dec(&p);
343  }
344  }
345 
346  return LW_SUCCESS;
347 }
static void to_rad(POINT4D *pt)
convert decimal degress to radians
static void to_dec(POINT4D *pt)
convert radians to decimal degress
#define LW_FAILURE
Definition: liblwgeom.h:111
#define LW_SUCCESS
Definition: liblwgeom.h:112
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:126
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:37
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static size_t ptarray_point_size(const POINTARRAY *pa)
Definition: lwinline.h:58
PJ * pj
Definition: liblwgeom.h:61
uint32_t npoints
Definition: liblwgeom.h:442
uint8_t * serialized_pointlist
Definition: liblwgeom.h:449

References getPoint4d_p(), LW_FAILURE, LW_SUCCESS, lwerror(), POINTARRAY::npoints, LWPROJ::pj, ptarray_has_z(), ptarray_point_size(), POINTARRAY::serialized_pointlist, to_dec(), to_rad(), pixval::x, and pixval::y.

Referenced by gml_reproject_pa(), and lwgeom_transform().

Here is the call graph for this function:
Here is the caller graph for this function: