PostGIS  3.1.6dev-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 322 of file lwgeom_export.c.

323 {
324  GSERIALIZED *geom;
325  LWGEOM *lwgeom;
326  int version;
327  int option = 0;
329  static const char* default_defid = "x3d:"; /* default defid */
330  char *defidbuf;
331  const char* defid = default_defid;
332  text *defid_text;
333 
334  /* Get the version */
335  version = PG_GETARG_INT32(0);
336  if ( version != 3 )
337  {
338  elog(ERROR, "Only X3D version 3 are supported");
339  PG_RETURN_NULL();
340  }
341 
342  /* Get the geometry */
343  if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
344  geom = PG_GETARG_GSERIALIZED_P(1);
345 
346  /* Retrieve precision if any (default is max) */
347  if (PG_NARGS() >2 && !PG_ARGISNULL(2))
348  {
349  precision = PG_GETARG_INT32(2);
350  }
351 
352  /* retrieve option */
353  if (PG_NARGS() >3 && !PG_ARGISNULL(3))
354  option = PG_GETARG_INT32(3);
355 
356 
357  /* retrieve defid */
358  if (PG_NARGS() >4 && !PG_ARGISNULL(4))
359  {
360  defid_text = PG_GETARG_TEXT_P(4);
361  if ( VARSIZE_ANY_EXHDR(defid_text) == 0 )
362  {
363  defid = "";
364  }
365  else
366  {
367  /* +2 is one for the ':' and one for term null */
368  defidbuf = palloc(VARSIZE_ANY_EXHDR(defid_text)+2);
369  memcpy(defidbuf, VARDATA(defid_text),
370  VARSIZE_ANY_EXHDR(defid_text));
371  /* add colon and null terminate */
372  defidbuf[VARSIZE_ANY_EXHDR(defid_text)] = ':';
373  defidbuf[VARSIZE_ANY_EXHDR(defid_text)+1] = '\0';
374  defid = defidbuf;
375  }
376  }
377 
378  lwgeom = lwgeom_from_gserialized(geom);
379 
380  if (option & LW_X3D_USE_GEOCOORDS) {
381  if (lwgeom->srid != 4326)
382  {
383  PG_FREE_IF_COPY(geom, 1);
386  elog(ERROR, "Only SRID 4326 is supported for geocoordinates.");
387  PG_RETURN_NULL();
388  }
389  }
390 
391  PG_RETURN_TEXT_P(lwgeom_to_x3d3(lwgeom, precision, option, defid));
392 }
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:1692
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:474

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: