PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwproj_from_str()

LWPROJ* lwproj_from_str ( const char *  str_in,
const char *  str_out 
)

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 50 of file liblwgeom/lwgeom_transform.c.

51 {
52  uint8_t source_is_latlong = LW_FALSE;
53  double semi_major_metre = DBL_MAX, semi_minor_metre = DBL_MAX;
54 
55  /* Usable inputs? */
56  if (! (str_in && str_out))
57  return NULL;
58 
59  PJ* pj = proj_create_crs_to_crs(PJ_DEFAULT_CTX, str_in, str_out, NULL);
60  if (!pj)
61  return NULL;
62 
63  /* Fill in geodetic parameter information when a null-transform */
64  /* is passed, because that's how we signal we want to store */
65  /* that info in the cache */
66  if (strcmp(str_in, str_out) == 0)
67  {
68  PJ *pj_source_crs = proj_get_source_crs(PJ_DEFAULT_CTX, pj);
69  PJ *pj_ellps;
70  PJ_TYPE pj_type = proj_get_type(pj_source_crs);
71  if (pj_type == PJ_TYPE_UNKNOWN)
72  {
73  proj_destroy(pj);
74  lwerror("%s: unable to access source crs type", __func__);
75  return NULL;
76  }
77  source_is_latlong = (pj_type == PJ_TYPE_GEOGRAPHIC_2D_CRS) || (pj_type == PJ_TYPE_GEOGRAPHIC_3D_CRS);
78 
79  pj_ellps = proj_get_ellipsoid(PJ_DEFAULT_CTX, pj_source_crs);
80  proj_destroy(pj_source_crs);
81  if (!pj_ellps)
82  {
83  proj_destroy(pj);
84  lwerror("%s: unable to access source crs ellipsoid", __func__);
85  return NULL;
86  }
87  if (!proj_ellipsoid_get_parameters(PJ_DEFAULT_CTX,
88  pj_ellps,
89  &semi_major_metre,
90  &semi_minor_metre,
91  NULL,
92  NULL))
93  {
94  proj_destroy(pj_ellps);
95  proj_destroy(pj);
96  lwerror("%s: unable to access source crs ellipsoid parameters", __func__);
97  return NULL;
98  }
99  proj_destroy(pj_ellps);
100  }
101 
102  /* Add in an axis swap if necessary */
103  PJ* pj_norm = proj_normalize_for_visualization(PJ_DEFAULT_CTX, pj);
104  /* Swap failed for some reason? Fall back to coordinate operation */
105  if (!pj_norm)
106  pj_norm = pj;
107  /* Swap is not a copy of input? Clean up input */
108  else if (pj != pj_norm)
109  proj_destroy(pj);
110 
111  /* Allocate and populate return value */
112  LWPROJ *lp = lwalloc(sizeof(LWPROJ));
113  lp->pj = pj_norm; /* Caller is going to have to explicitly proj_destroy this */
114  lp->pipeline_is_forward = true;
115  lp->source_is_latlong = source_is_latlong;
116  lp->source_semi_major_metre = semi_major_metre;
117  lp->source_semi_minor_metre = semi_minor_metre;
118  return lp;
119 }
#define LW_FALSE
Definition: liblwgeom.h:94
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
bool pipeline_is_forward
Definition: liblwgeom.h:49
uint8_t source_is_latlong
Definition: liblwgeom.h:52
double source_semi_major_metre
Definition: liblwgeom.h:54
double source_semi_minor_metre
Definition: liblwgeom.h:55
PJ * pj
Definition: liblwgeom.h:46

References LW_FALSE, lwalloc(), lwerror(), LWPROJ::pipeline_is_forward, LWPROJ::pj, LWPROJ::source_is_latlong, LWPROJ::source_semi_major_metre, and LWPROJ::source_semi_minor_metre.

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: