Skip to content

Commit

Permalink
ENH: Added allow_superseded kwargs to TransformerGroup (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmahr1 authored Apr 11, 2023
1 parent 0aba9d5 commit e4d5abc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Change Log

Latest
------
- ENH: Added allow_superseded kwargs to :class:`pyproj.transformer.TransformerGroup` (pull #1269)

- ENH: Added :meth:`CRS.to_2d` to demote 3D CRS to 2D (issue #1266)

Expand Down
1 change: 1 addition & 0 deletions pyproj/_transformer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class _TransformerGroup:
authority: Optional[str],
accuracy: Optional[float],
allow_ballpark: bool,
allow_superseded: bool,
) -> None: ...

class _Transformer(Base):
Expand Down
6 changes: 6 additions & 0 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ cdef class _TransformerGroup:
bint allow_ballpark,
str authority,
double accuracy,
bint allow_superseded,
):
"""
From PROJ docs:
Expand Down Expand Up @@ -202,6 +203,11 @@ cdef class _TransformerGroup:
operation_factory_context,
allow_ballpark,
)
proj_operation_factory_context_set_discard_superseded(
self.context,
operation_factory_context,
not allow_superseded,
)
proj_operation_factory_context_set_grid_availability_use(
self.context,
operation_factory_context,
Expand Down
5 changes: 5 additions & 0 deletions pyproj/proj.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ cdef extern from "proj.h" nogil:
PJ_OPERATION_FACTORY_CONTEXT *factory_ctx,
int allow
)
void proj_operation_factory_context_set_discard_superseded(
PJ_CONTEXT *ctx,
PJ_OPERATION_FACTORY_CONTEXT *factory_ctx,
int discard
)
void proj_operation_factory_context_set_desired_accuracy(
PJ_CONTEXT *ctx,
PJ_OPERATION_FACTORY_CONTEXT *factory_ctx,
Expand Down
7 changes: 7 additions & 0 deletions pyproj/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ def __init__(
authority: Optional[str] = None,
accuracy: Optional[float] = None,
allow_ballpark: bool = True,
allow_superseded: bool = False,
) -> None:
"""Get all possible transformations from a :obj:`pyproj.crs.CRS`
or input used to create one.
.. versionadded:: 3.4.0 authority, accuracy, allow_ballpark
.. versionadded:: 3.6.0 allow_superseded
Parameters
----------
Expand Down Expand Up @@ -195,6 +197,10 @@ def __init__(
allow_ballpark: bool, default=True
Set to False to disallow the use of Ballpark transformation
in the candidate coordinate operations. Default is to allow.
allow_superseded: bool, default=False
Set to True to allow the use of superseded (but not deprecated)
transformations in the candidate coordinate operations. Default is
to disallow.
"""
super().__init__(
Expand All @@ -205,6 +211,7 @@ def __init__(
authority=authority,
accuracy=-1 if accuracy is None else accuracy,
allow_ballpark=allow_ballpark,
allow_superseded=allow_superseded,
)
for iii, transformer in enumerate(self._transformers):
# pylint: disable=unsupported-assignment-operation
Expand Down
17 changes: 17 additions & 0 deletions test/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,23 @@ def test_transformer_group_allow_ballpark_filter():
assert not group.unavailable_operations


@pytest.mark.parametrize(
"from_crs, to_crs, allow_superseded, expected_num_transformers",
[
(6319, 5703, 0, 2),
(6319, 5703, False, 2),
(6319, 5703, True, 3),
(6319, 5703, 123456789, 3),
(6319, 5703, "blah", 3),
],
)
def test_transformer_group_allow_superseded_filter(
from_crs, to_crs, allow_superseded, expected_num_transformers
):
group = TransformerGroup(from_crs, to_crs, allow_superseded=allow_superseded)
assert len(group.transformers) == expected_num_transformers


def test_transformer_group_authority_filter():
group = TransformerGroup("EPSG:4326", "EPSG:4258", authority="PROJ")
assert len(group.transformers) == 1
Expand Down

0 comments on commit e4d5abc

Please sign in to comment.