PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ ptarray_to_GEOSCoordSeq()

GEOSCoordSeq ptarray_to_GEOSCoordSeq ( const POINTARRAY pa,
uint8_t  fix_ring 
)

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

276{
277 uint32_t dims = 2;
278 uint32_t i;
279 int append_points = 0;
280 const POINT3D *p3d = NULL;
281 const POINT2D* p2d = NULL;
282 GEOSCoordSeq sq;
283
284 if (FLAGS_GET_Z(pa->flags)) dims = 3;
285
286 if (fix_ring)
287 {
288 if (pa->npoints < 1)
289 {
290 lwerror("ptarray_to_GEOSCoordSeq called with fix_ring and 0 vertices in ring, cannot fix");
291 return NULL;
292 }
293 else
294 {
295 if (pa->npoints < 4) append_points = 4 - pa->npoints;
296 if (!ptarray_is_closed_2d(pa) && append_points == 0) append_points = 1;
297 }
298 }
299
300#if POSTGIS_GEOS_VERSION >= 31000
301 if (append_points == 0) {
302 sq = GEOSCoordSeq_copyFromBuffer((const double*) pa->serialized_pointlist, pa->npoints, FLAGS_GET_Z(pa->flags), FLAGS_GET_M(pa->flags));
303 if (!sq)
304 {
305 GEOS_FAIL();
306 }
307 return sq;
308 }
309#endif
310 if (!(sq = GEOSCoordSeq_create(pa->npoints + append_points, dims)))
311 {
312 GEOS_FAIL();
313 }
314
315 for (i = 0; i < pa->npoints; i++)
316 {
317 if (dims == 3)
318 {
319 p3d = getPoint3d_cp(pa, i);
320 p2d = (const POINT2D*)p3d;
321 LWDEBUGF(4, "Point: %g,%g,%g", p3d->x, p3d->y, p3d->z);
322 }
323 else
324 {
325 p2d = getPoint2d_cp(pa, i);
326 LWDEBUGF(4, "Point: %g,%g", p2d->x, p2d->y);
327 }
328
329 if (dims == 3)
330 GEOSCoordSeq_setXYZ(sq, i, p2d->x, p2d->y, p3d->z);
331 else
332 GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
333
334 }
335
336 if (append_points)
337 {
338 if (dims == 3)
339 {
340 p3d = getPoint3d_cp(pa, 0);
341 p2d = (const POINT2D*)p3d;
342 }
343 else
344 p2d = getPoint2d_cp(pa, 0);
345 for (i = pa->npoints; i < pa->npoints + append_points; i++)
346 {
347
348 GEOSCoordSeq_setXY(sq, i, p2d->x, p2d->y);
349
350 if (dims == 3) GEOSCoordSeq_setZ(sq, i, p3d->z);
351 }
352 }
353
354 return sq;
355
356}
#define GEOS_FAIL()
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition ptarray.c:710
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
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:109
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:97
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390
double z
Definition liblwgeom.h:402
double x
Definition liblwgeom.h:402
double y
Definition liblwgeom.h:402
lwflags_t flags
Definition liblwgeom.h:431
uint32_t npoints
Definition liblwgeom.h:427
uint8_t * serialized_pointlist
Definition liblwgeom.h:434

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