PostGIS  2.1.10dev-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 149 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: