PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 336 of file lwgeom_export.c.

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