PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ LWGEOM_asEncodedPolyline()

Datum LWGEOM_asEncodedPolyline ( PG_FUNCTION_ARGS  )

Definition at line 633 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().

634 {
635  GSERIALIZED *geom;
636  LWGEOM *lwgeom;
637  char *encodedpolyline;
638  int precision = 5;
639  text *result;
640 
641  if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
642 
643  geom = PG_GETARG_GSERIALIZED_P(0);
644  if (gserialized_get_srid(geom) != 4326) {
645  PG_FREE_IF_COPY(geom, 0);
646  elog(ERROR, "Only SRID 4326 is supported.");
647  PG_RETURN_NULL();
648  }
649  lwgeom = lwgeom_from_gserialized(geom);
650 
651  if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
652  {
653  precision = PG_GETARG_INT32(1);
654  if ( precision < 0 ) precision = 5;
655  }
656 
657  encodedpolyline = lwgeom_to_encoded_polyline(lwgeom, precision);
658  lwgeom_free(lwgeom);
659  PG_FREE_IF_COPY(geom, 0);
660 
661  result = cstring_to_text(encodedpolyline);
662  lwfree(encodedpolyline);
663 
664  PG_RETURN_TEXT_P(result);
665 }
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:1144
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:99
Here is the call graph for this function:
Here is the caller graph for this function: