PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ptarray_to_GEOSCoordSeq()

GEOSCoordSeq ptarray_to_GEOSCoordSeq ( const POINTARRAY pa,
uint8_t  fix_ring 
)

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

249 {
250  uint32_t dims = 2;
251  uint32_t i;
252  int append_points = 0;
253  const POINT3DZ* p3d = NULL;
254  const POINT2D* p2d = NULL;
255  GEOSCoordSeq sq;
256 
257  if (FLAGS_GET_Z(pa->flags)) dims = 3;
258 
259  if (fix_ring)
260  {
261  if (pa->npoints < 1)
262  {
263  lwerror("ptarray_to_GEOSCoordSeq called with fix_ring and 0 vertices in ring, cannot fix");
264  return NULL;
265  }
266  else
267  {
268  if (pa->npoints < 4) append_points = 4 - pa->npoints;
269  if (!ptarray_is_closed_2d(pa) && append_points == 0) append_points = 1;
270  }
271  }
272 
273  if (!(sq = GEOSCoordSeq_create(pa->npoints + append_points, dims)))
274  {
275  lwerror("Error creating GEOS Coordinate Sequence");
276  return NULL;
277  }
278 
279  for (i = 0; i < pa->npoints; i++)
280  {
281  if (dims == 3)
282  {
283  p3d = getPoint3dz_cp(pa, i);
284  p2d = (const POINT2D*)p3d;
285  LWDEBUGF(4, "Point: %g,%g,%g", p3d->x, p3d->y, p3d->z);
286  }
287  else
288  {
289  p2d = getPoint2d_cp(pa, i);
290  LWDEBUGF(4, "Point: %g,%g", p2d->x, p2d->y);
291  }
292 
293 #if POSTGIS_GEOS_VERSION < 38
294  GEOSCoordSeq_setX(sq, i, p2d->x);
295  GEOSCoordSeq_setY(sq, i, p2d->y);
296  if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->z);
297 #else
298  if (dims == 3)
299  GEOSCoordSeq_setXYZ(sq, i, p2d->x, p2d->y, p3d->z);
300  else
301  GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
302 #endif
303 
304  }
305 
306  if (append_points)
307  {
308  if (dims == 3)
309  {
310  p3d = getPoint3dz_cp(pa, 0);
311  p2d = (const POINT2D*)p3d;
312  }
313  else
314  p2d = getPoint2d_cp(pa, 0);
315  for (i = pa->npoints; i < pa->npoints + append_points; i++)
316  {
317 #if POSTGIS_GEOS_VERSION < 38
318  GEOSCoordSeq_setX(sq, i, p2d->x);
319  GEOSCoordSeq_setY(sq, i, p2d->y);
320 #else
321  GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
322 #endif
323 
324  if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->z);
325  }
326  }
327 
328  return sq;
329 }
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwgeom_api.c:388
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:695
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwgeom_api.c:374
#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
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
double z
Definition: liblwgeom.h:337
double x
Definition: liblwgeom.h:337
double y
Definition: liblwgeom.h:337
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372
unsigned int uint32_t
Definition: uthash.h:78

References POINTARRAY::flags, FLAGS_GET_Z, getPoint2d_cp(), getPoint3dz_cp(), LWDEBUGF, lwerror(), POINTARRAY::npoints, ptarray_is_closed_2d(), POINT2D::x, POINT3DZ::x, POINT2D::y, POINT3DZ::y, and POINT3DZ::z.

Referenced by LWGEOM2GEOS(), and ptarray_to_GEOSLinearRing().

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