PostGIS  2.2.7dev-r@@SVN_REVISION@@
GEOSCoordSeq ptarray_to_GEOSCoordSeq ( const POINTARRAY pa)

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

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

Referenced by LWGEOM2GEOS(), and ptarray_to_GEOSLinearRing().

203 {
204  uint32_t dims = 2;
205  uint32_t i;
206  const POINT3DZ *p3d;
207  const POINT2D *p2d;
208  GEOSCoordSeq sq;
209 
210  if ( FLAGS_GET_Z(pa->flags) )
211  dims = 3;
212 
213  if ( ! (sq = GEOSCoordSeq_create(pa->npoints, dims)) )
214  lwerror("Error creating GEOS Coordinate Sequence");
215 
216  for ( i=0; i < pa->npoints; i++ )
217  {
218  if ( dims == 3 )
219  {
220  p3d = getPoint3dz_cp(pa, i);
221  p2d = (const POINT2D *)p3d;
222  LWDEBUGF(4, "Point: %g,%g,%g", p3d->x, p3d->y, p3d->z);
223  }
224  else
225  {
226  p2d = getPoint2d_cp(pa, i);
227  LWDEBUGF(4, "Point: %g,%g", p2d->x, p2d->y);
228  }
229 
230 #if POSTGIS_GEOS_VERSION < 33
231  /* Make sure we don't pass any infinite values down into GEOS */
232  /* GEOS 3.3+ is supposed to handle this stuff OK */
233  if ( isinf(p2d->x) || isinf(p2d->y) || (dims == 3 && isinf(p3d->z)) )
234  lwerror("Infinite coordinate value found in geometry.");
235  if ( isnan(p2d->x) || isnan(p2d->y) || (dims == 3 && isnan(p3d->z)) )
236  lwerror("NaN coordinate value found in geometry.");
237 #endif
238 
239  GEOSCoordSeq_setX(sq, i, p2d->x);
240  GEOSCoordSeq_setY(sq, i, p2d->y);
241 
242  if ( dims == 3 )
243  GEOSCoordSeq_setZ(sq, i, p3d->z);
244  }
245  return sq;
246 }
double z
Definition: liblwgeom.h:318
double y
Definition: liblwgeom.h:318
double x
Definition: liblwgeom.h:318
int npoints
Definition: liblwgeom.h:355
double x
Definition: liblwgeom.h:312
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:472
uint8_t flags
Definition: liblwgeom.h:353
double y
Definition: liblwgeom.h:312
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, int n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:486
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74

Here is the call graph for this function:

Here is the caller graph for this function: