PostGIS  2.5.0dev-r@@SVN_REVISION@@
GEOSCoordSeq ptarray_to_GEOSCoordSeq ( const POINTARRAY pa,
int  fix_ring 
)

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

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().

214 {
215  uint32_t dims = 2;
216  uint32_t i;
217  int append_points = 0;
218  const POINT3DZ *p3d;
219  const POINT2D *p2d;
220  GEOSCoordSeq sq;
221 
222  if ( FLAGS_GET_Z(pa->flags) )
223  dims = 3;
224 
225  if ( fix_ring )
226  {
227  if (pa->npoints < 1)
228  {
229  lwerror("ptarray_to_GEOSCoordSeq called with fix_ring and 0 vertices in ring, cannot fix");
230  return NULL;
231  }
232  else
233  {
234  if ( pa->npoints < 4 )
235  {
236  append_points = 4 - pa->npoints;
237  }
238  if ( ! ptarray_is_closed_2d(pa) && append_points == 0 )
239  {
240  append_points = 1;
241  }
242  }
243  }
244 
245  if ( ! (sq = GEOSCoordSeq_create(pa->npoints + append_points, dims)) )
246  {
247  lwerror("Error creating GEOS Coordinate Sequence");
248  return NULL;
249  }
250 
251  for ( i=0; i < pa->npoints; i++ )
252  {
253  if ( dims == 3 )
254  {
255  p3d = getPoint3dz_cp(pa, i);
256  p2d = (const POINT2D *)p3d;
257  LWDEBUGF(4, "Point: %g,%g,%g", p3d->x, p3d->y, p3d->z);
258  }
259  else
260  {
261  p2d = getPoint2d_cp(pa, i);
262  LWDEBUGF(4, "Point: %g,%g", p2d->x, p2d->y);
263  }
264 
265  GEOSCoordSeq_setX(sq, i, p2d->x);
266  GEOSCoordSeq_setY(sq, i, p2d->y);
267 
268  if ( dims == 3 )
269  {
270  GEOSCoordSeq_setZ(sq, i, p3d->z);
271  }
272  }
273 
274  if ( append_points )
275  {
276  if ( dims == 3 )
277  {
278  p3d = getPoint3dz_cp(pa, 0);
279  p2d = (const POINT2D *)p3d;
280  }
281  else
282  {
283  p2d = getPoint2d_cp(pa, 0);
284  }
285  for ( i = pa->npoints; i < pa->npoints + append_points; i++ )
286  {
287  GEOSCoordSeq_setX(sq, i, p2d->x);
288  GEOSCoordSeq_setY(sq, i, p2d->y);
289 
290  if ( dims == 3 )
291  {
292  GEOSCoordSeq_setZ(sq, i, p3d->z);
293  }
294  }
295  }
296 
297  return sq;
298 }
double z
Definition: liblwgeom.h:333
double y
Definition: liblwgeom.h:333
double x
Definition: liblwgeom.h:333
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:688
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:327
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:378
uint8_t flags
Definition: liblwgeom.h:368
double y
Definition: liblwgeom.h:327
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
#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
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:364
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: