PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ pointArray_to_geojson()

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

Definition at line 680 of file lwout_geojson.c.

References POINTARRAY::flags, FLAGS_GET_Z, getPoint2d_cp(), getPoint3dz_cp(), lwprint_double(), POINTARRAY::npoints, OUT_DOUBLE_BUFFER_SIZE, OUT_MAX_DOUBLE_PRECISION, 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().

681 {
682  uint32_t i;
683  char *ptr;
686  char z[OUT_DOUBLE_BUFFER_SIZE];
687 
688  assert ( precision <= OUT_MAX_DOUBLE_PRECISION );
689  ptr = output;
690 
691  /* TODO: rewrite this loop to be simpler and possibly quicker */
692  if (!FLAGS_GET_Z(pa->flags))
693  {
694  for (i=0; i<pa->npoints; i++)
695  {
696  const POINT2D *pt;
697  pt = getPoint2d_cp(pa, i);
698 
703 
704  if ( i ) ptr += sprintf(ptr, ",");
705  ptr += sprintf(ptr, "[%s,%s]", x, y);
706  }
707  }
708  else
709  {
710  for (i=0; i<pa->npoints; i++)
711  {
712  const POINT3DZ *pt;
713  pt = getPoint3dz_cp(pa, i);
714 
721 
722  if ( i ) ptr += sprintf(ptr, ",");
723  ptr += sprintf(ptr, "[%s,%s,%s]", x, y, z);
724  }
725  }
726 
727  return (ptr-output);
728 }
int lwprint_double(double d, int maxdd, char *buf, size_t bufsize)
Definition: lwprint.c:488
double z
Definition: liblwgeom.h:336
double y
Definition: liblwgeom.h:336
double x
Definition: liblwgeom.h:336
#define OUT_MAX_DOUBLE_PRECISION
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:330
const POINT3DZ * getPoint3dz_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT3DZ pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:378
uint8_t flags
Definition: liblwgeom.h:371
uint8_t precision
Definition: cu_in_twkb.c:25
double y
Definition: liblwgeom.h:330
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:139
#define OUT_DOUBLE_BUFFER_SIZE
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: