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

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

84 {
85  int i, j;
86  int dims = FLAGS_GET_Z(pa->flags) ? 3 : 2;
87  POINT4D pt;
88  double *d;
89 
90  for ( i = 0; i < pa->npoints; i++ )
91  {
92  getPoint4d_p(pa, i, &pt);
93  d = (double*)(&pt);
94  if ( i ) stringbuffer_append(sb," ");
95  for (j = 0; j < dims; j++)
96  {
97  if ( j ) stringbuffer_append(sb,",");
98  if( fabs(d[j]) < OUT_MAX_DOUBLE )
99  {
100  if ( stringbuffer_aprintf(sb, "%.*f", precision, d[j]) < 0 ) return LW_FAILURE;
101  }
102  else
103  {
104  if ( stringbuffer_aprintf(sb, "%g", d[j]) < 0 ) return LW_FAILURE;
105  }
107  }
108  }
109  return LW_SUCCESS;
110 }
int npoints
Definition: liblwgeom.h:327
#define LW_SUCCESS
Definition: liblwgeom.h:55
#define LW_FAILURE
Definition: liblwgeom.h:54
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:247
uint8_t flags
Definition: liblwgeom.h:325
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
#define OUT_MAX_DOUBLE
void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
Definition: stringbuffer.c:128
int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
Trims zeroes off the end of the last number in the stringbuffer.
Definition: stringbuffer.c:298
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:217

Here is the call graph for this function:

Here is the caller graph for this function: