PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ geography_in()

Datum geography_in ( PG_FUNCTION_ARGS  )

Definition at line 122 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().

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