PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ptarray_from_GEOSCoordSeq()

POINTARRAY* ptarray_from_GEOSCoordSeq ( const GEOSCoordSequence *  cs,
uint8_t  want3d 
)

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

120 {
121  uint32_t dims = 2;
122  uint32_t size = 0, i;
123  POINTARRAY* pa;
124  POINT4D point = { 0.0, 0.0, 0.0, 0.0 };
125 
126  LWDEBUG(2, "ptarray_fromGEOSCoordSeq called");
127 
128  if (!GEOSCoordSeq_getSize(cs, &size)) lwerror("Exception thrown");
129 
130  LWDEBUGF(4, " GEOSCoordSeq size: %d", size);
131 
132  if (want3d)
133  {
134  if (!GEOSCoordSeq_getDimensions(cs, &dims)) lwerror("Exception thrown");
135 
136  LWDEBUGF(4, " GEOSCoordSeq dimensions: %d", dims);
137 
138  /* forget higher dimensions (if any) */
139  if (dims > 3) dims = 3;
140  }
141 
142  LWDEBUGF(4, " output dimensions: %d", dims);
143 
144  pa = ptarray_construct((dims == 3), 0, size);
145 
146  for (i = 0; i < size; i++)
147  {
148 #if POSTGIS_GEOS_VERSION < 38
149  GEOSCoordSeq_getX(cs, i, &(point.x));
150  GEOSCoordSeq_getY(cs, i, &(point.y));
151  if (dims >= 3) GEOSCoordSeq_getZ(cs, i, &(point.z));
152 #else
153  if (dims >= 3)
154  GEOSCoordSeq_getXYZ(cs, i, &(point.x), &(point.y), &(point.z));
155  else
156  GEOSCoordSeq_getXY(cs, i, &(point.x), &(point.y));
157 #endif
158  ptarray_set_point4d(pa, i, &point);
159  }
160 
161  return pa;
162 }
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:435
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#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
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
unsigned int uint32_t
Definition: uthash.h:78

References LWDEBUG, LWDEBUGF, lwerror(), ptarray_construct(), ptarray_set_point4d(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by GEOS2LWGEOM(), and lwtin_from_geos().

Here is the call graph for this function:
Here is the caller graph for this function: