Skip to content

Commit

Permalink
projinfo --list-crs / proj_get_crs_info_list_from_database(): make it…
Browse files Browse the repository at this point in the history
… work with IAU generic authority name
  • Loading branch information
rouault committed Sep 28, 2021
1 parent f13c584 commit 00278d6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion include/proj/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ class PROJ_GCC_DLL DatabaseContext {
const std::string &version,
std::string &versionedAuthNameOut);

PROJ_INTERNAL std::vector<std::string>
PROJ_DLL std::vector<std::string>
getVersionedAuthoritiesFromName(const std::string &authName);

//! @endcond
Expand Down
78 changes: 42 additions & 36 deletions src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ int main(int argc, char **argv) {
double minimumAccuracy = -1;
bool outputAll = false;
bool dumpDbStructure = false;
std::string listCRS;
std::string listCRSFilter;
bool listCRSSpecified = false;

for (int i = 1; i < argc; i++) {
Expand Down Expand Up @@ -1251,7 +1251,7 @@ int main(int argc, char **argv) {
listCRSSpecified = true;
if (i + 1 < argc && argv[i + 1][0] != '-') {
i++;
listCRS = argv[i];
listCRSFilter = argv[i];
}
} else if (ci_equal(arg, "--searchpaths")) {
#ifdef _WIN32
Expand Down Expand Up @@ -1354,11 +1354,11 @@ int main(int argc, char **argv) {
if (listCRSSpecified) {
bool allow_deprecated = false;
std::set<AuthorityFactory::ObjectType> 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")) {
Expand Down Expand Up @@ -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()
Expand Down
19 changes: 14 additions & 5 deletions src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2766,18 +2766,27 @@ 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<AuthorityFactory::CRSInfo> 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(
params->west_lon_degree, params->south_lat_degree,
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;
Expand Down

0 comments on commit 00278d6

Please sign in to comment.