PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWCIRCSTRING * lwcircstring_from_lwpointarray ( int  srid,
uint32_t  npoints,
LWPOINT **  points 
)

Definition at line 135 of file lwcircstring.c.

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

136 {
137  int zmflag=0;
138  uint32_t i;
139  POINTARRAY *pa;
140  uint8_t *newpoints, *ptr;
141  size_t ptsize, size;
142 
143  /*
144  * Find output dimensions, check integrity
145  */
146  for (i = 0; i < npoints; i++)
147  {
148  if (points[i]->type != POINTTYPE)
149  {
150  lwerror("lwcurve_from_lwpointarray: invalid input type: %s",
151  lwtype_name(points[i]->type));
152  return NULL;
153  }
154  if (FLAGS_GET_Z(points[i]->flags)) zmflag |= 2;
155  if (FLAGS_GET_M(points[i]->flags)) zmflag |= 1;
156  if (zmflag == 3) break;
157  }
158 
159  if (zmflag == 0) ptsize = 2 * sizeof(double);
160  else if (zmflag == 3) ptsize = 4 * sizeof(double);
161  else ptsize = 3 * sizeof(double);
162 
163  /*
164  * Allocate output points array
165  */
166  size = ptsize * npoints;
167  newpoints = lwalloc(size);
168  memset(newpoints, 0, size);
169 
170  ptr = newpoints;
171  for (i = 0; i < npoints; i++)
172  {
173  size = ptarray_point_size(points[i]->point);
174  memcpy(ptr, getPoint_internal(points[i]->point, 0), size);
175  ptr += ptsize;
176  }
177  pa = ptarray_construct_reference_data(zmflag&2, zmflag&1, npoints, newpoints);
178 
179  return lwcircstring_construct(srid, NULL, pa);
180 }
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1645
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:41
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:280
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
void * lwalloc(size_t size)
Definition: lwutil.c:175
LWCIRCSTRING * lwcircstring_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwcircstring.c:38

Here is the call graph for this function: