PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ proj_crs_is_swapped()

static uint8_t proj_crs_is_swapped ( const PJ *  pj_crs)
static

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

271 {
272  int axis_count;
273  PJ *pj_cs = proj_cs_get_simplecs(pj_crs);
274  if (!pj_cs)
275  lwerror("%s: proj_cs_get_simplecs returned NULL", __func__);
276 
277  axis_count = proj_cs_get_axis_count(NULL, pj_cs);
278  if (axis_count >= 2)
279  {
280  const char *out_name1, *out_abbrev1, *out_direction1;
281  const char *out_name2, *out_abbrev2, *out_direction2;
282  /* Read first axis */
283  proj_cs_get_axis_info(NULL,
284  pj_cs, 0,
285  &out_name1, &out_abbrev1, &out_direction1,
286  NULL, NULL, NULL, NULL);
287  /* Read second axis */
288  proj_cs_get_axis_info(NULL,
289  pj_cs, 1,
290  &out_name2, &out_abbrev2, &out_direction2,
291  NULL, NULL, NULL, NULL);
292 
293  proj_destroy(pj_cs);
294 
295  /* Directions agree, this is a northing/easting CRS, so reverse it */
296  if(out_direction1 && STR_IEQUALS(out_direction1, "north") &&
297  out_direction2 && STR_IEQUALS(out_direction2, "east") )
298  {
299  return LW_TRUE;
300  }
301 
302  /* Oddball case? Both axes north / both axes south, swap */
303  if(out_direction1 && out_direction2 &&
304  ((STR_IEQUALS(out_direction1, "north") && STR_IEQUALS(out_direction2, "north")) ||
305  (STR_IEQUALS(out_direction1, "south") && STR_IEQUALS(out_direction2, "south"))) &&
306  out_name1 && STR_ISTARTS(out_name1, "northing") &&
307  out_name2 && STR_ISTARTS(out_name2, "easting"))
308  {
309  return LW_TRUE;
310  }
311 
312  /* Any lat/lon system with Lat in first axis gets swapped */
313  if (STR_ISTARTS(out_abbrev1, "Lat"))
314  return LW_TRUE;
315 
316  return LW_FALSE;
317  }
318 
319  /* Failed the axis count test, leave quietly */
320  proj_destroy(pj_cs);
321  return LW_FALSE;
322 }
#define STR_ISTARTS(A, B)
static PJ * proj_cs_get_simplecs(const PJ *pj_crs)
#define STR_IEQUALS(A, B)
#define LW_FALSE
Definition: liblwgeom.h:108
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190

References LW_FALSE, LW_TRUE, lwerror(), proj_cs_get_simplecs(), STR_IEQUALS, and STR_ISTARTS.

Referenced by lwproj_from_PJ().

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