PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ptarray_to_GEOSCoordSeq()

GEOSCoordSeq ptarray_to_GEOSCoordSeq ( const POINTARRAY pa,
int  fix_ring 
)

Definition at line 215 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 GEOS2LWGEOM(), LWGEOM2GEOS(), and ptarray_to_GEOSLinearRing().

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