PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwgeom_to_wkt()

char * lwgeom_to_wkt ( const LWGEOM geom,
uint8_t  variant,
int  precision,
size_t *  size_out 
)
extern

WKT emitter function.

Parameters
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.

Parameters
variantBitmasked value, accepts one of WKT_ISO, WKT_SFSQL, WKT_EXTENDED.
precisionMaximal number of digits after comma in the output doubles.
size_outIf supplied, will return the size of the returned string, including the null terminator.

Definition at line 676 of file lwout_wkt.c.

677{
678 stringbuffer_t *sb;
679 char *str = NULL;
680 if ( geom == NULL )
681 return NULL;
682 sb = stringbuffer_create();
683 /* Extended mode starts with an "SRID=" section for geoms that have one */
684 if ( (variant & WKT_EXTENDED) && lwgeom_has_srid(geom) )
685 {
686 stringbuffer_aprintf(sb, "SRID=%d;", geom->srid);
687 }
689 if ( stringbuffer_getstring(sb) == NULL )
690 {
691 lwerror("Uh oh");
692 return NULL;
693 }
695 if ( size_out )
696 *size_out = stringbuffer_getlength(sb) + 1;
698 return str;
699}
static uint8_t variant
Definition cu_in_twkb.c:26
static uint8_t precision
Definition cu_in_twkb.c:25
#define WKT_EXTENDED
Definition liblwgeom.h:2132
int lwgeom_has_srid(const LWGEOM *geom)
Return true or false depending on whether a geometry has a valid SRID set.
Definition lwgeom.c:1387
#define str(s)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition lwutil.c:190
static void lwgeom_to_wkt_sb(const LWGEOM *geom, stringbuffer_t *sb, int precision, uint8_t variant)
Definition lwout_wkt.c:606
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
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.
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
char * stringbuffer_getstringcopy(stringbuffer_t *s)
Returns a newly allocated string large enough to contain the current state of the string.
int stringbuffer_getlength(stringbuffer_t *s)
Returns the length of the current string, not including the null terminator (same behavior as strlen(...
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
int32_t srid
Definition liblwgeom.h:446

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

Referenced by _lwt_AddLine(), _lwt_AddPoint(), _lwt_EdgeSplit(), _lwt_FaceByEdges(), _lwt_FindNextRingEdge(), cu_wkt(), cu_wkt_in(), do_encoded_polyline_test(), do_geojson_test(), do_lwgeom_swap_ordinates(), do_test_chaikin(), do_test_filterm(), GenerateLineStringGeometry(), GeneratePointGeometry(), GeneratePolygonGeometry(), LWGEOM_asEWKT(), LWGEOM_asText(), lwgeom_to_ewkt(), lwgeom_to_text(), lwgeom_to_text(), lwgeom_to_text(), lwt_ChangeEdgeGeom(), lwt_GetFaceEdges(), rect_tree_to_wkt(), rt_raster_gdal_polygonize(), rt_raster_surface(), test_lwcurve_linearize(), test_lwgeom_locate_along(), test_misc_wkb(), test_unstroke(), and triangle_parse().

Here is the call graph for this function:
Here is the caller graph for this function: