PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ ptarray_from_GEOSCoordSeq()

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

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

121 {
122  uint32_t dims = 2;
123  POINTARRAY* pa;
124  uint32_t size = 0;
125 #if POSTGIS_GEOS_VERSION < 31000
126  uint32_t i;
127  POINT4D point = { 0.0, 0.0, 0.0, 0.0 };
128 #endif
129 
130  LWDEBUG(2, "ptarray_fromGEOSCoordSeq called");
131 
132  if (!GEOSCoordSeq_getSize(cs, &size)) lwerror("Exception thrown");
133 
134  LWDEBUGF(4, " GEOSCoordSeq size: %d", size);
135 
136  if (want3d)
137  {
138  if (!GEOSCoordSeq_getDimensions(cs, &dims)) lwerror("Exception thrown");
139 
140  LWDEBUGF(4, " GEOSCoordSeq dimensions: %d", dims);
141 
142  /* forget higher dimensions (if any) */
143  if (dims > 3) dims = 3;
144  }
145 
146  LWDEBUGF(4, " output dimensions: %d", dims);
147 
148  pa = ptarray_construct((dims == 3), 0, size);
149 #if POSTGIS_GEOS_VERSION >= 31000
150  GEOSCoordSeq_copyToBuffer(cs, (double*) pa->serialized_pointlist, (dims == 3), 0);
151  return pa;
152 #else
153  for (i = 0; i < size; i++)
154  {
155 #if POSTGIS_GEOS_VERSION < 30800
156  GEOSCoordSeq_getX(cs, i, &(point.x));
157  GEOSCoordSeq_getY(cs, i, &(point.y));
158  if (dims >= 3) GEOSCoordSeq_getZ(cs, i, &(point.z));
159 #else
160  if (dims >= 3)
161  GEOSCoordSeq_getXYZ(cs, i, &(point.x), &(point.y), &(point.z));
162  else
163  GEOSCoordSeq_getXY(cs, i, &(point.x), &(point.y));
164 #endif
165  ptarray_set_point4d(pa, i, &point);
166  }
167 
168  return pa;
169 #endif
170 }
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:370
#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:429
double z
Definition: liblwgeom.h:429
double y
Definition: liblwgeom.h:429
uint8_t * serialized_pointlist
Definition: liblwgeom.h:449

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: