From 5d6bdadfca419c1d54d455e240743791e6cea44e Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 28 Sep 2021 15:09:24 +0200 Subject: projinfo --list-crs / proj_get_crs_info_list_from_database(): make it work with IAU generic authority name --- include/proj/io.hpp | 2 +- scripts/reference_exported_symbols.txt | 1 + src/apps/projinfo.cpp | 78 ++++++++++++++++++---------------- src/iso19111/c_api.cpp | 19 ++++++--- 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/include/proj/io.hpp b/include/proj/io.hpp index eefec11e..47703442 100644 --- a/include/proj/io.hpp +++ b/include/proj/io.hpp @@ -922,7 +922,7 @@ class PROJ_GCC_DLL DatabaseContext { const std::string &version, std::string &versionedAuthNameOut); - PROJ_INTERNAL std::vector + PROJ_DLL std::vector getVersionedAuthoritiesFromName(const std::string &authName); //! @endcond diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index 6cb734e2..682f5d39 100644 --- a/scripts/reference_exported_symbols.txt +++ b/scripts/reference_exported_symbols.txt @@ -371,6 +371,7 @@ osgeo::proj::io::DatabaseContext::getInsertStatementsFor(dropbox::oxygen::nn types; - auto tokens = split(listCRS, ','); - if (listCRS.empty()) { + auto tokens = split(listCRSFilter, ','); + if (listCRSFilter.empty()) { tokens.clear(); } - for (auto token : tokens) { + for (const auto &token : tokens) { if (ci_equal(token, "allow_deprecated")) { allow_deprecated = true; } else if (ci_equal(token, "geodetic")) { @@ -1397,44 +1397,50 @@ int main(int argc, char **argv) { } for (const auto &auth_name : allowedAuthorities) { try { - auto factory = - AuthorityFactory::create(NN_NO_CHECK(dbContext), auth_name); - const auto list = factory->getCRSInfoList(); - for (const auto &info : list) { - if (!allow_deprecated && info.deprecated) { - continue; - } - if (!types.empty() && - types.find(info.type) == types.end()) { - continue; - } - if (bboxFilter) { - if (!info.bbox_valid) { + auto actualAuthNames = + dbContext->getVersionedAuthoritiesFromName(auth_name); + if (actualAuthNames.empty()) + actualAuthNames.push_back(auth_name); + for (const auto &actualAuthName : actualAuthNames) { + auto factory = AuthorityFactory::create( + NN_NO_CHECK(dbContext), actualAuthName); + const auto list = factory->getCRSInfoList(); + for (const auto &info : list) { + if (!allow_deprecated && info.deprecated) { + continue; + } + if (!types.empty() && + types.find(info.type) == types.end()) { continue; } - auto crsExtent = Extent::createFromBBOX( - info.west_lon_degree, info.south_lat_degree, - info.east_lon_degree, info.north_lat_degree); - if (spatialCriterion == - CoordinateOperationContext::SpatialCriterion:: - STRICT_CONTAINMENT) { - if (!bboxFilter->contains(crsExtent)) { + if (bboxFilter) { + if (!info.bbox_valid) { continue; } - } else { - if (!bboxFilter->intersects(crsExtent)) { - continue; + auto crsExtent = Extent::createFromBBOX( + info.west_lon_degree, info.south_lat_degree, + info.east_lon_degree, info.north_lat_degree); + if (spatialCriterion == + CoordinateOperationContext::SpatialCriterion:: + STRICT_CONTAINMENT) { + if (!bboxFilter->contains(crsExtent)) { + continue; + } + } else { + if (!bboxFilter->intersects(crsExtent)) { + continue; + } } + } else if (!area.empty() && + tolower(info.areaName).find(areaLower) == + std::string::npos) { + continue; } - } else if (!area.empty() && - tolower(info.areaName).find(areaLower) == - std::string::npos) { - continue; + std::cout << info.authName << ":" << info.code << " \"" + << info.name << "\"" + << (info.deprecated ? " [deprecated]" : "") + << std::endl; } - std::cout << info.authName << ":" << info.code << " \"" - << info.name << "\"" - << (info.deprecated ? " [deprecated]" : "") - << std::endl; } } catch (const std::exception &e) { std::cerr << "ERROR: list-crs failed with: " << e.what() diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index a5e1bc81..9493452c 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -2766,10 +2766,19 @@ proj_get_crs_info_list_from_database(PJ_CONTEXT *ctx, const char *auth_name, PROJ_CRS_INFO **ret = nullptr; int i = 0; try { - auto factory = AuthorityFactory::create(getDBcontext(ctx), - auth_name ? auth_name : ""); - auto list = factory->getCRSInfoList(); - ret = new PROJ_CRS_INFO *[list.size() + 1]; + auto dbContext = getDBcontext(ctx); + const std::string authName = auth_name ? auth_name : ""; + auto actualAuthNames = + dbContext->getVersionedAuthoritiesFromName(authName); + if (actualAuthNames.empty()) + actualAuthNames.push_back(authName); + std::list concatList; + for (const auto &actualAuthName : actualAuthNames) { + auto factory = AuthorityFactory::create(dbContext, actualAuthName); + auto list = factory->getCRSInfoList(); + concatList.splice(concatList.end(), std::move(list)); + } + ret = new PROJ_CRS_INFO *[concatList.size() + 1]; GeographicBoundingBoxPtr bbox; if (params && params->bbox_valid) { bbox = GeographicBoundingBox::create( @@ -2777,7 +2786,7 @@ proj_get_crs_info_list_from_database(PJ_CONTEXT *ctx, const char *auth_name, params->east_lon_degree, params->north_lat_degree) .as_nullable(); } - for (const auto &info : list) { + for (const auto &info : concatList) { auto type = PJ_TYPE_CRS; if (info.type == AuthorityFactory::ObjectType::GEOGRAPHIC_2D_CRS) { type = PJ_TYPE_GEOGRAPHIC_2D_CRS; -- cgit v1.2.3