PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geometry_type_from_string()

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

Calculate type integer and dimensional flags from string input.

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 163 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().

164 {
165  char *tmpstr;
166  int tmpstartpos, tmpendpos;
167  int i;
168 
169  assert(str);
170  assert(type);
171  assert(z);
172  assert(m);
173 
174  /* Initialize. */
175  *type = 0;
176  *z = 0;
177  *m = 0;
178 
179  /* Locate any leading/trailing spaces */
180  tmpstartpos = 0;
181  for (i = 0; i < strlen(str); i++)
182  {
183  if (str[i] != ' ')
184  {
185  tmpstartpos = i;
186  break;
187  }
188  }
189 
190  tmpendpos = strlen(str) - 1;
191  for (i = strlen(str) - 1; i >= 0; i--)
192  {
193  if (str[i] != ' ')
194  {
195  tmpendpos = i;
196  break;
197  }
198  }
199 
200  /* Copy and convert to upper case for comparison */
201  tmpstr = lwalloc(tmpendpos - tmpstartpos + 2);
202  for (i = tmpstartpos; i <= tmpendpos; i++)
203  tmpstr[i - tmpstartpos] = dump_toupper(str[i]);
204 
205  /* Add NULL to terminate */
206  tmpstr[i - tmpstartpos] = '\0';
207 
208  /* Now check for the type */
209  for (i = 0; i < GEOMTYPE_STRUCT_ARRAY_LEN; i++)
210  {
211  if (!strcmp(tmpstr, geomtype_struct_array[i].typename))
212  {
214  *z = geomtype_struct_array[i].z;
215  *m = geomtype_struct_array[i].m;
216 
217  lwfree(tmpstr);
218 
219  return LW_SUCCESS;
220  }
221 
222  }
223 
224  lwfree(tmpstr);
225 
226  return LW_FAILURE;
227 }
void lwfree(void *mem)
Definition: lwutil.c:244
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define LW_FAILURE
Definition: liblwgeom.h:79
struct geomtype_struct geomtype_struct_array[]
Definition: g_util.c:44
type
Definition: ovdump.py:41
void * lwalloc(size_t size)
Definition: lwutil.c:229
static char dump_toupper(int in)
Definition: g_util.c:138
#define GEOMTYPE_STRUCT_ARRAY_LEN
Definition: g_util.c:127
Here is the call graph for this function:
Here is the caller graph for this function: