PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ geography_as_kml()

Datum geography_as_kml ( PG_FUNCTION_ARGS  )

Definition at line 348 of file geography_inout.c.

349 {
350 
351  char *kml;
352  text *result;
353  static const char *default_prefix = "";
354  char *prefixbuf;
355  const char *prefix = default_prefix;
356  GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
357  int precision = PG_GETARG_INT32(1);
358  text *prefix_text = PG_GETARG_TEXT_P(2);
359  LWGEOM *lwgeom = lwgeom_from_gserialized(g);
360 
361  /* Condition the precision */
362  if (precision > DBL_DIG)
363  precision = DBL_DIG;
364  if (precision < 0)
365  precision = 0;
366 
367  if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
368  {
369  /* +2 is one for the ':' and one for term null */
370  prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
371  memcpy(prefixbuf, VARDATA(prefix_text),
372  VARSIZE_ANY_EXHDR(prefix_text));
373  /* add colon and null terminate */
374  prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
375  prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
376  prefix = prefixbuf;
377  }
378  else
379  {
380  prefix = "";
381  }
382 
383  kml = lwgeom_to_kml2(lwgeom, precision, prefix);
384 
385  lwgeom_free(lwgeom);
386  PG_FREE_IF_COPY(g, 0);
387 
388  if (!kml)
389  PG_RETURN_NULL();
390 
391  result = cstring_to_text(kml);
392  lwfree(kml);
393 
394  PG_RETURN_TEXT_P(result);
395 }
static uint8_t precision
Definition: cu_in_twkb.c:25
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:44
void lwfree(void *mem)
Definition: lwutil.c:242

References lwfree(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_to_kml2(), and precision.

Here is the call graph for this function: