/
| 634 | |
| 635 | /*************************************************************************************/ |
| 636 | static int cs2cs_emulation_setup (PJ *P) { |
| 637 | /************************************************************************************** |
| 638 | If any cs2cs style modifiers are given (axis=..., towgs84=..., ) create the 4D API |
| 639 | equivalent operations, so the preparation and finalization steps in the pj_inv/pj_fwd |
| 640 | invocators can emulate the behavior of pj_transform and the cs2cs app. |
| 641 | |
| 642 | Returns 1 on success, 0 on failure |
| 643 | **************************************************************************************/ |
| 644 | PJ *Q; |
| 645 | paralist *p; |
| 646 | int do_cart = 0; |
| 647 | if (nullptr==P) |
| 648 | return 0; |
| 649 | |
| 650 | /* Don't recurse when calling proj_create (which calls us back) */ |
| 651 | if (pj_param_exists (P->params, "break_cs2cs_recursion")) |
| 652 | return 1; |
| 653 | |
| 654 | /* Swap axes? */ |
| 655 | p = pj_param_exists (P->params, "axis"); |
| 656 | |
| 657 | const bool disable_grid_presence_check = pj_param_exists ( |
| 658 | P->params, "disable_grid_presence_check") != nullptr; |
| 659 | |
| 660 | /* Don't axisswap if data are already in "enu" order */ |
| 661 | if (p && (0!=strcmp ("enu", p->param))) { |
| 662 | char *def = static_cast<char*>(malloc (100+strlen(P->axis))); |
| 663 | if (nullptr==def) |
| 664 | return 0; |
| 665 | sprintf (def, "break_cs2cs_recursion proj=axisswap axis=%s", P->axis); |
| 666 | Q = pj_create_internal (P->ctx, def); |
| 667 | free (def); |
| 668 | if (nullptr==Q) |
| 669 | return 0; |
| 670 | P->axisswap = skip_prep_fin(Q); |
| 671 | } |
| 672 | |
| 673 | /* Geoid grid(s) given? */ |
| 674 | p = pj_param_exists (P->params, "geoidgrids"); |
| 675 | if (!disable_grid_presence_check && p && strlen (p->param) > strlen ("geoidgrids=")) { |
| 676 | char *gridnames = p->param + strlen ("geoidgrids="); |
| 677 | char *def = static_cast<char*>(malloc (100+2*strlen(gridnames))); |
| 678 | if (nullptr==def) |
| 679 | return 0; |
| 680 | sprintf (def, "break_cs2cs_recursion proj=vgridshift grids=%s", |
| 681 | pj_double_quote_string_param_if_needed(gridnames).c_str()); |
| 682 | Q = pj_create_internal (P->ctx, def); |
| 683 | free (def); |
| 684 | if (nullptr==Q) |
| 685 | return 0; |
| 686 | P->vgridshift = skip_prep_fin(Q); |
| 687 | } |
| 688 | |
| 689 | /* Datum shift grid(s) given? */ |
| 690 | p = pj_param_exists (P->params, "nadgrids"); |
| 691 | if (!disable_grid_presence_check && p && strlen (p->param) > strlen ("nadgrids=")) { |
| 692 | char *gridnames = p->param + strlen ("nadgrids="); |
| 693 | char *def = static_cast<char*>(malloc (100+2*strlen(gridnames))); |
no test coverage detected