PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ pointArray_to_geojson()

static size_t pointArray_to_geojson ( POINTARRAY pa,
char *  buf,
int  precision 
)
static

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

714 {
715  int i;
716  char *ptr;
717 #define BUFSIZE OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION
718  char x[BUFSIZE+1];
719  char y[BUFSIZE+1];
720  char z[BUFSIZE+1];
721 
722  assert ( precision <= OUT_MAX_DOUBLE_PRECISION );
723 
724  /* Ensure a terminating NULL at the end of buffers
725  * so that we don't need to check for truncation
726  * inprint_double */
727  x[BUFSIZE] = '\0';
728  y[BUFSIZE] = '\0';
729  z[BUFSIZE] = '\0';
730 
731  ptr = output;
732 
733  /* TODO: rewrite this loop to be simpler and possibly quicker */
734  if (!FLAGS_GET_Z(pa->flags))
735  {
736  for (i=0; i<pa->npoints; i++)
737  {
738  const POINT2D *pt;
739  pt = getPoint2d_cp(pa, i);
740 
741  lwprint_double(pt->x, precision, x, BUFSIZE);
743  lwprint_double(pt->y, precision, y, BUFSIZE);
745 
746  if ( i ) ptr += sprintf(ptr, ",");
747  ptr += sprintf(ptr, "[%s,%s]", x, y);
748  }
749  }
750  else
751  {
752  for (i=0; i<pa->npoints; i++)
753  {
754  const POINT3DZ *pt;
755  pt = getPoint3dz_cp(pa, i);
756 
757  lwprint_double(pt->x, precision, x, BUFSIZE);
759  lwprint_double(pt->y, precision, y, BUFSIZE);
761  lwprint_double(pt->z, precision, z, BUFSIZE);
763 
764  if ( i ) ptr += sprintf(ptr, ",");
765  ptr += sprintf(ptr, "[%s,%s,%s]", x, y, z);
766  }
767  }
768 
769  return (ptr-output);
770 }
double z
Definition: liblwgeom.h:334
double y
Definition: liblwgeom.h:334
double x
Definition: liblwgeom.h:334
#define BUFSIZE
int npoints
Definition: liblwgeom.h:371
#define OUT_MAX_DOUBLE_PRECISION
void trim_trailing_zeros(char *num)
Definition: lwutil.c:254
double x
Definition: liblwgeom.h:328
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:373
uint8_t flags
Definition: liblwgeom.h:369
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:328
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
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:387
Here is the call graph for this function:
Here is the caller graph for this function: