PostGIS  2.5.7dev-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.

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 }
char * s
Definition: cu_in_wkt.c:23
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 TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:166
#define LW_FAILURE
Definition: liblwgeom.h:79
#define TYPMOD_SET_TYPE(typmod, type)
Definition: liblwgeom.h:168
#define SRID_DEFAULT
Definition: liblwgeom.h:198
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
#define TYPMOD_SET_M(typmod)
Definition: liblwgeom.h:172
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
#define TYPMOD_SET_Z(typmod)
Definition: liblwgeom.h:170
type
Definition: ovdump.py:41
unsigned int int32
Definition: shpopen.c:273
unsigned char uint8_t
Definition: uthash.h:79

References clamp_srid(), geometry_type_from_string(), LW_FAILURE, 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().

Here is the call graph for this function:
Here is the caller graph for this function: