aboutsummaryrefslogtreecommitdiff
path: root/src/apps
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2020-11-10 14:40:17 +0100
committerEven Rouault <even.rouault@spatialys.com>2020-11-10 14:47:41 +0100
commit6be4e25c66e805218c851d67157e4d1ddc0a761e (patch)
tree5ff51d3064c46b27a8aa0f68aeaabc1ba957a6b4 /src/apps
parenta8be7bc87c37f802ddd480b55ba0c19613397892 (diff)
downloadPROJ-6be4e25c66e805218c851d67157e4d1ddc0a761e.tar.gz
PROJ-6be4e25c66e805218c851d67157e4d1ddc0a761e.zip
cct: allow @filename syntax
Similarly as for projinfo, allow "cct @filename" to mean read filename and use its content as if it was provided inline. Useful for WKT or PROJJSON And a tiny improvements, when the object definition contains ':', only try proj_create_from_database() if the left part (authority name) matches a known authority, to avoid a warning.
Diffstat (limited to 'src/apps')
-rw-r--r--src/apps/cct.cpp47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp
index 4de3cf8e..c482efc2 100644
--- a/src/apps/cct.cpp
+++ b/src/apps/cct.cpp
@@ -77,6 +77,8 @@ Thomas Knudsen, thokn@sdfe.dk, 2016-05-25/2017-10-26
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+
+#include <fstream> // std::ifstream
#include <iostream>
#include "proj.h"
@@ -293,20 +295,55 @@ int main(int argc, char **argv) {
/* Setup transformation */
if (o-> pargc == 0 && o->fargc > 0) {
- /* Assume we got a auth:code combination */
std::string input(o->fargv[0]);
+
+ if (!input.empty() && input[0] == '@') {
+ std::ifstream fs;
+ auto filename = input.substr(1);
+ fs.open(filename, std::fstream::in | std::fstream::binary);
+ if (!fs.is_open()) {
+ std::cerr << "cannot open " << filename << std::endl;
+ std::exit(1);
+ }
+ input.clear();
+ while (!fs.eof()) {
+ char buffer[256];
+ fs.read(buffer, sizeof(buffer));
+ input.append(buffer, static_cast<size_t>(fs.gcount()));
+ if (input.size() > 100 * 1000) {
+ fs.close();
+ std::cerr << "too big file " << filename << std::endl;
+ std::exit(1);
+ }
+ }
+ fs.close();
+ }
+
+ /* Assume we got a auth:code combination */
auto n = input.find(":");
if (n > 0) {
std::string auth = input.substr(0,n);
std::string code = input.substr(n+1, input.length());
- P = proj_create_from_database(
- nullptr, auth.c_str(), code.c_str(), PJ_CATEGORY_COORDINATE_OPERATION, 0, nullptr
- );
+ // Check that the authority matches one of the known ones
+ auto authorityList = proj_get_authorities_from_database(nullptr);
+ if( authorityList )
+ {
+ for( auto iter = authorityList; *iter; iter++ )
+ {
+ if( *iter == auth ) {
+ P = proj_create_from_database(
+ nullptr, auth.c_str(), code.c_str(),
+ PJ_CATEGORY_COORDINATE_OPERATION, 0, nullptr);
+ break;
+ }
+ }
+ proj_string_list_destroy(authorityList);
+ }
}
if( P == nullptr ) {
/* if we didn't get a auth:code combo we try to see if the input matches */
/* anything else */
- P = proj_create(nullptr, o->fargv[0]);
+ P = proj_create(nullptr, input.c_str());
}
/* If instantiating operation without +-options optargpm thinks the input is */