| 188 | // --------------------------------------------------------------------------- |
| 189 | |
| 190 | static PJ *pj_obj_create(PJ_CONTEXT *ctx, const IdentifiedObjectNNPtr &objIn) { |
| 191 | auto coordop = dynamic_cast<const CoordinateOperation *>(objIn.get()); |
| 192 | if (coordop) { |
| 193 | auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); |
| 194 | try { |
| 195 | auto formatter = PROJStringFormatter::create( |
| 196 | PROJStringFormatter::Convention::PROJ_5, dbContext); |
| 197 | auto projString = coordop->exportToPROJString(formatter.get()); |
| 198 | if (proj_context_is_network_enabled(ctx)) { |
| 199 | ctx->defer_grid_opening = true; |
| 200 | } |
| 201 | auto pj = pj_create_internal(ctx, projString.c_str()); |
| 202 | ctx->defer_grid_opening = false; |
| 203 | if (pj) { |
| 204 | pj->iso_obj = objIn; |
| 205 | return pj; |
| 206 | } |
| 207 | } catch (const std::exception &) { |
| 208 | // Silence, since we may not always be able to export as a |
| 209 | // PROJ string. |
| 210 | } |
| 211 | } |
| 212 | auto pj = pj_new(); |
| 213 | if (pj) { |
| 214 | pj->ctx = ctx; |
| 215 | pj->descr = "ISO-19111 object"; |
| 216 | pj->iso_obj = objIn; |
| 217 | try { |
| 218 | auto crs = dynamic_cast<const CRS *>(objIn.get()); |
| 219 | if (crs) { |
| 220 | auto geodCRS = crs->extractGeodeticCRS(); |
| 221 | if (geodCRS) { |
| 222 | const auto &ellps = geodCRS->ellipsoid(); |
| 223 | const double a = ellps->semiMajorAxis().getSIValue(); |
| 224 | const double es = ellps->squaredEccentricity(); |
| 225 | pj_calc_ellipsoid_params(pj, a, es); |
| 226 | assert(pj->geod == nullptr); |
| 227 | pj->geod = static_cast<struct geod_geodesic *>( |
| 228 | calloc(1, sizeof(struct geod_geodesic))); |
| 229 | if (pj->geod) { |
| 230 | geod_init(pj->geod, pj->a, |
| 231 | pj->es / (1 + sqrt(pj->one_es))); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | } catch (const std::exception &) { |
| 236 | } |
| 237 | } |
| 238 | return pj; |
| 239 | } |
| 240 | //! @endcond |
| 241 | |
| 242 | // --------------------------------------------------------------------------- |
no test coverage detected