Skip to content
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

Add is_deprecated and get_non_deprecated() to CRS #1383

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Log
Latest
------
- DEP: Minimum supported Python version 3.10 (pull #1357)
- ENH: Add :meth:`CRS.is_deprecated` and :meth:`CRS.get_non_deprecated` (pull #1383)

3.6.1
------
Expand Down
3 changes: 3 additions & 0 deletions pyproj/_crs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ class _CRS(Base):
@property
def is_geocentric(self) -> bool: ...
def equals(self, other: Any, ignore_axis_order: bool) -> bool: ...
@property
def is_deprecated(self) -> bool: ...
def get_non_deprecated(self) -> list["_CRS"]: ...

def is_proj(proj_string: str) -> bool: ...
def is_wkt(proj_string: str) -> bool: ...
Expand Down
57 changes: 57 additions & 0 deletions pyproj/_crs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3203,3 +3203,60 @@ cdef class _CRS(Base):
if not isinstance(other, _CRS):
return False
return self._equals(other, ignore_axis_order=ignore_axis_order)

@property
def is_deprecated(self):
"""
.. versionadded:: 3.7.0

Check if the CRS is deprecated

Returns
-------
bool
"""
return bool(proj_is_deprecated(self.projobj))

def get_non_deprecated(self):
"""
.. versionadded:: 3.7.0

Return a list of non-deprecated objects related to this.

Returns
-------
list[_CRS]
"""

non_deprecated = []

cdef PJ_OBJ_LIST *proj_list = NULL
cdef int num_proj_objects = 0

proj_list = proj_get_non_deprecated(
self.context,
self.projobj
)
if proj_list != NULL:
num_proj_objects = proj_list_get_count(proj_list)

cdef PJ* proj = NULL
try:
for iii in range(num_proj_objects):
proj = proj_list_get(self.context, proj_list, iii)
non_deprecated.append(_CRS(_to_wkt(
self.context,
proj,
version=WktVersion.WKT2_2019,
pretty=False,
)))
proj_destroy(proj)
proj = NULL
finally:
# If there was an error we have to call proj_destroy
# If there was none, calling it on NULL does nothing
proj_destroy(proj)
proj_list_destroy(proj_list)
_clear_proj_error()

return non_deprecated
25 changes: 25 additions & 0 deletions pyproj/crs/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,31 @@ def is_derived(self):
"""
return self._crs.is_derived

@property
def is_deprecated(self) -> bool:
"""
.. versionadded:: 3.6.2
jjimenezshaw marked this conversation as resolved.
Show resolved Hide resolved

Check if the CRS is deprecated

Returns
-------
bool
"""
return self._crs.is_deprecated

def get_non_deprecated(self) -> list["CRS"]:
"""
.. versionadded:: 3.6.2
jjimenezshaw marked this conversation as resolved.
Show resolved Hide resolved

Return a list of non-deprecated objects related to this.

Returns
-------
list[CRS]
"""
return self._crs.get_non_deprecated()

def __eq__(self, other: Any) -> bool:
return self.equals(other)

Expand Down
3 changes: 3 additions & 0 deletions pyproj/proj.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,6 @@ cdef extern from "proj.h" nogil:
)
void proj_unit_list_destroy(PROJ_UNIT_INFO** list)
const char *proj_context_get_url_endpoint(PJ_CONTEXT* ctx)

int proj_is_deprecated(const PJ *obj)
PJ_OBJ_LIST *proj_get_non_deprecated(PJ_CONTEXT *ctx, const PJ *obj)
30 changes: 30 additions & 0 deletions test/crs/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,36 @@ def test_to_wkt_pretty():
assert "\n" not in crs.to_wkt()


def test_no_non_deprecated():
crs = CRS.from_epsg(4326)
assert not crs.is_deprecated
non_dep = crs.get_non_deprecated()
assert len(non_dep) == 0


def test_non_deprecated():
crs = CRS.from_epsg(28473)
assert crs.is_deprecated
non_dep = crs.get_non_deprecated()
assert len(non_dep) == 1
assert "EPSG:2503" == ":".join(non_dep[0].to_authority())


def test_non_deprecated_empty():
crs = CRS.from_epsg(3151)
assert crs.is_deprecated
assert len(crs.get_non_deprecated()) == 0


def test_non_deprecated_multiple():
crs = CRS.from_epsg(3315)
assert crs.is_deprecated
non_dep = [":".join(el.to_authority()) for el in crs.get_non_deprecated()]
assert len(non_dep) == 4
for elem in ["EPSG:3989", "EPSG:3988", "EPSG:3987", "EPSG:3986"]:
assert elem in non_dep


@pytest.mark.parametrize(
"version, expected",
[
Expand Down
Loading