PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ptarray_to_GEOSCoordSeq()

GEOSCoordSeq ptarray_to_GEOSCoordSeq ( const POINTARRAY pa,
uint8_t  fix_ring 
)

Definition at line 280 of file liblwgeom/lwgeom_geos.c.

281 {
282  uint32_t dims = 2;
283  uint32_t i;
284  int append_points = 0;
285  const POINT3D *p3d = NULL;
286  const POINT2D* p2d = NULL;
287  GEOSCoordSeq sq;
288 
289  if (FLAGS_GET_Z(pa->flags)) dims = 3;
290 
291  if (fix_ring)
292  {
293  if (pa->npoints < 1)
294  {
295  lwerror("ptarray_to_GEOSCoordSeq called with fix_ring and 0 vertices in ring, cannot fix");
296  return NULL;
297  }
298  else
299  {
300  if (pa->npoints < 4) append_points = 4 - pa->npoints;
301  if (!ptarray_is_closed_2d(pa) && append_points == 0) append_points = 1;
302  }
303  }
304 
305 #if POSTGIS_GEOS_VERSION >= 31000
306  if (append_points == 0) {
307  sq = GEOSCoordSeq_copyFromBuffer((const double*) pa->serialized_pointlist, pa->npoints, FLAGS_GET_Z(pa->flags), FLAGS_GET_M(pa->flags));
308  if (!sq)
309  {
310  GEOS_FAIL();
311  }
312  return sq;
313  }
314 #endif
315  if (!(sq = GEOSCoordSeq_create(pa->npoints + append_points, dims)))
316  {
317  GEOS_FAIL();
318  }
319 
320  for (i = 0; i < pa->npoints; i++)
321  {
322  if (dims == 3)
323  {
324  p3d = getPoint3d_cp(pa, i);
325  p2d = (const POINT2D*)p3d;
326  LWDEBUGF(4, "Point: %g,%g,%g", p3d->x, p3d->y, p3d->z);
327  }
328  else
329  {
330  p2d = getPoint2d_cp(pa, i);
331  LWDEBUGF(4, "Point: %g,%g", p2d->x, p2d->y);
332  }
333 
334 #if POSTGIS_GEOS_VERSION < 30800
335  GEOSCoordSeq_setX(sq, i, p2d->x);
336  GEOSCoordSeq_setY(sq, i, p2d->y);
337  if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->z);
338 #else
339  if (dims == 3)
340  GEOSCoordSeq_setXYZ(sq, i, p2d->x, p2d->y, p3d->z);
341  else
342  GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
343 #endif
344 
345  }
346 
347  if (append_points)
348  {
349  if (dims == 3)
350  {
351  p3d = getPoint3d_cp(pa, 0);
352  p2d = (const POINT2D*)p3d;
353  }
354  else
355  p2d = getPoint2d_cp(pa, 0);
356  for (i = pa->npoints; i < pa->npoints + append_points; i++)
357  {
358 #if POSTGIS_GEOS_VERSION < 30800
359  GEOSCoordSeq_setX(sq, i, p2d->x);
360  GEOSCoordSeq_setY(sq, i, p2d->y);
361 #else
362  GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
363 #endif
364 
365  if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->z);
366  }
367  }
368 
369  return sq;
370 
371 }
#define GEOS_FAIL()
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:165
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:166
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:714
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:101
static const POINT3D * getPoint3d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT3D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:113
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
double z
Definition: liblwgeom.h:402
double x
Definition: liblwgeom.h:402
double y
Definition: liblwgeom.h:402
lwflags_t flags
Definition: liblwgeom.h:431
uint32_t npoints
Definition: liblwgeom.h:427
uint8_t * serialized_pointlist
Definition: liblwgeom.h:434

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, GEOS_FAIL, getPoint2d_cp(), getPoint3d_cp(), LWDEBUGF, lwerror(), POINTARRAY::npoints, ptarray_is_closed_2d(), POINTARRAY::serialized_pointlist, POINT2D::x, POINT3D::x, POINT2D::y, POINT3D::y, and POINT3D::z.

Referenced by LWGEOM2GEOS(), and ptarray_to_GEOSLinearRing().

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