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

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

204 {
205  uint32 typmod = 0;
206  Datum *elem_values;
207  int n = 0;
208  int i = 0;
209 
210  if (ARR_ELEMTYPE(arr) != CSTRINGOID)
211  ereport(ERROR,
212  (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
213  errmsg("typmod array must be type cstring[]")));
214 
215  if (ARR_NDIM(arr) != 1)
216  ereport(ERROR,
217  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
218  errmsg("typmod array must be one-dimensional")));
219 
220  if (ARR_HASNULL(arr))
221  ereport(ERROR,
222  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
223  errmsg("typmod array must not contain nulls")));
224 
225  deconstruct_array(arr,
226  CSTRINGOID, -2, false, 'c', /* hardwire cstring representation details */
227  &elem_values, NULL, &n);
228 
229  /* Set the SRID to the default value first */
230  if ( is_geography)
231  TYPMOD_SET_SRID(typmod, SRID_DEFAULT);
232  else
233  TYPMOD_SET_SRID(typmod, SRID_UNKNOWN);
234 
235  for (i = 0; i < n; i++)
236  {
237  if ( i == 0 ) /* TYPE */
238  {
239  char *s = DatumGetCString(elem_values[i]);
240  uint8_t type = 0;
241  int z = 0;
242  int m = 0;
243 
244  if ( geometry_type_from_string(s, &type, &z, &m) == LW_FAILURE )
245  {
246  ereport(ERROR,
247  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
248  errmsg("Invalid geometry type modifier: %s", s)));
249  }
250  else
251  {
252  TYPMOD_SET_TYPE(typmod, type);
253  if ( z )
254  TYPMOD_SET_Z(typmod);
255  if ( m )
256  TYPMOD_SET_M(typmod);
257  }
258  }
259  if ( i == 1 ) /* SRID */
260  {
261  int srid = pg_atoi(DatumGetCString(elem_values[i]),
262  sizeof(int32), '\0');
263  srid = clamp_srid(srid);
264  POSTGIS_DEBUGF(3, "srid: %d", srid);
265  if ( srid != SRID_UNKNOWN )
266  {
267  TYPMOD_SET_SRID(typmod, srid);
268  }
269  }
270  }
271 
272  pfree(elem_values);
273 
274  return typmod;
275 }
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:326
#define TYPMOD_SET_Z(typmod)
Definition: liblwgeom.h:136
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:149
#define SRID_DEFAULT
Definition: liblwgeom.h:161
#define TYPMOD_SET_M(typmod)
Definition: liblwgeom.h:138
#define LW_FAILURE
Definition: liblwgeom.h:54
unsigned int uint32
Definition: shpopen.c:274
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
char * s
Definition: cu_in_wkt.c:24
#define TYPMOD_SET_TYPE(typmod, type)
Definition: liblwgeom.h:134
#define TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:132

Here is the call graph for this function:

Here is the caller graph for this function: