PostGIS  2.1.10dev-r@@SVN_REVISION@@
char* lwgeom_to_wkt ( const LWGEOM geom,
uint8_t  variant,
int  precision,
size_t *  size_out 

WKT emitter function.

lwgeomgeometry to convert to WKT
variantoutput format to use (WKT_ISO, WKT_SFSQL, WKT_EXTENDED)

Allocates a new *char and fills it with the WKT representation. If size_out is not NULL, it will be set to the size of the allocated *char.

variantBitmasked value, accepts one of WKT_ISO, WKT_SFSQL, WKT_EXTENDED.
precisionNumber of significant digits in the output doubles.
size_outIf supplied, will return the size of the returned string, including the null terminator.

Definition at line 655 of file lwout_wkt.c.

References lwerror(), lwgeom_has_srid(), lwgeom_to_wkt_sb(), LWGEOM::srid, stringbuffer_aprintf(), stringbuffer_create(), stringbuffer_destroy(), stringbuffer_getlength(), stringbuffer_getstring(), stringbuffer_getstringcopy(), and WKT_EXTENDED.

Referenced by cu_wkt(), cu_wkt_in(), do_geojson_test(), do_lwgeom_flip_coordinates(), errorIfGeometryCollection(), GenerateLineStringGeometry(), GeneratePointGeometry(), GeneratePolygonGeometry(), gserialized_to_string(), LWGEOM_asEWKT(), LWGEOM_asText(), lwgeom_to_ewkt(), lwgeom_to_text(), rt_raster_gdal_polygonize(), rt_raster_surface(), test_lwgeom_locate_along(), test_misc_wkb(), test_ptarray_desegmentize(), and triangle_parse().

656 {
657  stringbuffer_t *sb;
658  char *str = NULL;
659  if ( geom == NULL )
660  return NULL;
661  sb = stringbuffer_create();
662  /* Extended mode starts with an "SRID=" section for geoms that have one */
663  if ( (variant & WKT_EXTENDED) && lwgeom_has_srid(geom) )
664  {
665  stringbuffer_aprintf(sb, "SRID=%d;", geom->srid);
666  }
667  lwgeom_to_wkt_sb(geom, sb, precision, variant);
668  if ( stringbuffer_getstring(sb) == NULL )
669  {
670  lwerror("Uh oh");
671  return NULL;
672  }
673  str = stringbuffer_getstringcopy(sb);
674  if ( size_out )
675  *size_out = stringbuffer_getlength(sb) + 1;
677  return str;
678 }
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition: lwgeom.c:1272
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
Definition: stringbuffer.c:47
char * stringbuffer_getstringcopy(stringbuffer_t *s)
Returns a newly allocated string large enough to contain the current state of the string...
Definition: stringbuffer.c:154
int32_t srid
Definition: liblwgeom.h:355
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided...
Definition: stringbuffer.c:247
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
int stringbuffer_getlength(stringbuffer_t *s)
Returns the length of the current string, not including the null terminator (same behavior as strlen(...
Definition: stringbuffer.c:168
static void lwgeom_to_wkt_sb(const LWGEOM *geom, stringbuffer_t *sb, int precision, uint8_t variant)
Definition: lwout_wkt.c:586
Definition: liblwgeom.h:1778
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
Definition: stringbuffer.c:72
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
Definition: stringbuffer.c:143

Here is the call graph for this function:

Here is the caller graph for this function: