Skip to content

Commit 2c12b7a

Browse files
authored
Merge pull request #11130 from rouault/OSRGetAuthorityListFromDatabase
Add OSRGetAuthorityListFromDatabase() to get the list of CRS authorities used in the PROJ database.
2 parents 5095aa7 + 41500e1 commit 2c12b7a

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

autotest/osr/osr_basic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,3 +2478,13 @@ def test_osr_basic_export_wkt_utm_south():
24782478

24792479
j = json.loads(srs.ExportToPROJJSON())
24802480
assert j["conversion"]["id"]["code"] == 16101
2481+
2482+
2483+
###############################################################################
2484+
2485+
2486+
def test_osr_basic_GetAuthorityListFromDatabase():
2487+
2488+
ret = osr.GetAuthorityListFromDatabase()
2489+
assert "EPSG" in ret
2490+
assert "PROJ" in ret

ogr/ogr_srs_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,8 @@ OSRGetCRSInfoListFromDatabase(const char *pszAuthName,
10051005

10061006
void CPL_DLL OSRDestroyCRSInfoList(OSRCRSInfo **list);
10071007

1008+
char CPL_DLL **OSRGetAuthorityListFromDatabase(void);
1009+
10081010
/* -------------------------------------------------------------------- */
10091011
/* OGRCoordinateTransform C API. */
10101012
/* -------------------------------------------------------------------- */

ogr/ogrspatialreference.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12854,6 +12854,38 @@ void OSRDestroyCRSInfoList(OSRCRSInfo **list)
1285412854
}
1285512855
}
1285612856

12857+
/************************************************************************/
12858+
/* OSRGetAuthorityListFromDatabase() */
12859+
/************************************************************************/
12860+
12861+
/** \brief Return the list of CRS authorities used in the PROJ database.
12862+
*
12863+
* Such as "EPSG", "ESRI", "PROJ", "IGNF", "IAU_2015", etc.
12864+
*
12865+
* This is a direct mapping of https://proj.org/en/latest/development/reference/functions.html#c.proj_get_authorities_from_database
12866+
*
12867+
* @return nullptr in case of error, or a NULL terminated list of strings to
12868+
* free with CSLDestroy()
12869+
* @since GDAL 3.10
12870+
*/
12871+
char **OSRGetAuthorityListFromDatabase()
12872+
{
12873+
PROJ_STRING_LIST list =
12874+
proj_get_authorities_from_database(OSRGetProjTLSContext());
12875+
if (!list)
12876+
{
12877+
return nullptr;
12878+
}
12879+
int count = 0;
12880+
while (list[count])
12881+
++count;
12882+
char **res = static_cast<char **>(CPLCalloc(count + 1, sizeof(char *)));
12883+
for (int i = 0; i < count; ++i)
12884+
res[i] = CPLStrdup(list[i]);
12885+
proj_string_list_destroy(list);
12886+
return res;
12887+
}
12888+
1285712889
/************************************************************************/
1285812890
/* UpdateCoordinateSystemFromGeogCRS() */
1285912891
/************************************************************************/

swig/include/osr.i

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,15 @@ const char* OSRCRSInfo_projection_method_get( OSRCRSInfo *crsInfo ) {
15561556

15571557
#endif
15581558

1559+
%apply (char **CSL) {(char **)};
1560+
%inline %{
1561+
char** GetAuthorityListFromDatabase()
1562+
{
1563+
return OSRGetAuthorityListFromDatabase();
1564+
}
1565+
%}
1566+
%clear (char **);
1567+
15591568
#ifdef SWIGPYTHON
15601569
%inline %{
15611570
void GetCRSInfoListFromDatabase( const char *authName,

0 commit comments

Comments
 (0)