PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 148 of file g_util.c.

References dump_toupper(), GEOMTYPE_STRUCT_ARRAY_LEN, LW_FAILURE, LW_SUCCESS, lwalloc(), lwfree(), geomtype_struct::m, geomtype_struct::type, and geomtype_struct::z.

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

149 {
150  char *tmpstr;
151  int tmpstartpos, tmpendpos;
152  int i;
153 
154  assert(str);
155  assert(type);
156  assert(z);
157  assert(m);
158 
159  /* Initialize. */
160  *type = 0;
161  *z = 0;
162  *m = 0;
163 
164  /* Locate any leading/trailing spaces */
165  tmpstartpos = 0;
166  for (i = 0; i < strlen(str); i++)
167  {
168  if (str[i] != ' ')
169  {
170  tmpstartpos = i;
171  break;
172  }
173  }
174 
175  tmpendpos = strlen(str) - 1;
176  for (i = strlen(str) - 1; i >= 0; i--)
177  {
178  if (str[i] != ' ')
179  {
180  tmpendpos = i;
181  break;
182  }
183  }
184 
185  /* Copy and convert to upper case for comparison */
186  tmpstr = lwalloc(tmpendpos - tmpstartpos + 2);
187  for (i = tmpstartpos; i <= tmpendpos; i++)
188  tmpstr[i - tmpstartpos] = dump_toupper(str[i]);
189 
190  /* Add NULL to terminate */
191  tmpstr[i - tmpstartpos] = '\0';
192 
193  /* Now check for the type */
194  for (i = 0; i < GEOMTYPE_STRUCT_ARRAY_LEN; i++)
195  {
196  if (!strcmp(tmpstr, geomtype_struct_array[i].typename))
197  {
198  *type = geomtype_struct_array[i].type;
199  *z = geomtype_struct_array[i].z;
200  *m = geomtype_struct_array[i].m;
201 
202  lwfree(tmpstr);
203 
204  return LW_SUCCESS;
205  }
206 
207  }
208 
209  lwfree(tmpstr);
210 
211  return LW_FAILURE;
212 }
void lwfree(void *mem)
Definition: lwutil.c:214
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define LW_FAILURE
Definition: liblwgeom.h:64
struct geomtype_struct geomtype_struct_array[]
Definition: g_util.c:29
void * lwalloc(size_t size)
Definition: lwutil.c:199
static char dump_toupper(int in)
Definition: g_util.c:123
#define GEOMTYPE_STRUCT_ARRAY_LEN
Definition: g_util.c:112

Here is the call graph for this function:

Here is the caller graph for this function: