PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gserialized_typmod_in()

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

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

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