PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ptarray_transform()

int ptarray_transform ( POINTARRAY pa,
LWPROJ pj 
)

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

231 {
232  uint32_t i;
233  POINT4D p;
234  size_t n_converted;
235  size_t n_points = pa->npoints;
236  size_t point_size = ptarray_point_size(pa);
237  int has_z = ptarray_has_z(pa);
238  double *pa_double = (double*)(pa->serialized_pointlist);
239 
240  PJ_DIRECTION direction = pj->pipeline_is_forward ? PJ_FWD : PJ_INV;
241 
242  /* Convert to radians if necessary */
243  if (proj_angular_input(pj->pj, direction))
244  {
245  for (i = 0; i < pa->npoints; i++)
246  {
247  getPoint4d_p(pa, i, &p);
248  to_rad(&p);
249  ptarray_set_point4d(pa, i, &p);
250  }
251  }
252 
253  if (n_points == 1)
254  {
255  /* For single points it's faster to call proj_trans */
256  PJ_XYZT v = {pa_double[0], pa_double[1], has_z ? pa_double[2] : 0.0, 0.0};
257  PJ_COORD c;
258  c.xyzt = v;
259  PJ_COORD t = proj_trans(pj->pj, direction, c);
260 
261  int pj_errno_val = proj_errno_reset(pj->pj);
262  if (pj_errno_val)
263  {
264  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
265  return LW_FAILURE;
266  }
267  pa_double[0] = (t.xyzt).x;
268  pa_double[1] = (t.xyzt).y;
269  if (has_z)
270  pa_double[2] = (t.xyzt).z;
271  }
272  else
273  {
274  /*
275  * size_t proj_trans_generic(PJ *P, PJ_DIRECTION direction,
276  * double *x, size_t sx, size_t nx,
277  * double *y, size_t sy, size_t ny,
278  * double *z, size_t sz, size_t nz,
279  * double *t, size_t st, size_t nt)
280  */
281 
282  n_converted = proj_trans_generic(pj->pj,
283  direction,
284  pa_double,
285  point_size,
286  n_points, /* X */
287  pa_double + 1,
288  point_size,
289  n_points, /* Y */
290  has_z ? pa_double + 2 : NULL,
291  has_z ? point_size : 0,
292  has_z ? n_points : 0, /* Z */
293  NULL,
294  0,
295  0 /* M */
296  );
297 
298  if (n_converted != n_points)
299  {
300  lwerror("ptarray_transform: converted (%d) != input (%d)", n_converted, n_points);
301  return LW_FAILURE;
302  }
303 
304  int pj_errno_val = proj_errno_reset(pj->pj);
305  if (pj_errno_val)
306  {
307  lwerror("transform: %s (%d)", proj_errno_string(pj_errno_val), pj_errno_val);
308  return LW_FAILURE;
309  }
310  }
311 
312  /* Convert radians to degrees if necessary */
313  if (proj_angular_output(pj->pj, direction))
314  {
315  for (i = 0; i < pa->npoints; i++)
316  {
317  getPoint4d_p(pa, i, &p);
318  to_dec(&p);
319  ptarray_set_point4d(pa, i, &p);
320  }
321  }
322 
323  return LW_SUCCESS;
324 }
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:96
#define LW_SUCCESS
Definition: liblwgeom.h:97
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:369
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
bool pipeline_is_forward
Definition: liblwgeom.h:49
PJ * pj
Definition: liblwgeom.h:46
uint32_t npoints
Definition: liblwgeom.h:427
uint8_t * serialized_pointlist
Definition: liblwgeom.h:434

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

Referenced by box3d_transform(), gml_reproject_pa(), and lwgeom_transform().

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