PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ptarray_to_GEOSCoordSeq()

GEOSCoordSeq ptarray_to_GEOSCoordSeq ( const POINTARRAY pa,
uint8_t  fix_ring 
)

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

257 {
258  uint32_t dims = 2;
259  uint32_t i;
260  int append_points = 0;
261  const POINT3D *p3d = NULL;
262  const POINT2D* p2d = NULL;
263  GEOSCoordSeq sq;
264 
265  if (FLAGS_GET_Z(pa->flags)) dims = 3;
266 
267  if (fix_ring)
268  {
269  if (pa->npoints < 1)
270  {
271  lwerror("ptarray_to_GEOSCoordSeq called with fix_ring and 0 vertices in ring, cannot fix");
272  return NULL;
273  }
274  else
275  {
276  if (pa->npoints < 4) append_points = 4 - pa->npoints;
277  if (!ptarray_is_closed_2d(pa) && append_points == 0) append_points = 1;
278  }
279  }
280 
281 #if POSTGIS_GEOS_VERSION >= 31000
282  if (append_points == 0) {
283  sq = GEOSCoordSeq_copyFromBuffer((const double*) pa->serialized_pointlist, pa->npoints, FLAGS_GET_Z(pa->flags), FLAGS_GET_M(pa->flags));
284  if (!sq)
285  {
286  lwerror("Error creating GEOS Coordinate Sequence");
287  return NULL;
288  }
289  return sq;
290  }
291 #endif
292  if (!(sq = GEOSCoordSeq_create(pa->npoints + append_points, dims)))
293  {
294  lwerror("Error creating GEOS Coordinate Sequence");
295  return NULL;
296  }
297 
298  for (i = 0; i < pa->npoints; i++)
299  {
300  if (dims == 3)
301  {
302  p3d = getPoint3d_cp(pa, i);
303  p2d = (const POINT2D*)p3d;
304  LWDEBUGF(4, "Point: %g,%g,%g", p3d->x, p3d->y, p3d->z);
305  }
306  else
307  {
308  p2d = getPoint2d_cp(pa, i);
309  LWDEBUGF(4, "Point: %g,%g", p2d->x, p2d->y);
310  }
311 
312 #if POSTGIS_GEOS_VERSION < 30800
313  GEOSCoordSeq_setX(sq, i, p2d->x);
314  GEOSCoordSeq_setY(sq, i, p2d->y);
315  if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->z);
316 #else
317  if (dims == 3)
318  GEOSCoordSeq_setXYZ(sq, i, p2d->x, p2d->y, p3d->z);
319  else
320  GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
321 #endif
322 
323  }
324 
325  if (append_points)
326  {
327  if (dims == 3)
328  {
329  p3d = getPoint3d_cp(pa, 0);
330  p2d = (const POINT2D*)p3d;
331  }
332  else
333  p2d = getPoint2d_cp(pa, 0);
334  for (i = pa->npoints; i < pa->npoints + append_points; i++)
335  {
336 #if POSTGIS_GEOS_VERSION < 30800
337  GEOSCoordSeq_setX(sq, i, p2d->x);
338  GEOSCoordSeq_setY(sq, i, p2d->y);
339 #else
340  GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
341 #endif
342 
343  if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->z);
344  }
345  }
346 
347  return sq;
348 
349 }
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:180
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:181
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:701
#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:405
double x
Definition: liblwgeom.h:405
double z
Definition: liblwgeom.h:417
double x
Definition: liblwgeom.h:417
double y
Definition: liblwgeom.h:417
lwflags_t flags
Definition: liblwgeom.h:446
uint32_t npoints
Definition: liblwgeom.h:442
uint8_t * serialized_pointlist
Definition: liblwgeom.h:449

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, 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: