51{
52 uint8_t source_is_latlong =
LW_FALSE;
53 double semi_major_metre = DBL_MAX, semi_minor_metre = DBL_MAX;
54
55
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
64
65
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
103 PJ* pj_norm = proj_normalize_for_visualization(PJ_DEFAULT_CTX, pj);
104
105 if (!pj_norm)
106 pj_norm = pj;
107
108 else if (pj != pj_norm)
109 proj_destroy(pj);
110
111
118 return lp;
119}
void * lwalloc(size_t size)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
uint8_t source_is_latlong
double source_semi_major_metre
double source_semi_minor_metre