PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ gserialized_typmod_in()

static uint32 gserialized_typmod_in ( ArrayType *  arr,
int  is_geography 
)
static

Definition at line 212 of file gserialized_typmod.c.

References clamp_srid(), geography_typmod_in(), geometry_type_from_string(), LW_FAILURE, PG_FUNCTION_INFO_V1(), s, SRID_DEFAULT, SRID_UNKNOWN, ovdump::type, TYPMOD_SET_M, TYPMOD_SET_SRID, TYPMOD_SET_TYPE, and TYPMOD_SET_Z.

Referenced by geography_typmod_in(), and geometry_typmod_in().

213 {
214  int32 typmod = 0;
215  Datum *elem_values;
216  int n = 0;
217  int i = 0;
218 
219  if (ARR_ELEMTYPE(arr) != CSTRINGOID)
220  ereport(ERROR,
221  (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
222  errmsg("typmod array must be type cstring[]")));
223 
224  if (ARR_NDIM(arr) != 1)
225  ereport(ERROR,
226  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
227  errmsg("typmod array must be one-dimensional")));
228 
229  if (ARR_HASNULL(arr))
230  ereport(ERROR,
231  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
232  errmsg("typmod array must not contain nulls")));
233 
234  deconstruct_array(arr,
235  CSTRINGOID, -2, false, 'c', /* hardwire cstring representation details */
236  &elem_values, NULL, &n);
237 
238  /* Set the SRID to the default value first */
239  if ( is_geography)
240  TYPMOD_SET_SRID(typmod, SRID_DEFAULT);
241  else
242  TYPMOD_SET_SRID(typmod, SRID_UNKNOWN);
243 
244  for (i = 0; i < n; i++)
245  {
246  if ( i == 0 ) /* TYPE */
247  {
248  char *s = DatumGetCString(elem_values[i]);
249  uint8_t type = 0;
250  int z = 0;
251  int m = 0;
252 
253  if ( geometry_type_from_string(s, &type, &z, &m) == LW_FAILURE )
254  {
255  ereport(ERROR,
256  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
257  errmsg("Invalid geometry type modifier: %s", s)));
258  }
259  else
260  {
261  TYPMOD_SET_TYPE(typmod, type);
262  if ( z )
263  TYPMOD_SET_Z(typmod);
264  if ( m )
265  TYPMOD_SET_M(typmod);
266  }
267  }
268  if ( i == 1 ) /* SRID */
269  {
270  int srid = pg_atoi(DatumGetCString(elem_values[i]),
271  sizeof(int32), '\0');
272  srid = clamp_srid(srid);
273  POSTGIS_DEBUGF(3, "srid: %d", srid);
274  if ( srid != SRID_UNKNOWN )
275  {
276  TYPMOD_SET_SRID(typmod, srid);
277  }
278  }
279  }
280 
281  pfree(elem_values);
282 
283  return typmod;
284 }
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:347
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:197
#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
type
Definition: ovdump.py:41
#define TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:165
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: