PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_asEncodedPolyline()

Datum LWGEOM_asEncodedPolyline ( PG_FUNCTION_ARGS  )

Definition at line 624 of file lwgeom_export.c.

References dumpnode::geom, gserialized_get_srid(), lwfree(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_to_encoded_polyline(), and precision.

Referenced by LWGEOM_asX3D().

625 {
626  GSERIALIZED *geom;
627  LWGEOM *lwgeom;
628  char *encodedpolyline;
629  int precision = 5;
630  text *result;
631 
632  if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
633 
634  geom = PG_GETARG_GSERIALIZED_P(0);
635  if (gserialized_get_srid(geom) != 4326) {
636  PG_FREE_IF_COPY(geom, 0);
637  elog(ERROR, "Only SRID 4326 is supported.");
638  PG_RETURN_NULL();
639  }
640  lwgeom = lwgeom_from_gserialized(geom);
641 
642  if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
643  {
644  precision = PG_GETARG_INT32(1);
645  if ( precision < 0 ) precision = 5;
646  }
647 
648  encodedpolyline = lwgeom_to_encoded_polyline(lwgeom, precision);
649  lwgeom_free(lwgeom);
650  PG_FREE_IF_COPY(geom, 0);
651 
652  result = cstring2text(encodedpolyline);
653  lwfree(encodedpolyline);
654 
655  PG_RETURN_TEXT_P(result);
656 }
void lwfree(void *mem)
Definition: lwutil.c:244
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
char * lwgeom_to_encoded_polyline(const LWGEOM *geom, int precision)
LWGEOM * geom
uint8_t precision
Definition: cu_in_twkb.c:25
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)...
Definition: g_serialized.c:100
Here is the call graph for this function:
Here is the caller graph for this function: