PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gserialized_typmod_in()

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

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

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:380
unsigned int int32
Definition: shpopen.c:273
#define TYPMOD_SET_Z(typmod)
Definition: liblwgeom.h:170
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:195
#define TYPMOD_SET_M(typmod)
Definition: liblwgeom.h:172
#define LW_FAILURE
Definition: liblwgeom.h:79
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
char * s
Definition: cu_in_wkt.c:23
#define TYPMOD_SET_TYPE(typmod, type)
Definition: liblwgeom.h:168
type
Definition: ovdump.py:41
#define TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:166
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: