PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_asX3D()

Datum LWGEOM_asX3D ( PG_FUNCTION_ARGS  )

TODO: we need to support UTM and other coordinate systems supported by X3D eventually http://www.web3d.org/documents/specifications/19775-1/V3.2/Part01/components/geodata.html#t-earthgeoids

Definition at line 333 of file lwgeom_export.c.

334 {
335  GSERIALIZED *geom;
336  LWGEOM *lwgeom;
337  int version;
338  int option = 0;
340  static const char* default_defid = "x3d:"; /* default defid */
341  char *defidbuf;
342  const char* defid = default_defid;
343  text *defid_text;
344 
345  /* Get the version */
346  version = PG_GETARG_INT32(0);
347  if ( version != 3 )
348  {
349  elog(ERROR, "Only X3D version 3 are supported");
350  PG_RETURN_NULL();
351  }
352 
353  /* Get the geometry */
354  if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
355  geom = PG_GETARG_GSERIALIZED_P(1);
356 
357  /* Retrieve precision if any (default is max) */
358  if (PG_NARGS() >2 && !PG_ARGISNULL(2))
359  {
360  precision = PG_GETARG_INT32(2);
361  }
362 
363  /* retrieve option */
364  if (PG_NARGS() >3 && !PG_ARGISNULL(3))
365  option = PG_GETARG_INT32(3);
366 
367 
368  /* retrieve defid */
369  if (PG_NARGS() >4 && !PG_ARGISNULL(4))
370  {
371  defid_text = PG_GETARG_TEXT_P(4);
372  if ( VARSIZE_ANY_EXHDR(defid_text) == 0 )
373  {
374  defid = "";
375  }
376  else
377  {
378  /* +2 is one for the ':' and one for term null */
379  defidbuf = palloc(VARSIZE_ANY_EXHDR(defid_text)+2);
380  memcpy(defidbuf, VARDATA(defid_text),
381  VARSIZE_ANY_EXHDR(defid_text));
382  /* add colon and null terminate */
383  defidbuf[VARSIZE_ANY_EXHDR(defid_text)] = ':';
384  defidbuf[VARSIZE_ANY_EXHDR(defid_text)+1] = '\0';
385  defid = defidbuf;
386  }
387  }
388 
389  lwgeom = lwgeom_from_gserialized(geom);
390 
391  if (option & LW_X3D_USE_GEOCOORDS) {
392  if (lwgeom->srid != 4326)
393  {
394  PG_FREE_IF_COPY(geom, 0);
397  elog(ERROR, "Only SRID 4326 is supported for geocoordinates.");
398  PG_RETURN_NULL();
399  }
400  }
401 
402  PG_RETURN_TEXT_P(lwgeom_to_x3d3(lwgeom, precision, option, defid));
403 }
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
#define LW_X3D_USE_GEOCOORDS
Definition: liblwgeom.h:1701
lwvarlena_t * lwgeom_to_x3d3(const LWGEOM *geom, int precision, int opts, const char *defid)
Definition: lwout_x3d.c:37
#define OUT_DEFAULT_DECIMAL_DIGITS
int32_t srid
Definition: liblwgeom.h:460

References LW_X3D_USE_GEOCOORDS, lwgeom_from_gserialized(), lwgeom_to_x3d3(), OUT_DEFAULT_DECIMAL_DIGITS, precision, and LWGEOM::srid.

Here is the call graph for this function: