PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ptarray_to_kml2_sb()

static int ptarray_to_kml2_sb ( const POINTARRAY pa,
int  precision,
stringbuffer_t sb 
)
static

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

95 {
96  int i, j;
97  int dims = FLAGS_GET_Z(pa->flags) ? 3 : 2;
98  POINT4D pt;
99  double *d;
100 
101  for ( i = 0; i < pa->npoints; i++ )
102  {
103  getPoint4d_p(pa, i, &pt);
104  d = (double*)(&pt);
105  if ( i ) stringbuffer_append(sb," ");
106  for (j = 0; j < dims; j++)
107  {
108  if ( j ) stringbuffer_append(sb,",");
109  if( fabs(d[j]) < OUT_MAX_DOUBLE )
110  {
111  if ( stringbuffer_aprintf(sb, "%.*f", precision, d[j]) < 0 ) return LW_FAILURE;
112  }
113  else
114  {
115  if ( stringbuffer_aprintf(sb, "%g", d[j]) < 0 ) return LW_FAILURE;
116  }
118  }
119  }
120  return LW_SUCCESS;
121 }
int npoints
Definition: liblwgeom.h:371
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define LW_FAILURE
Definition: liblwgeom.h:79
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:253
uint8_t flags
Definition: liblwgeom.h:369
uint8_t precision
Definition: cu_in_twkb.c:25
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
#define OUT_MAX_DOUBLE
void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
Definition: stringbuffer.c:134
int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
Trims zeroes off the end of the last number in the stringbuffer.
Definition: stringbuffer.c:304
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
Here is the call graph for this function:
Here is the caller graph for this function: