Skip to content

Commit

Permalink
Add OSRGetAuthorityListFromDatabase() to get the list of CRS authorit…
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 26, 2024
1 parent cdb5ea6 commit 41500e1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions autotest/osr/osr_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2478,3 +2478,13 @@ def test_osr_basic_export_wkt_utm_south():

j = json.loads(srs.ExportToPROJJSON())
assert j["conversion"]["id"]["code"] == 16101


###############################################################################


def test_osr_basic_GetAuthorityListFromDatabase():

ret = osr.GetAuthorityListFromDatabase()
assert "EPSG" in ret
assert "PROJ" in ret
2 changes: 2 additions & 0 deletions ogr/ogr_srs_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,8 @@ OSRGetCRSInfoListFromDatabase(const char *pszAuthName,

void CPL_DLL OSRDestroyCRSInfoList(OSRCRSInfo **list);

char CPL_DLL **OSRGetAuthorityListFromDatabase(void);

/* -------------------------------------------------------------------- */
/* OGRCoordinateTransform C API. */
/* -------------------------------------------------------------------- */
Expand Down
32 changes: 32 additions & 0 deletions ogr/ogrspatialreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12854,6 +12854,38 @@ void OSRDestroyCRSInfoList(OSRCRSInfo **list)
}
}

/************************************************************************/
/* OSRGetAuthorityListFromDatabase() */
/************************************************************************/

/** \brief Return the list of CRS authorities used in the PROJ database.
*
* Such as "EPSG", "ESRI", "PROJ", "IGNF", "IAU_2015", etc.
*
* This is a direct mapping of https://proj.org/en/latest/development/reference/functions.html#c.proj_get_authorities_from_database
*
* @return nullptr in case of error, or a NULL terminated list of strings to
* free with CSLDestroy()
* @since GDAL 3.10
*/
char **OSRGetAuthorityListFromDatabase()
{
PROJ_STRING_LIST list =
proj_get_authorities_from_database(OSRGetProjTLSContext());
if (!list)
{
return nullptr;
}
int count = 0;
while (list[count])
++count;
char **res = static_cast<char **>(CPLCalloc(count + 1, sizeof(char *)));
for (int i = 0; i < count; ++i)
res[i] = CPLStrdup(list[i]);
proj_string_list_destroy(list);
return res;
}

/************************************************************************/
/* UpdateCoordinateSystemFromGeogCRS() */
/************************************************************************/
Expand Down
9 changes: 9 additions & 0 deletions swig/include/osr.i
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,15 @@ const char* OSRCRSInfo_projection_method_get( OSRCRSInfo *crsInfo ) {

#endif

%apply (char **CSL) {(char **)};
%inline %{
char** GetAuthorityListFromDatabase()
{
return OSRGetAuthorityListFromDatabase();
}
%}
%clear (char **);

#ifdef SWIGPYTHON
%inline %{
void GetCRSInfoListFromDatabase( const char *authName,
Expand Down

0 comments on commit 41500e1

Please sign in to comment.