PostGIS  3.0.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 t = proj_trans(pj->pj, PJ_FWD, (PJ_COORD)v);
523 
524  int pj_errno_val = proj_errno(pj->pj);
525  if (pj_errno_val)
526  {
527  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
528  return LW_FAILURE;
529  }
530  pa_double[0] = ((PJ_XYZT)t.xyzt).x;
531  pa_double[1] = ((PJ_XYZT)t.xyzt).y;
532  if (has_z)
533  pa_double[2] = ((PJ_XYZT)t.xyzt).z;
534  }
535  else
536  {
537  /*
538  * size_t proj_trans_generic(PJ *P, PJ_DIRECTION direction,
539  * double *x, size_t sx, size_t nx,
540  * double *y, size_t sy, size_t ny,
541  * double *z, size_t sz, size_t nz,
542  * double *t, size_t st, size_t nt)
543  */
544 
545  n_converted = proj_trans_generic(pj->pj,
546  PJ_FWD,
547  pa_double,
548  point_size,
549  n_points, /* X */
550  pa_double + 1,
551  point_size,
552  n_points, /* Y */
553  has_z ? pa_double + 2 : NULL,
554  has_z ? point_size : 0,
555  has_z ? n_points : 0, /* Z */
556  NULL,
557  0,
558  0 /* M */
559  );
560 
561  if (n_converted != n_points)
562  {
563  lwerror("ptarray_transform: converted (%d) != input (%d)", n_converted, n_points);
564  return LW_FAILURE;
565  }
566 
567  int pj_errno_val = proj_errno(pj->pj);
568  if (pj_errno_val)
569  {
570  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
571  return LW_FAILURE;
572  }
573  }
574 
575  if (pj->target_swapped)
577 
578  /* Convert radians to degrees if necessary */
579  if (proj_angular_output(pj->pj, PJ_FWD))
580  {
581  for (i = 0; i < pa->npoints; i++)
582  {
583  getPoint4d_p(pa, i, &p);
584  to_dec(&p);
585  }
586  }
587 
588  return LW_SUCCESS;
589 }
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:125
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:379
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:48
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:413
uint8_t * serialized_pointlist
Definition: liblwgeom.h:420

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(), and to_rad().

Referenced by gml_reproject_pa(), and lwgeom_transform().

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