PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ TWKBFromLWGEOM()

Datum TWKBFromLWGEOM ( PG_FUNCTION_ARGS  )

Definition at line 433 of file lwgeom_inout.c.

434 {
435  GSERIALIZED *geom;
436  LWGEOM *lwgeom;
437  uint8_t variant = 0;
438  srs_precision sp;
439 
440  /*check for null input since we cannot have the sql-function as strict.
441  That is because we use null as default for optional ID*/
442  if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
443 
444  geom = PG_GETARG_GSERIALIZED_P(0);
445 
446  /* Read sensible precision defaults (about one meter) given the srs */
447  sp = srid_axis_precision(gserialized_get_srid(geom), TWKB_DEFAULT_PRECISION);
448 
449  /* If user specified XY precision, use it */
450  if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
451  sp.precision_xy = PG_GETARG_INT32(1);
452 
453  /* If user specified Z precision, use it */
454  if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
455  sp.precision_z = PG_GETARG_INT32(2);
456 
457  /* If user specified M precision, use it */
458  if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
459  sp.precision_m = PG_GETARG_INT32(3);
460 
461  /* We don't permit ids for single geometries */
462  variant = variant & ~TWKB_ID;
463 
464  /* If user wants registered twkb sizes */
465  if ( PG_NARGS() > 4 && ! PG_ARGISNULL(4) && PG_GETARG_BOOL(4) )
466  variant |= TWKB_SIZE;
467 
468  /* If user wants bounding boxes */
469  if ( PG_NARGS() > 5 && ! PG_ARGISNULL(5) && PG_GETARG_BOOL(5) )
470  variant |= TWKB_BBOX;
471 
472  /* Create TWKB binary string */
473  lwgeom = lwgeom_from_gserialized(geom);
474  PG_RETURN_BYTEA_P(lwgeom_to_twkb(lwgeom, variant, sp.precision_xy, sp.precision_z, sp.precision_m));
475 }
static uint8_t variant
Definition: cu_in_twkb.c:26
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)...
Definition: gserialized.c:155
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:268
lwvarlena_t * lwgeom_to_twkb(const LWGEOM *geom, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m)
Definition: lwout_twkb.c:636
#define TWKB_ID
Definition: liblwgeom.h:2226
#define TWKB_DEFAULT_PRECISION
Definition: liblwgeom.h:2229
#define TWKB_SIZE
Definition: liblwgeom.h:2225
#define TWKB_BBOX
Definition: liblwgeom.h:2224

References gserialized_get_srid(), lwgeom_from_gserialized(), lwgeom_to_twkb(), TWKB_BBOX, TWKB_DEFAULT_PRECISION, TWKB_ID, TWKB_SIZE, and variant.

Here is the call graph for this function: