PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ LWGEOM_from_text()

Datum LWGEOM_from_text ( PG_FUNCTION_ARGS  )

Definition at line 781 of file lwgeom_ogc.c.

References struct_lwgeom_parser_result::geom, geometry_serialize(), LW_FAILURE, LW_PARSER_CHECK_ALL, LWGEOM_from_WKB(), lwgeom_parse_wkt(), lwgeom_parser_result_free(), lwgeom_set_srid(), PG_FUNCTION_INFO_V1(), LWGEOM::srid, SRID_UNKNOWN, and text2cstring().

Referenced by LWGEOM_endpoint_linestring().

782 {
783  text *wkttext = PG_GETARG_TEXT_P(0);
784  char *wkt = text2cstring(wkttext);
785  LWGEOM_PARSER_RESULT lwg_parser_result;
786  GSERIALIZED *geom_result = NULL;
787  LWGEOM *lwgeom;
788 
789  POSTGIS_DEBUG(2, "LWGEOM_from_text");
790  POSTGIS_DEBUGF(3, "wkt: [%s]", wkt);
791 
792  if (lwgeom_parse_wkt(&lwg_parser_result, wkt, LW_PARSER_CHECK_ALL) == LW_FAILURE)
793  PG_PARSER_ERROR(lwg_parser_result);
794 
795  lwgeom = lwg_parser_result.geom;
796 
797  if ( lwgeom->srid != SRID_UNKNOWN )
798  {
799  elog(WARNING, "OGC WKT expected, EWKT provided - use GeomFromEWKT() for this");
800  }
801 
802  /* read user-requested SRID if any */
803  if ( PG_NARGS() > 1 )
804  lwgeom_set_srid(lwgeom, PG_GETARG_INT32(1));
805 
806  geom_result = geometry_serialize(lwgeom);
807  lwgeom_parser_result_free(&lwg_parser_result);
808 
809  PG_RETURN_POINTER(geom_result);
810 }
void lwgeom_parser_result_free(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:885
int32_t srid
Definition: liblwgeom.h:398
#define LW_FAILURE
Definition: liblwgeom.h:78
int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int parse_flags)
Parse a WKT geometry string into an LWGEOM structure.
Parser result structure: returns the result of attempting to convert (E)WKT/(E)WKB to LWGEOM...
Definition: liblwgeom.h:1992
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
char * text2cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
void lwgeom_set_srid(LWGEOM *geom, int srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:1986
Here is the call graph for this function:
Here is the caller graph for this function: