Skip to content

Commit

Permalink
ENH: Added get_database_metadata (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Nov 6, 2021
1 parent 61ece93 commit 3084961
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/api/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ pyproj.database.query_utm_crs_info
-----------------------------------

.. autofunction:: pyproj.database.query_utm_crs_info


pyproj.database.get_database_metadata
---------------------------------------

.. autofunction:: pyproj.database.get_database_metadata
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Latest
- ENH: Add support for transforming bounds at the poles in :meth:`pyproj.transformer.Transformer.transform_bounds` (pull #962)
- ENH: Added :attr:`pyproj.transformer.Transformer.source_crs` & :attr:`pyproj.transformer.Transformer.target_crs` (pull #976)
- ENH: Added :class:`pyproj.crs.coordinate_operation.PoleRotationNetCDFCFConversion` (issue #948)
- ENH: Added :func:`pyproj.database.get_database_metadata` (issue #990)

3.2.1
------
Expand Down
2 changes: 2 additions & 0 deletions pyproj/database.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ def query_crs_info(
contains: bool = False,
allow_deprecated: bool = False,
) -> List[CRSInfo]: ...

def get_database_metadata(key: str) -> Optional[str]: ...
45 changes: 45 additions & 0 deletions pyproj/database.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,48 @@ def get_units_map(str auth_name=None, str category=None, bint allow_deprecated=F
proj_unit_list_destroy(db_unit_list)
pyproj_context_destroy(context)
return units_map


def get_database_metadata(str key not None):
"""
Return metadata from the database.
Available keys:
- DATABASE.LAYOUT.VERSION.MAJOR
- DATABASE.LAYOUT.VERSION.MINOR
- EPSG.VERSION
- EPSG.DATE
- ESRI.VERSION
- ESRI.DATE
- IGNF.SOURCE
- IGNF.VERSION
- IGNF.DATE
- NKG.SOURCE
- NKG.VERSION
- NKG.DATE
- PROJ.VERSION
- PROJ_DATA.VERSION : PROJ-data version most compatible with this database.
Parameters
----------
key: str
The name of the metadata item to get data for.
Returns
-------
Optional[str]:
The metatada information if available.
"""
cdef PJ_CONTEXT* context = pyproj_context_create()
cdef const char* metadata = NULL
try:
metadata = proj_context_get_database_metadata(
context,
cstrdecode(key),
)
if metadata == NULL:
return None
return metadata
finally:
pyproj_context_destroy(context)
5 changes: 3 additions & 2 deletions pyproj/proj.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ cdef extern from "proj.h" nogil:
const char *dbPath,
const char *const *auxDbPaths,
const char* const *options)
void proj_context_set_ca_bundle_path(PJ_CONTEXT *ctx, const char *path);

void proj_context_set_ca_bundle_path(PJ_CONTEXT *ctx, const char *path)
const char *proj_context_get_database_metadata(PJ_CONTEXT* ctx,
const char* key)
ctypedef struct PJ
ctypedef struct PJ_CONTEXT
PJ_CONTEXT *proj_context_create ()
Expand Down
11 changes: 11 additions & 0 deletions test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Unit,
get_authorities,
get_codes,
get_database_metadata,
get_units_map,
query_crs_info,
query_utm_crs_info,
Expand Down Expand Up @@ -249,3 +250,13 @@ def test_query_utm_crs_info__aoi_contains():
assert crs_info.auth_name == "EPSG"
assert crs_info.type == PJType.PROJECTED_CRS
assert not crs_info.deprecated


def test_get_database_metadata():
epsg_version = get_database_metadata("EPSG.VERSION")
assert epsg_version
assert isinstance(epsg_version, str)


def test_get_database_metadata__invalid():
assert get_database_metadata("doesnotexist") is None

0 comments on commit 3084961

Please sign in to comment.