PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwproj_from_string()

projPJ lwproj_from_string ( const char *  txt)

Get a projection from a string representation.

Eg: "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

Definition at line 173 of file liblwgeom/lwgeom_transform.c.

References lwalloc(), and lwfree().

Referenced by gml_reproject_pa(), and transform_geom().

174 {
175  int t;
176  char *params[1024]; /* one for each parameter */
177  char *loc;
178  char *str;
179  size_t slen;
180  projPJ result;
181 
182 
183  if (str1 == NULL) return NULL;
184 
185  slen = strlen(str1);
186 
187  if (slen == 0) return NULL;
188 
189  str = lwalloc(slen+1);
190  strcpy(str, str1);
191 
192  /*
193  * first we split the string into a bunch of smaller strings,
194  * based on the " " separator
195  */
196 
197  params[0] = str; /* 1st param, we'll null terminate at the " " soon */
198 
199  loc = str;
200  t = 1;
201  while ((loc != NULL) && (*loc != 0) )
202  {
203  loc = strchr(loc, ' ');
204  if (loc != NULL)
205  {
206  *loc = 0; /* null terminate */
207  params[t] = loc+1;
208  loc++; /* next char */
209  t++; /*next param */
210  }
211  }
212 
213  if (!(result=pj_init(t, params)))
214  {
215  lwfree(str);
216  return NULL;
217  }
218  lwfree(str);
219  return result;
220 }
void lwfree(void *mem)
Definition: lwutil.c:244
void * lwalloc(size_t size)
Definition: lwutil.c:229
Here is the call graph for this function:
Here is the caller graph for this function: