Skip to content

Commit

Permalink
REF: Skip transformations if 'noop' & deprecate 'skip_equivalent'
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Apr 10, 2021
1 parent 9818912 commit a9c5750
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 157 deletions.
10 changes: 2 additions & 8 deletions docs/advanced_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ Results: 6.32 µs ± 49.7 ns per loop (mean ± std. dev. of 7 runs, 100000 loops
Transforming with the same projections
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pyproj will skip transformations if they are exactly the same by default. However, if you
sometimes throw in the projections that are about the same and the results being close enough
is what you want, the `skip_equivalent` option can help.

.. note:: From PROJ code: The objects are equivalent for the purpose of coordinate operations.
They can differ by the name of their objects, identifiers, other metadata.
Parameters may be expressed in different units, provided that the value is
(with some tolerance) the same once expressed in a common unit.
pyproj skips `noop` transformations.


Transformation Group
--------------------
Expand Down
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Change Log
* ENH: Added :meth:`pyproj.crs.CRS.to_3d` (pull #808)
* ENH: Added :meth:`pyproj.transformer.Transformer.transform_bounds` (issue #809)
* ENH: Added :attr:`pyproj.crs.CRS.is_compound` (pull #823)
* REF: Skip transformations if `noop` & deprecate `skip_equivalent` (issue #782)

3.0.1
-----
Expand Down
6 changes: 0 additions & 6 deletions pyproj/_transformer.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ cdef class _TransformerGroup:
cdef class _Transformer(Base):
cdef PJ_PROJ_INFO proj_info
cdef readonly _area_of_use
cdef readonly skip_equivalent
cdef readonly projections_equivalent
cdef readonly projections_exact_same
cdef readonly type_name
cdef readonly object _operations

@staticmethod
cdef _Transformer _from_pj(
PJ_CONTEXT* context,
PJ *transform_pj,
_CRS crs_from,
_CRS crs_to,
skip_equivalent,
always_xy,
)
13 changes: 4 additions & 9 deletions pyproj/_transformer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class _TransformerGroup:
_best_available: bool
def __init__(
self,
crs_from: _CRS,
crs_to: _CRS,
skip_equivalent: bool = False,
crs_from: str,
crs_to: str,
always_xy: bool = False,
area_of_interest: Optional[AreaOfInterest] = None,
) -> None: ...
Expand All @@ -43,9 +42,6 @@ class _Transformer(Base):
input_geographic: bool
output_geographic: bool
is_pipeline: bool
skip_equivalent: bool
projections_equivalent: bool
projections_exact_same: bool
type_name: str
@property
def id(self) -> str: ...
Expand All @@ -70,9 +66,8 @@ class _Transformer(Base):
) -> str: ...
@staticmethod
def from_crs(
crs_from: _CRS,
crs_to: _CRS,
skip_equivalent: bool = False,
crs_from: str,
crs_to: str,
always_xy: bool = False,
area_of_interest: Optional[AreaOfInterest] = None,
authority: Optional[str] = None,
Expand Down
62 changes: 10 additions & 52 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ cdef class _TransformerGroup:
self,
_CRS crs_from,
_CRS crs_to,
skip_equivalent=False,
always_xy=False,
area_of_interest=None,
):
Expand Down Expand Up @@ -201,9 +200,6 @@ cdef class _TransformerGroup:
_Transformer._from_pj(
context,
pj_transform,
crs_from,
crs_to,
skip_equivalent,
always_xy,
)
)
Expand Down Expand Up @@ -503,9 +499,6 @@ cdef double antimeridian_max(double* data, Py_ssize_t arr_len) nogil:
cdef class _Transformer(Base):
def __cinit__(self):
self._area_of_use = None
self.skip_equivalent = False
self.projections_equivalent = False
self.projections_exact_same = False
self.type_name = "Unknown Transformer"
self._operations = None

Expand Down Expand Up @@ -598,9 +591,8 @@ cdef class _Transformer(Base):

@staticmethod
def from_crs(
_CRS crs_from,
_CRS crs_to,
skip_equivalent=False,
const char* crs_from,
const char* crs_to,
always_xy=False,
area_of_interest=None,
authority=None,
Expand Down Expand Up @@ -638,8 +630,8 @@ cdef class _Transformer(Base):
transformer.context = pyproj_context_create()
transformer.projobj = proj_create_crs_to_crs(
transformer.context,
cstrencode(crs_from.srs),
cstrencode(crs_to.srs),
crs_from,
crs_to,
pj_area_of_interest,
authority=authority,
accuracy=accuracy,
Expand All @@ -652,21 +644,13 @@ cdef class _Transformer(Base):
if transformer.projobj == NULL:
raise ProjError("Error creating Transformer from CRS.")

transformer._init_from_crs(
crs_from=crs_from,
crs_to=crs_to,
skip_equivalent=skip_equivalent,
always_xy=always_xy,
)
transformer._init_from_crs(always_xy)
return transformer

@staticmethod
cdef _Transformer _from_pj(
PJ_CONTEXT* context,
PJ *transform_pj,
_CRS crs_from,
_CRS crs_to,
skip_equivalent,
always_xy,
):
"""
Expand All @@ -679,12 +663,7 @@ cdef class _Transformer(Base):
if transformer.projobj == NULL:
raise ProjError("Error creating Transformer.")

transformer._init_from_crs(
crs_from=crs_from,
crs_to=crs_to,
skip_equivalent=skip_equivalent,
always_xy=always_xy,
)
transformer._init_from_crs(always_xy)
return transformer

@staticmethod
Expand Down Expand Up @@ -729,22 +708,13 @@ cdef class _Transformer(Base):
proj_destroy(self.projobj)
self.projobj = always_xy_pj

def _init_from_crs(
self,
_CRS crs_from,
_CRS crs_to,
skip_equivalent,
always_xy,
):
def _init_from_crs(self, always_xy):
"""
Finish initializing transformer properties from CRS objects
"""
if always_xy:
self._set_always_xy()
self._initialize_from_projobj()
self.projections_exact_same = crs_from.is_exact_same(crs_to)
self.projections_equivalent = crs_from == crs_to
self.skip_equivalent = skip_equivalent

@cython.boundscheck(False)
@cython.wraparound(False)
Expand All @@ -758,11 +728,7 @@ cdef class _Transformer(Base):
bint radians,
bint errcheck,
):
if (
self.projections_exact_same
or (self.projections_equivalent and self.skip_equivalent)
or self.id == "noop"
):
if self.id == "noop":
return

tmp_pj_direction = _PJ_DIRECTION_MAP[TransformDirection.create(direction)]
Expand Down Expand Up @@ -853,11 +819,7 @@ cdef class _Transformer(Base):
bint radians,
bint errcheck,
):
if (
self.projections_exact_same
or (self.projections_equivalent and self.skip_equivalent)
or self.id == "noop"
):
if self.id == "noop":
return
tmp_pj_direction = _PJ_DIRECTION_MAP[TransformDirection.create(direction)]
cdef PJ_DIRECTION pj_direction = <PJ_DIRECTION>tmp_pj_direction
Expand Down Expand Up @@ -956,11 +918,7 @@ cdef class _Transformer(Base):
bint errcheck,
object direction,
):
if (
self.projections_exact_same
or (self.projections_equivalent and self.skip_equivalent)
or self.id == "noop"
):
if self.id == "noop":
return (left, bottom, right, top)

if densify_pts < 0:
Expand Down
Loading

0 comments on commit a9c5750

Please sign in to comment.