PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geography_in()

Datum geography_in ( PG_FUNCTION_ARGS  )

Definition at line 137 of file geography_inout.c.

References geography_out(), 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(), PG_FUNCTION_INFO_V1(), and LWGEOM::srid.

Referenced by gserialized_geography_from_lwgeom().

138 {
139  char *str = PG_GETARG_CSTRING(0);
140  /* Datum geog_oid = PG_GETARG_OID(1); Not needed. */
141  int32 geog_typmod = -1;
142  LWGEOM_PARSER_RESULT lwg_parser_result;
143  LWGEOM *lwgeom = NULL;
144  GSERIALIZED *g_ser = NULL;
145 
146  if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) ) {
147  geog_typmod = PG_GETARG_INT32(2);
148  }
149 
150  lwgeom_parser_result_init(&lwg_parser_result);
151 
152  /* Empty string. */
153  if ( str[0] == '\0' )
154  ereport(ERROR,(errmsg("parse error - invalid geometry")));
155 
156  /* WKB? Let's find out. */
157  if ( str[0] == '0' )
158  {
159  /* TODO: 20101206: No parser checks! This is inline with current 1.5 behavior, but needs discussion */
161  /* Error out if something went sideways */
162  if ( ! lwgeom )
163  ereport(ERROR,(errmsg("parse error - invalid geometry")));
164  }
165  /* WKT then. */
166  else
167  {
168  if ( lwgeom_parse_wkt(&lwg_parser_result, str, LW_PARSER_CHECK_ALL) == LW_FAILURE )
169  PG_PARSER_ERROR(lwg_parser_result);
170 
171  lwgeom = lwg_parser_result.geom;
172  }
173 
174  /* Error on any SRID != default */
175  srid_is_latlong(fcinfo, lwgeom->srid);
176 
177  /* Convert to gserialized */
178  g_ser = gserialized_geography_from_lwgeom(lwgeom, geog_typmod);
179 
180  /* Clean up temporary object */
181  lwgeom_free(lwgeom);
182 
183 
184  PG_RETURN_POINTER(g_ser);
185 }
unsigned int int32
Definition: shpopen.c:273
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
int32_t srid
Definition: liblwgeom.h:399
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
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:2020
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:797
void lwgeom_parser_result_init(LWGEOM_PARSER_RESULT *parser_result)
Definition: lwin_wkt.c:879
GSERIALIZED * gserialized_geography_from_lwgeom(LWGEOM *lwgeom, int32 geog_typmod)
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:2014
Here is the call graph for this function:
Here is the caller graph for this function: