PostGIS  2.3.7dev-r@@SVN_REVISION@@
static uint32 gserialized_typmod_in ( ArrayType *  arr,
int  is_geography 
)
static

Definition at line 219 of file gserialized_typmod.c.

References clamp_srid(), geometry_type_from_string(), LW_FAILURE, s, SRID_DEFAULT, SRID_UNKNOWN, TYPMOD_SET_M, TYPMOD_SET_SRID, TYPMOD_SET_TYPE, and TYPMOD_SET_Z.

Referenced by geography_typmod_in(), and geometry_typmod_in().

220 {
221  uint32 typmod = 0;
222  Datum *elem_values;
223  int n = 0;
224  int i = 0;
225 
226  if (ARR_ELEMTYPE(arr) != CSTRINGOID)
227  ereport(ERROR,
228  (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
229  errmsg("typmod array must be type cstring[]")));
230 
231  if (ARR_NDIM(arr) != 1)
232  ereport(ERROR,
233  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
234  errmsg("typmod array must be one-dimensional")));
235 
236  if (ARR_HASNULL(arr))
237  ereport(ERROR,
238  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
239  errmsg("typmod array must not contain nulls")));
240 
241  deconstruct_array(arr,
242  CSTRINGOID, -2, false, 'c', /* hardwire cstring representation details */
243  &elem_values, NULL, &n);
244 
245  /* Set the SRID to the default value first */
246  if ( is_geography)
247  TYPMOD_SET_SRID(typmod, SRID_DEFAULT);
248  else
249  TYPMOD_SET_SRID(typmod, SRID_UNKNOWN);
250 
251  for (i = 0; i < n; i++)
252  {
253  if ( i == 0 ) /* TYPE */
254  {
255  char *s = DatumGetCString(elem_values[i]);
256  uint8_t type = 0;
257  int z = 0;
258  int m = 0;
259 
260  if ( geometry_type_from_string(s, &type, &z, &m) == LW_FAILURE )
261  {
262  ereport(ERROR,
263  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
264  errmsg("Invalid geometry type modifier: %s", s)));
265  }
266  else
267  {
268  TYPMOD_SET_TYPE(typmod, type);
269  if ( z )
270  TYPMOD_SET_Z(typmod);
271  if ( m )
272  TYPMOD_SET_M(typmod);
273  }
274  }
275  if ( i == 1 ) /* SRID */
276  {
277  int srid = pg_atoi(DatumGetCString(elem_values[i]),
278  sizeof(int32), '\0');
279  srid = clamp_srid(srid);
280  POSTGIS_DEBUGF(3, "srid: %d", srid);
281  if ( srid != SRID_UNKNOWN )
282  {
283  TYPMOD_SET_SRID(typmod, srid);
284  }
285  }
286  }
287 
288  pfree(elem_values);
289 
290  return typmod;
291 }
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
Definition: lwutil.c:378
unsigned int int32
Definition: shpopen.c:273
#define TYPMOD_SET_Z(typmod)
Definition: liblwgeom.h:169
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Calculate type integer and dimensional flags from string input.
Definition: g_util.c:163
#define SRID_DEFAULT
Definition: liblwgeom.h:194
#define TYPMOD_SET_M(typmod)
Definition: liblwgeom.h:171
#define LW_FAILURE
Definition: liblwgeom.h:78
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
char * s
Definition: cu_in_wkt.c:23
#define TYPMOD_SET_TYPE(typmod, type)
Definition: liblwgeom.h:167
#define TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:165

Here is the call graph for this function:

Here is the caller graph for this function: