-
Notifications
You must be signed in to change notification settings - Fork 887
Add interrupted projection for "sinu", "tmerc", "cass" and "poly" #4770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jjimenezshaw
wants to merge
6
commits into
OSGeo:master
Choose a base branch
from
jjimenezshaw:interrupted
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+355
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
23e4379
Add interrupted.cpp
jjimenezshaw 8efb7c4
add interrupted to the compilation and list of projections
jjimenezshaw 9b21921
consider gores param always a string
jjimenezshaw 632c166
add documentation for interrupted
jjimenezshaw 933fa76
gores doesn't have to be symmetric
jjimenezshaw cc92f85
add tests for interrupted
jjimenezshaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| .. _interrupted: | ||
|
|
||
| ******************************************************************************** | ||
| Interrupted | ||
| ******************************************************************************** | ||
|
|
||
| +---------------------+----------------------------------------------------------+ | ||
| | **Classification** | Interrupted meta-projection | | ||
| +---------------------+----------------------------------------------------------+ | ||
| | **Available forms** | Forward and inverse, spherical and ellipsoidal | | ||
| +---------------------+----------------------------------------------------------+ | ||
| | **Defined area** | Global | | ||
| +---------------------+----------------------------------------------------------+ | ||
| | **Alias** | interrupted | | ||
| +---------------------+----------------------------------------------------------+ | ||
| | **Domain** | 2D | | ||
| +---------------------+----------------------------------------------------------+ | ||
| | **Input type** | Geodetic coordinates | | ||
| +---------------------+----------------------------------------------------------+ | ||
| | **Output type** | Projected coordinates | | ||
| +---------------------+----------------------------------------------------------+ | ||
|
|
||
|
|
||
| .. figure:: ./images/interrupted.png | ||
| :width: 500 px | ||
| :align: center | ||
| :alt: Interrupted | ||
|
|
||
| proj-string: ``+proj=interrupted +base=sinu`` | ||
|
|
||
| Meta-projection to create interrupted maps using different base projections. | ||
| The supported projections are :ref:`cass`, :ref:`poly`, :ref:`sinu` and :ref:`tmerc`. | ||
| The world is divided in gores tangent at the equator. :cite:`Huck2024` | ||
|
|
||
| Parameters | ||
| ################################################################################ | ||
|
|
||
| .. note:: All parameters are optional for the Interrupted projection except ``base``. | ||
|
|
||
| .. option:: +base=<value> | ||
|
|
||
| Base projection. It can be one of ``cass``, ``poly``, ``sinu`` or ``tmerc``. | ||
| Note that some projections may not behave correctly with too wide gores. | ||
|
|
||
| .. option:: +gores=<value> | ||
|
|
||
| :option:`+gores` can be a number or a list of comma separated values. | ||
| When it is a single number, it is the number of equal gores. | ||
| When it is a list, they are the relative sizes of the gores (v.g. ``1,2,1``). | ||
|
|
||
| *Defaults to 3.* | ||
|
|
||
| .. include:: ../options/lon_0.rst | ||
|
|
||
| .. include:: ../options/ellps.rst | ||
|
|
||
| .. include:: ../options/R.rst | ||
|
|
||
| .. include:: ../options/x_0.rst | ||
|
|
||
| .. include:: ../options/y_0.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -404,6 +404,7 @@ gg | |
| gie | ||
| gimbal | ||
| Gitter | ||
| globemaking | ||
| gn | ||
| gnom | ||
| gnomonic | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| /* | ||
| * Implementation of meta interrupted projection for some pseudocylindrical | ||
| * | ||
| * Copyright (c) 2025 Javier Jimenez Shaw | ||
| * | ||
| */ | ||
|
|
||
| #include <errno.h> | ||
| #include <math.h> | ||
|
|
||
| #include <iostream> | ||
| #include <numeric> | ||
|
|
||
| #include "proj.h" | ||
| #include "proj_internal.h" | ||
|
|
||
| #define FROM_PROJ_CPP | ||
| #include "proj/internal/internal.hpp" | ||
|
|
||
| C_NAMESPACE PJ *pj_cass(PJ *); | ||
| C_NAMESPACE PJ *pj_poly(PJ *); | ||
| C_NAMESPACE PJ *pj_sinu(PJ *); | ||
| C_NAMESPACE PJ *pj_tmerc(PJ *); | ||
|
|
||
| PROJ_HEAD(interrupted, "Interrupted") "\n\tSph&Ell"; | ||
|
|
||
| namespace { // anonymous namespace | ||
| struct pj_interrupted_data { | ||
| PJ *base_pj; | ||
| std::vector<double> lam_borders; | ||
| std::vector<double> lam_centers; | ||
| std::vector<double> x_borders; | ||
| std::vector<double> x_centers; | ||
| }; | ||
| } // anonymous namespace | ||
|
|
||
| static PJ_XY interrupted_forward(PJ_LP lp, PJ *P) { | ||
| PJ_XY xy = {0.0, 0.0}; | ||
| struct pj_interrupted_data *Q = | ||
| static_cast<struct pj_interrupted_data *>(P->opaque); | ||
| double center_lam = 0; | ||
| double center_x = 0; | ||
| for (size_t i = 0; i < Q->lam_borders.size(); i++) { | ||
| if (lp.lam <= Q->lam_borders[i]) { | ||
| center_lam = Q->lam_centers[i]; | ||
| center_x = Q->x_centers[i]; | ||
| break; | ||
| } | ||
| } | ||
| lp.lam -= center_lam; | ||
| xy = Q->base_pj->fwd(lp, Q->base_pj); | ||
| xy.x += center_x; | ||
| return xy; | ||
| } | ||
|
|
||
| static PJ_LP interrupted_inverse(PJ_XY xy, PJ *P) { | ||
| PJ_LP lp = {0.0, 0.0}; | ||
|
|
||
| struct pj_interrupted_data *Q = | ||
| static_cast<struct pj_interrupted_data *>(P->opaque); | ||
|
|
||
| double center_lam = 0; | ||
| double center_x = 0; | ||
| double start_lam = 0; | ||
| double end_lam = 0; | ||
| for (size_t i = 0; i < Q->x_borders.size(); i++) { | ||
| if (xy.x <= Q->x_borders[i]) { | ||
| center_lam = Q->lam_centers[i]; | ||
| center_x = Q->x_centers[i]; | ||
| end_lam = (i + 1 != Q->x_borders.size()) ? Q->lam_borders[i] : M_PI; | ||
| start_lam = i > 0 ? Q->lam_borders[i - 1] : -M_PI; | ||
| break; | ||
| } | ||
| } | ||
| xy.x -= center_x; | ||
| lp = Q->base_pj->inv(xy, Q->base_pj); | ||
| lp.lam += center_lam; | ||
| if (lp.lam > end_lam || lp.lam < start_lam) { | ||
| proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN); | ||
| return lp; | ||
| } | ||
|
|
||
| return lp; | ||
| } | ||
|
|
||
| static PJ *interrupted_destructor(PJ *P, int errlev) { /* Destructor */ | ||
| if (nullptr == P) | ||
| return nullptr; | ||
| if (nullptr == P->opaque) | ||
| return pj_default_destructor(P, errlev); | ||
| proj_destroy(static_cast<struct pj_interrupted_data *>(P->opaque)->base_pj); | ||
|
|
||
| return pj_default_destructor(P, errlev); | ||
| } | ||
|
|
||
| PJ *PJ_PROJECTION(interrupted) { | ||
| struct pj_interrupted_data *Q = static_cast<struct pj_interrupted_data *>( | ||
| calloc(1, sizeof(struct pj_interrupted_data))); | ||
| if (nullptr == Q) | ||
| return pj_default_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); | ||
| P->opaque = Q; | ||
| P->destructor = interrupted_destructor; | ||
|
|
||
| std::string base; | ||
| if (pj_param(P->ctx, P->params, "tbase").i) { | ||
| base = pj_param(P->ctx, P->params, "sbase").s; | ||
| } | ||
| if (base != "cass" && base != "poly" && base != "sinu" && base != "tmerc") { | ||
| proj_log_error(P, _("Invalid value for base parameter")); | ||
| return pj_default_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); | ||
| } | ||
| std::vector<double> sizes; | ||
| if (pj_param(P->ctx, P->params, "tgores").i) { | ||
| const std::string g = pj_param(P->ctx, P->params, "sgores").s; | ||
| const std::vector<std::string> gores = | ||
| osgeo::proj::internal::split(g, ","); | ||
| bool success = true; | ||
| for (const auto &gore : gores) { | ||
| if (gore.empty()) | ||
| continue; | ||
| double d = osgeo::proj::internal::c_locale_stod(gore, success); | ||
| if (!success) { | ||
| proj_log_error(P, _("Invalid value for gores parameter")); | ||
| return pj_default_destructor( | ||
| P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); | ||
| } | ||
| sizes.push_back(d); | ||
| } | ||
| } else { | ||
| sizes.push_back(3.0); | ||
| } | ||
|
|
||
| if (sizes.size() == 1) { | ||
| sizes = std::vector<double>(static_cast<size_t>(sizes.front()), 1.0); | ||
| } | ||
| if (sizes.empty()) { | ||
| proj_log_error(P, _("Invalid 0 gores")); | ||
| return pj_default_destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); | ||
| } | ||
|
|
||
| auto get_fun_ptr = [&base]() { | ||
| if (base == "cass") { | ||
| return pj_cass; | ||
| } else if (base == "poly") { | ||
| return pj_poly; | ||
| } else if (base == "sinu") { | ||
| return pj_sinu; | ||
| } else if (base == "tmerc") { | ||
| return pj_tmerc; | ||
| } | ||
| return pj_sinu; | ||
| }; | ||
|
|
||
| Q->base_pj = get_fun_ptr()(nullptr); | ||
| if (Q->base_pj == nullptr) | ||
| return interrupted_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); | ||
| Q->base_pj->ctx = P->ctx; | ||
| Q->base_pj->es = P->es; | ||
| Q->base_pj->one_es = P->one_es; | ||
| Q->base_pj->k0 = P->k0; | ||
| Q->base_pj->f = P->f; | ||
| Q->base_pj->f2 = P->f2; | ||
| Q->base_pj->n = P->n; | ||
| Q->base_pj = get_fun_ptr()(Q->base_pj); | ||
| if (Q->base_pj == nullptr) | ||
| return interrupted_destructor(P, PROJ_ERR_OTHER /*ENOMEM*/); | ||
|
|
||
| const double total_size = std::accumulate(sizes.begin(), sizes.end(), 0.0); | ||
|
|
||
| // Compute center and east border of every gore in lambda (radians) | ||
| double lam_start = -M_PI; | ||
| std::vector<double> x_semi_widths; | ||
| for (auto &s : sizes) { | ||
| const double lam_semi_width = s * M_PI / total_size; | ||
| const auto x_swd = Q->base_pj->fwd({lam_semi_width, 0}, Q->base_pj); | ||
| x_semi_widths.push_back(x_swd.x); | ||
| const double lam_center = lam_start + lam_semi_width; | ||
| Q->lam_centers.push_back(lam_center); | ||
| const double lam_end = lam_start + lam_semi_width * 2; | ||
| Q->lam_borders.push_back(lam_end); | ||
| lam_start = lam_end; | ||
| } | ||
|
|
||
| // Compute center and east border of every gore in x | ||
| double x_start = | ||
| -std::accumulate(x_semi_widths.begin(), x_semi_widths.end(), 0.0); | ||
| for (auto &x_semi_width : x_semi_widths) { | ||
| const double x_center = x_start + x_semi_width; | ||
| Q->x_centers.push_back(x_center); | ||
| const double x_end = x_start + x_semi_width * 2.0; | ||
| Q->x_borders.push_back(x_end); | ||
| x_start = x_end; | ||
| } | ||
|
|
||
| // Add some marging to the last gore | ||
| Q->lam_borders.back() += 1.; | ||
| Q->x_borders.back() += 100.; | ||
|
|
||
| P->fwd = interrupted_forward; | ||
| P->inv = interrupted_inverse; | ||
|
|
||
| return P; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those parameters are the ones I found needed for the ellipsoidal projections. Do I need more? Is there already any function that copies them?