PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ ptarray_transform()

int ptarray_transform ( POINTARRAY pa,
LWPROJ pj 
)

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

496 {
497  uint32_t i;
498  POINT4D p;
499  size_t n_converted;
500  size_t n_points = pa->npoints;
501  size_t point_size = ptarray_point_size(pa);
502  int has_z = ptarray_has_z(pa);
503  double *pa_double = (double*)(pa->serialized_pointlist);
504 
505  /* Convert to radians if necessary */
506  if (proj_angular_input(pj->pj, PJ_FWD))
507  {
508  for (i = 0; i < pa->npoints; i++)
509  {
510  getPoint4d_p(pa, i, &p);
511  to_rad(&p);
512  }
513  }
514 
515  if (pj->source_swapped)
517 
518  if (n_points == 1)
519  {
520  /* For single points it's faster to call proj_trans */
521  PJ_XYZT v = {pa_double[0], pa_double[1], has_z ? pa_double[2] : 0.0, 0.0};
522  PJ_COORD c;
523  c.xyzt = v;
524  PJ_COORD t = proj_trans(pj->pj, PJ_FWD, c);
525 
526  int pj_errno_val = proj_errno_reset(pj->pj);
527  if (pj_errno_val)
528  {
529  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
530  return LW_FAILURE;
531  }
532  pa_double[0] = (t.xyzt).x;
533  pa_double[1] = (t.xyzt).y;
534  if (has_z)
535  pa_double[2] = (t.xyzt).z;
536  }
537  else
538  {
539  /*
540  * size_t proj_trans_generic(PJ *P, PJ_DIRECTION direction,
541  * double *x, size_t sx, size_t nx,
542  * double *y, size_t sy, size_t ny,
543  * double *z, size_t sz, size_t nz,
544  * double *t, size_t st, size_t nt)
545  */
546 
547  n_converted = proj_trans_generic(pj->pj,
548  PJ_FWD,
549  pa_double,
550  point_size,
551  n_points, /* X */
552  pa_double + 1,
553  point_size,
554  n_points, /* Y */
555  has_z ? pa_double + 2 : NULL,
556  has_z ? point_size : 0,
557  has_z ? n_points : 0, /* Z */
558  NULL,
559  0,
560  0 /* M */
561  );
562 
563  if (n_converted != n_points)
564  {
565  lwerror("ptarray_transform: converted (%d) != input (%d)", n_converted, n_points);
566  return LW_FAILURE;
567  }
568 
569  int pj_errno_val = proj_errno_reset(pj->pj);
570  if (pj_errno_val)
571  {
572  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
573  return LW_FAILURE;
574  }
575  }
576 
577  if (pj->target_swapped)
579 
580  /* Convert radians to degrees if necessary */
581  if (proj_angular_output(pj->pj, PJ_FWD))
582  {
583  for (i = 0; i < pa->npoints; i++)
584  {
585  getPoint4d_p(pa, i, &p);
586  to_dec(&p);
587  }
588  }
589 
590  return LW_SUCCESS;
591 }
static void to_rad(POINT4D *pt)
convert decimal degress to radians
static void to_dec(POINT4D *pt)
convert radians to decimal degress
@ LWORD_Y
Definition: liblwgeom.h:146
@ LWORD_X
Definition: liblwgeom.h:145
#define LW_FAILURE
Definition: liblwgeom.h:110
#define LW_SUCCESS
Definition: liblwgeom.h:111
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 ptarray_swap_ordinates(POINTARRAY *pa, LWORD o1, LWORD o2)
Swap ordinate values o1 and o2 on a given POINTARRAY.
Definition: ptarray.c:387
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
uint8_t source_swapped
Definition: liblwgeom.h:58
uint8_t target_swapped
Definition: liblwgeom.h:59
PJ * pj
Definition: liblwgeom.h:56
uint32_t npoints
Definition: liblwgeom.h:441
uint8_t * serialized_pointlist
Definition: liblwgeom.h:448

References getPoint4d_p(), LW_FAILURE, LW_SUCCESS, lwerror(), LWORD_X, LWORD_Y, POINTARRAY::npoints, LWPROJ::pj, ptarray_has_z(), ptarray_point_size(), ptarray_swap_ordinates(), POINTARRAY::serialized_pointlist, LWPROJ::source_swapped, LWPROJ::target_swapped, 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: