PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ptarray_from_GEOSCoordSeq()

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

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

145 {
146  uint32_t dims = 2;
147  POINTARRAY* pa;
148  uint32_t size = 0;
149 #if POSTGIS_GEOS_VERSION < 31000
150  uint32_t i;
151  POINT4D point = { 0.0, 0.0, 0.0, 0.0 };
152 #endif
153 
154  LWDEBUG(2, "ptarray_fromGEOSCoordSeq called");
155 
156  if (!GEOSCoordSeq_getSize(cs, &size)) lwerror("Exception thrown");
157 
158  LWDEBUGF(4, " GEOSCoordSeq size: %d", size);
159 
160  if (want3d)
161  {
162  if (!GEOSCoordSeq_getDimensions(cs, &dims)) lwerror("Exception thrown");
163 
164  LWDEBUGF(4, " GEOSCoordSeq dimensions: %d", dims);
165 
166  /* forget higher dimensions (if any) */
167  if (dims > 3) dims = 3;
168  }
169 
170  LWDEBUGF(4, " output dimensions: %d", dims);
171 
172  pa = ptarray_construct((dims == 3), 0, size);
173 #if POSTGIS_GEOS_VERSION >= 31000
174  GEOSCoordSeq_copyToBuffer(cs, (double*) pa->serialized_pointlist, (dims == 3), 0);
175  return pa;
176 #else
177  for (i = 0; i < size; i++)
178  {
179 #if POSTGIS_GEOS_VERSION < 30800
180  GEOSCoordSeq_getX(cs, i, &(point.x));
181  GEOSCoordSeq_getY(cs, i, &(point.y));
182  if (dims >= 3) GEOSCoordSeq_getZ(cs, i, &(point.z));
183 #else
184  if (dims >= 3)
185  GEOSCoordSeq_getXYZ(cs, i, &(point.x), &(point.y), &(point.z));
186  else
187  GEOSCoordSeq_getXY(cs, i, &(point.x), &(point.y));
188 #endif
189  ptarray_set_point4d(pa, i, &point);
190  }
191 
192  return pa;
193 #endif
194 }
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:51
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition: lwgeom_api.c:369
#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:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
uint8_t * serialized_pointlist
Definition: liblwgeom.h:434

References LWDEBUG, LWDEBUGF, lwerror(), ptarray_construct(), ptarray_set_point4d(), POINTARRAY::serialized_pointlist, 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: