PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ geometry_type_from_string()

int geometry_type_from_string ( const char *  str,
uint8_t *  type,
int *  z,
int *  m 
)

Utility function to get type number from string.

For example, a string 'POINTZ' would return type of 1 and z of 1 and m of 0. Valid

Utility function to get type number from string.

Case insensitive, and insensitive to spaces at front and back. Type == 0 in the case of the string "GEOMETRY" or "GEOGRAPHY". Return LW_SUCCESS for success.

Definition at line 489 of file lwutil.c.

490 {
491  char *tmpstr;
492  size_t tmpstartpos, tmpendpos;
493  size_t i;
494 
495  assert(str);
496  assert(type);
497  assert(z);
498  assert(m);
499 
500  /* Initialize. */
501  *type = 0;
502  *z = 0;
503  *m = 0;
504 
505  /* Locate any leading/trailing spaces */
506  tmpstartpos = 0;
507  for (i = 0; i < strlen(str); i++)
508  {
509  if (str[i] != ' ')
510  {
511  tmpstartpos = i;
512  break;
513  }
514  }
515 
516  tmpendpos = strlen(str) - 1;
517  for (i = strlen(str) - 1; i != 0; i--)
518  {
519  if (str[i] != ' ')
520  {
521  tmpendpos = i;
522  break;
523  }
524  }
525 
526  /* Copy and convert to upper case for comparison */
527  tmpstr = lwalloc(tmpendpos - tmpstartpos + 2);
528  for (i = tmpstartpos; i <= tmpendpos; i++)
529  tmpstr[i - tmpstartpos] = dumb_toupper(str[i]);
530 
531  /* Add NULL to terminate */
532  tmpstr[i - tmpstartpos] = '\0';
533 
534  /* Now check for the type */
535  for (i = 0; i < GEOMTYPE_STRUCT_ARRAY_LEN; i++)
536  {
537  if (!strcmp(tmpstr, geomtype_struct_array[i].typename))
538  {
540  *z = geomtype_struct_array[i].z;
541  *m = geomtype_struct_array[i].m;
542 
543  lwfree(tmpstr);
544 
545  return LW_SUCCESS;
546  }
547 
548  }
549 
550  lwfree(tmpstr);
551 
552  return LW_FAILURE;
553 }
#define LW_FAILURE
Definition: liblwgeom.h:110
#define LW_SUCCESS
Definition: liblwgeom.h:111
#define str(s)
static char dumb_toupper(int in)
Definition: lwutil.c:464
void lwfree(void *mem)
Definition: lwutil.c:242
#define GEOMTYPE_STRUCT_ARRAY_LEN
Definition: lwutil.c:453
void * lwalloc(size_t size)
Definition: lwutil.c:227
struct geomtype_struct geomtype_struct_array[]
Definition: lwutil.c:370
type
Definition: ovdump.py:42

References dumb_toupper(), geomtype_struct_array, GEOMTYPE_STRUCT_ARRAY_LEN, LW_FAILURE, LW_SUCCESS, lwalloc(), lwfree(), geomtype_struct::m, str, geomtype_struct::type, ovdump::type, and geomtype_struct::z.

Referenced by getTableInfo(), gserialized_typmod_in(), and test_geometry_type_from_string().

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