538 static const char* default_defid =
"x3d:";
540 const char* defid = default_defid;
544 version = PG_GETARG_INT32(0);
547 elog(ERROR,
"Only X3D version 3 are supported");
552 if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
553 geom = PG_GETARG_GSERIALIZED_P(1);
556 if (PG_NARGS() >2 && !PG_ARGISNULL(2))
558 precision = PG_GETARG_INT32(2);
560 if ( precision > DBL_DIG )
562 else if ( precision < 0 ) precision = 0;
566 if (PG_NARGS() >3 && !PG_ARGISNULL(3))
567 option = PG_GETARG_INT32(3);
572 if (PG_NARGS() >4 && !PG_ARGISNULL(4))
574 defid_text = PG_GETARG_TEXT_P(4);
575 if ( VARSIZE(defid_text)-VARHDRSZ == 0 )
582 defidbuf = palloc(VARSIZE(defid_text)-VARHDRSZ+2);
583 memcpy(defidbuf, VARDATA(defid_text),
584 VARSIZE(defid_text)-VARHDRSZ);
586 defidbuf[VARSIZE(defid_text)-VARHDRSZ] =
':';
587 defidbuf[VARSIZE(defid_text)-VARHDRSZ+1] =
'\0';
600 PG_FREE_IF_COPY(geom, 0);
603 elog(ERROR,
"Only SRID 4326 is supported for geocoordinates.");
612 PG_FREE_IF_COPY(geom, 1);
614 result = cstring2text(x3d);
617 PG_RETURN_TEXT_P(result);
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
#define LW_X3D_USE_GEOCOORDS
#define SRID_UNKNOWN
Unknown SRID value.
char * getSRSbySRID(int srid, bool short_crs)
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...