PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwproj_from_PJ()

LWPROJ* lwproj_from_PJ ( PJ *  pj,
int8_t  extra_geography_data 
)

Allocate a new LWPROJ containing the reference to the PROJ's PJ If extra_geography_data is true, it will generate the following values for the source srs: is_latlong (geometric or not) and spheroid values.

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

326 {
327  PJ *pj_source_crs = proj_get_source_crs(NULL, pj);
328  uint8_t source_is_latlong = LW_FALSE;
329  double out_semi_major_metre = DBL_MAX, out_semi_minor_metre = DBL_MAX;
330 
331  if (!pj_source_crs)
332  {
333  lwerror("%s: unable to access source crs", __func__);
334  return NULL;
335  }
336  uint8_t source_swapped = proj_crs_is_swapped(pj_source_crs);
337 
338  /* We only care about the extra values if there is no transformation */
339  if (!extra_geography_data)
340  {
341  proj_destroy(pj_source_crs);
342  }
343  else
344  {
345  PJ *pj_ellps;
346  double out_inv_flattening;
347  int out_is_semi_minor_computed;
348 
349  PJ_TYPE pj_type = proj_get_type(pj_source_crs);
350  if (pj_type == PJ_TYPE_UNKNOWN)
351  {
352  proj_destroy(pj_source_crs);
353  lwerror("%s: unable to access source crs type", __func__);
354  return NULL;
355  }
356  source_is_latlong = (pj_type == PJ_TYPE_GEOGRAPHIC_2D_CRS) || (pj_type == PJ_TYPE_GEOGRAPHIC_3D_CRS);
357 
358  pj_ellps = proj_get_ellipsoid(NULL, pj_source_crs);
359  proj_destroy(pj_source_crs);
360  if (!pj_ellps)
361  {
362  lwerror("%s: unable to access source crs ellipsoid", __func__);
363  return NULL;
364  }
365  if (!proj_ellipsoid_get_parameters(NULL,
366  pj_ellps,
367  &out_semi_major_metre,
368  &out_semi_minor_metre,
369  &out_is_semi_minor_computed,
370  &out_inv_flattening))
371  {
372  proj_destroy(pj_ellps);
373  lwerror("%s: unable to access source crs ellipsoid parameters", __func__);
374  return NULL;
375  }
376  proj_destroy(pj_ellps);
377  }
378 
379  PJ *pj_target_crs = proj_get_target_crs(NULL, pj);
380  if (!pj_target_crs)
381  {
382  lwerror("%s: unable to access target crs", __func__);
383  return NULL;
384  }
385  uint8_t target_swapped = proj_crs_is_swapped(pj_target_crs);
386  proj_destroy(pj_target_crs);
387 
388  LWPROJ *lp = lwalloc(sizeof(LWPROJ));
389  lp->pj = pj;
390  lp->source_swapped = source_swapped;
391  lp->target_swapped = target_swapped;
392  lp->source_is_latlong = source_is_latlong;
393  lp->source_semi_major_metre = out_semi_major_metre;
394  lp->source_semi_minor_metre = out_semi_minor_metre;
395 
396  return lp;
397 }
static uint8_t proj_crs_is_swapped(const PJ *pj_crs)
#define LW_FALSE
Definition: liblwgeom.h:108
void * lwalloc(size_t size)
Definition: lwutil.c:227
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint8_t source_is_latlong
Definition: liblwgeom.h:61
uint8_t source_swapped
Definition: liblwgeom.h:58
uint8_t target_swapped
Definition: liblwgeom.h:59
double source_semi_major_metre
Definition: liblwgeom.h:64
double source_semi_minor_metre
Definition: liblwgeom.h:65
PJ * pj
Definition: liblwgeom.h:56

References LW_FALSE, lwalloc(), lwerror(), LWPROJ::pj, proj_crs_is_swapped(), LWPROJ::source_is_latlong, LWPROJ::source_semi_major_metre, LWPROJ::source_semi_minor_metre, LWPROJ::source_swapped, and LWPROJ::target_swapped.

Referenced by gml_reproject_pa(), and lwgeom_transform_from_str().

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