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

◆ 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 POINT3D *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 = getPoint3d_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 = getPoint3d_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}
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:179
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition ptarray.c:701
#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
static const POINT3D * getPoint3d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition lwinline.h:103
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:91
double y
Definition liblwgeom.h:376
double x
Definition liblwgeom.h:376
double z
Definition liblwgeom.h:388
double x
Definition liblwgeom.h:388
double y
Definition liblwgeom.h:388
lwflags_t flags
Definition liblwgeom.h:417
uint32_t npoints
Definition liblwgeom.h:413

References POINTARRAY::flags, FLAGS_GET_Z, getPoint2d_cp(), getPoint3d_cp(), LWDEBUGF, lwerror(), POINTARRAY::npoints, ptarray_is_closed_2d(), 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: