PostGIS  2.2.7dev-r@@SVN_REVISION@@
static size_t pointArray_to_geojson ( POINTARRAY pa,
char *  buf,
int  precision 
)
static

Definition at line 699 of file lwout_geojson.c.

References BUFSIZE, POINTARRAY::flags, FLAGS_GET_Z, getPoint2d_cp(), getPoint3dz_cp(), lwprint_double(), POINTARRAY::npoints, OUT_MAX_DOUBLE_PRECISION, trim_trailing_zeros(), pixval::x, POINT2D::x, POINT3DZ::x, pixval::y, POINT2D::y, POINT3DZ::y, and POINT3DZ::z.

Referenced by asgeojson_line_buf(), asgeojson_multiline_buf(), asgeojson_multipoint_buf(), asgeojson_multipolygon_buf(), asgeojson_point_buf(), and asgeojson_poly_buf().

700 {
701  int i;
702  char *ptr;
703 #define BUFSIZE OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION
704  char x[BUFSIZE+1];
705  char y[BUFSIZE+1];
706  char z[BUFSIZE+1];
707 
708  assert ( precision <= OUT_MAX_DOUBLE_PRECISION );
709 
710  /* Ensure a terminating NULL at the end of buffers
711  * so that we don't need to check for truncation
712  * inprint_double */
713  x[BUFSIZE] = '\0';
714  y[BUFSIZE] = '\0';
715  z[BUFSIZE] = '\0';
716 
717  ptr = output;
718 
719  /* TODO: rewrite this loop to be simpler and possibly quicker */
720  if (!FLAGS_GET_Z(pa->flags))
721  {
722  for (i=0; i<pa->npoints; i++)
723  {
724  const POINT2D *pt;
725  pt = getPoint2d_cp(pa, i);
726 
727  lwprint_double(pt->x, precision, x, BUFSIZE);
729  lwprint_double(pt->y, precision, y, BUFSIZE);
731 
732  if ( i ) ptr += sprintf(ptr, ",");
733  ptr += sprintf(ptr, "[%s,%s]", x, y);
734  }
735  }
736  else
737  {
738  for (i=0; i<pa->npoints; i++)
739  {
740  const POINT3DZ *pt;
741  pt = getPoint3dz_cp(pa, i);
742 
743  lwprint_double(pt->x, precision, x, BUFSIZE);
745  lwprint_double(pt->y, precision, y, BUFSIZE);
747  lwprint_double(pt->z, precision, z, BUFSIZE);
749 
750  if ( i ) ptr += sprintf(ptr, ",");
751  ptr += sprintf(ptr, "[%s,%s,%s]", x, y, z);
752  }
753  }
754 
755  return (ptr-output);
756 }
double z
Definition: liblwgeom.h:318
double y
Definition: liblwgeom.h:318
double x
Definition: liblwgeom.h:318
#define BUFSIZE
int npoints
Definition: liblwgeom.h:355
#define OUT_MAX_DOUBLE_PRECISION
void trim_trailing_zeros(char *num)
Definition: lwutil.c:224
double x
Definition: liblwgeom.h:312
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:472
uint8_t flags
Definition: liblwgeom.h:353
static int lwprint_double(double d, int maxdd, char *buf, size_t bufsize)
uint8_t precision
Definition: cu_in_twkb.c:25
double y
Definition: liblwgeom.h:312
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
tuple x
Definition: pixval.py:53
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, int n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:486
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: