PostGIS  2.2.7dev-r@@SVN_REVISION@@
static int ptarray_to_kml2_sb ( const POINTARRAY pa,
int  precision,
stringbuffer_t sb 
)
static

Definition at line 82 of file lwout_kml.c.

References POINTARRAY::flags, FLAGS_GET_Z, getPoint4d_p(), LW_FAILURE, LW_SUCCESS, POINTARRAY::npoints, OUT_MAX_DOUBLE, stringbuffer_append(), stringbuffer_aprintf(), and stringbuffer_trim_trailing_zeroes().

Referenced by lwline_to_kml2_sb(), lwpoint_to_kml2_sb(), and lwpoly_to_kml2_sb().

83 {
84  int i, j;
85  int dims = FLAGS_GET_Z(pa->flags) ? 3 : 2;
86  POINT4D pt;
87  double *d;
88 
89  for ( i = 0; i < pa->npoints; i++ )
90  {
91  getPoint4d_p(pa, i, &pt);
92  d = (double*)(&pt);
93  if ( i ) stringbuffer_append(sb," ");
94  for (j = 0; j < dims; j++)
95  {
96  if ( j ) stringbuffer_append(sb,",");
97  if( fabs(d[j]) < OUT_MAX_DOUBLE )
98  {
99  if ( stringbuffer_aprintf(sb, "%.*f", precision, d[j]) < 0 ) return LW_FAILURE;
100  }
101  else
102  {
103  if ( stringbuffer_aprintf(sb, "%g", d[j]) < 0 ) return LW_FAILURE;
104  }
106  }
107  }
108  return LW_SUCCESS;
109 }
int npoints
Definition: liblwgeom.h:355
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define LW_FAILURE
Definition: liblwgeom.h:64
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided...
Definition: stringbuffer.c:246
uint8_t flags
Definition: liblwgeom.h:353
uint8_t precision
Definition: cu_in_twkb.c:25
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
#define OUT_MAX_DOUBLE
void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
Definition: stringbuffer.c:127
int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
Trims zeroes off the end of the last number in the stringbuffer.
Definition: stringbuffer.c:297
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231

Here is the call graph for this function:

Here is the caller graph for this function: