523{
526 char *x3d;
527 text *result;
528 int version;
529 char *srs;
530 int32_t srid;
531 int option = 0;
533 static const char* default_defid = "x3d:";
534 char *defidbuf;
535 const char* defid = default_defid;
536 text *defid_text;
537
538
539 version = PG_GETARG_INT32(0);
540 if ( version != 3 )
541 {
542 elog(ERROR, "Only X3D version 3 are supported");
543 PG_RETURN_NULL();
544 }
545
546
547 if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
548 geom = PG_GETARG_GSERIALIZED_P(1);
549
550
551 if (PG_NARGS() >2 && !PG_ARGISNULL(2))
552 {
554
558 }
559
560
561 if (PG_NARGS() >3 && !PG_ARGISNULL(3))
562 option = PG_GETARG_INT32(3);
563
564
565
566
567 if (PG_NARGS() >4 && !PG_ARGISNULL(4))
568 {
569 defid_text = PG_GETARG_TEXT_P(4);
570 if ( VARSIZE_ANY_EXHDR(defid_text) == 0 )
571 {
572 defid = "";
573 }
574 else
575 {
576
577 defidbuf = palloc(VARSIZE_ANY_EXHDR(defid_text)+2);
578 memcpy(defidbuf, VARDATA(defid_text),
579 VARSIZE_ANY_EXHDR(defid_text));
580
581 defidbuf[VARSIZE_ANY_EXHDR(defid_text)] = ':';
582 defidbuf[VARSIZE_ANY_EXHDR(defid_text)+1] = '\0';
583 defid = defidbuf;
584 }
585 }
586
590 else if (option & 1)
592 else
594
596 if (srid != 4326) {
597 PG_FREE_IF_COPY(geom, 0);
600 elog(ERROR, "Only SRID 4326 is supported for geocoordinates.");
601 PG_RETURN_NULL();
602 }
603 }
604
605
607
609 PG_FREE_IF_COPY(geom, 1);
610
611 result = cstring_to_text(x3d);
613
614 PG_RETURN_TEXT_P(result);
615}
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
char * lwgeom_to_x3d3(const LWGEOM *geom, char *srs, int precision, int opts, const char *defid)
void lwgeom_free(LWGEOM *geom)
#define SRID_UNKNOWN
Unknown SRID value.
#define LW_X3D_USE_GEOCOORDS
char * getSRSbySRID(FunctionCallInfo fcinfo, int32_t srid, bool short_crs)