PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum geography_in ( PG_FUNCTION_ARGS  )

Definition at line 123 of file geography_inout.c.

References struct_lwgeom_parser_result::geom, gserialized_geography_from_lwgeom(), LW_FAILURE, LW_PARSER_CHECK_ALL, LW_PARSER_CHECK_NONE, lwgeom_free(), lwgeom_from_hexwkb(), lwgeom_parse_wkt(), lwgeom_parser_result_init(), and LWGEOM::srid.

124 {
125  char *str = PG_GETARG_CSTRING(0);
126  /* Datum geog_oid = PG_GETARG_OID(1); Not needed. */
127  int32 geog_typmod = -1;
128  LWGEOM_PARSER_RESULT lwg_parser_result;
129  LWGEOM *lwgeom = NULL;
130  GSERIALIZED *g_ser = NULL;
131 
132  if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) ) {
133  geog_typmod = PG_GETARG_INT32(2);
134  }
135 
136  lwgeom_parser_result_init(&lwg_parser_result);
137 
138  /* Empty string. */
139  if ( str[0] == '\0' )
140  ereport(ERROR,(errmsg("parse error - invalid geometry")));
141 
142  /* WKB? Let's find out. */
143  if ( str[0] == '0' )
144  {
145  /* TODO: 20101206: No parser checks! This is inline with current 1.5 behavior, but needs discussion */
147  /* Error out if something went sideways */
148  if ( ! lwgeom )
149  ereport(ERROR,(errmsg("parse error - invalid geometry")));
150  }
151  /* WKT then. */
152  else
153  {
154  if ( lwgeom_parse_wkt(&lwg_parser_result, str, LW_PARSER_CHECK_ALL) == LW_FAILURE )
155  PG_PARSER_ERROR(lwg_parser_result);
156 
157  lwgeom = lwg_parser_result.geom;
158  }
159 
160  /* Error on any SRID != default */
161  srid_is_latlong(fcinfo, lwgeom->srid);
162 
163  /* Convert to gserialized */
164  g_ser = gserialized_geography_from_lwgeom(lwgeom, geog_typmod);
165 
166  /* Clean up temporary object */
167  lwgeom_free(lwgeom);
168 
169 
170  PG_RETURN_POINTER(g_ser);
171 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
int32_t srid
Definition: liblwgeom.h:355
#define LW_FAILURE
Definition: liblwgeom.h:54
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
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:1713
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:753
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:819
GSERIALIZED * gserialized_geography_from_lwgeom(LWGEOM *lwgeom, int32 geog_typmod)
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:1707

Here is the call graph for this function: