PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ lwcircstring_from_lwpointarray()

LWCIRCSTRING * lwcircstring_from_lwpointarray ( int  srid,
uint32_t  npoints,
LWPOINT **  points 
)

Definition at line 148 of file lwcircstring.c.

References FLAGS_GET_M, FLAGS_GET_Z, getPoint_internal(), lwalloc(), lwcircstring_construct(), lwerror(), lwtype_name(), POINTTYPE, ptarray_construct_reference_data(), ptarray_point_size(), and ovdump::type.

149 {
150  int zmflag=0;
151  uint32_t i;
152  POINTARRAY *pa;
153  uint8_t *newpoints, *ptr;
154  size_t ptsize, size;
155 
156  /*
157  * Find output dimensions, check integrity
158  */
159  for (i = 0; i < npoints; i++)
160  {
161  if (points[i]->type != POINTTYPE)
162  {
163  lwerror("lwcurve_from_lwpointarray: invalid input type: %s",
164  lwtype_name(points[i]->type));
165  return NULL;
166  }
167  if (FLAGS_GET_Z(points[i]->flags)) zmflag |= 2;
168  if (FLAGS_GET_M(points[i]->flags)) zmflag |= 1;
169  if (zmflag == 3) break;
170  }
171 
172  if (zmflag == 0) ptsize = 2 * sizeof(double);
173  else if (zmflag == 3) ptsize = 4 * sizeof(double);
174  else ptsize = 3 * sizeof(double);
175 
176  /*
177  * Allocate output points array
178  */
179  size = ptsize * npoints;
180  newpoints = lwalloc(size);
181  memset(newpoints, 0, size);
182 
183  ptr = newpoints;
184  for (i = 0; i < npoints; i++)
185  {
186  size = ptarray_point_size(points[i]->point);
187  memcpy(ptr, getPoint_internal(points[i]->point, 0), size);
188  ptr += ptsize;
189  }
190  pa = ptarray_construct_reference_data(zmflag&2, zmflag&1, npoints, newpoints);
191 
192  return lwcircstring_construct(srid, NULL, pa);
193 }
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
POINTARRAY * ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist)
Construct a new POINTARRAY, referencing to the data from ptlist.
Definition: ptarray.c:295
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:139
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
type
Definition: ovdump.py:41
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:51
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function: