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

Definition at line 700 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().

701 {
702  int i;
703  char *ptr;
704 #define BUFSIZE OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION
705  char x[BUFSIZE+1];
706  char y[BUFSIZE+1];
707  char z[BUFSIZE+1];
708 
709  assert ( precision <= OUT_MAX_DOUBLE_PRECISION );
710 
711  /* Ensure a terminating NULL at the end of buffers
712  * so that we don't need to check for truncation
713  * inprint_double */
714  x[BUFSIZE] = '\0';
715  y[BUFSIZE] = '\0';
716  z[BUFSIZE] = '\0';
717 
718  ptr = output;
719 
720  /* TODO: rewrite this loop to be simpler and possibly quicker */
721  if (!FLAGS_GET_Z(pa->flags))
722  {
723  for (i=0; i<pa->npoints; i++)
724  {
725  const POINT2D *pt;
726  pt = getPoint2d_cp(pa, i);
727 
728  lwprint_double(pt->x, precision, x, BUFSIZE);
730  lwprint_double(pt->y, precision, y, BUFSIZE);
732 
733  if ( i ) ptr += sprintf(ptr, ",");
734  ptr += sprintf(ptr, "[%s,%s]", x, y);
735  }
736  }
737  else
738  {
739  for (i=0; i<pa->npoints; i++)
740  {
741  const POINT3DZ *pt;
742  pt = getPoint3dz_cp(pa, i);
743 
744  lwprint_double(pt->x, precision, x, BUFSIZE);
746  lwprint_double(pt->y, precision, y, BUFSIZE);
748  lwprint_double(pt->z, precision, z, BUFSIZE);
750 
751  if ( i ) ptr += sprintf(ptr, ",");
752  ptr += sprintf(ptr, "[%s,%s,%s]", x, y, z);
753  }
754  }
755 
756  return (ptr-output);
757 }
double z
Definition: liblwgeom.h:290
double y
Definition: liblwgeom.h:290
double x
Definition: liblwgeom.h:290
#define BUFSIZE
int npoints
Definition: liblwgeom.h:327
#define OUT_MAX_DOUBLE_PRECISION
void trim_trailing_zeros(char *num)
Definition: lwutil.c:200
double x
Definition: liblwgeom.h:284
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:458
uint8_t flags
Definition: liblwgeom.h:325
static int lwprint_double(double d, int maxdd, char *buf, size_t bufsize)
double y
Definition: liblwgeom.h:284
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
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:472
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: