diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-12-06 22:51:27 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-12-06 23:42:16 +0100 |
| commit | cae698abe380b3823c3f08151c25097031ae091f (patch) | |
| tree | 0a6702b21eb70e2915b6f7df8514cbec93de0e05 /src | |
| parent | 67ca5c199dfe62fc0738a808f3142af2e77eafd7 (diff) | |
| download | PROJ-cae698abe380b3823c3f08151c25097031ae091f.tar.gz PROJ-cae698abe380b3823c3f08151c25097031ae091f.zip | |
Speed-up createBoundCRSToWGS84IfPossible()
Diffstat (limited to 'src')
| -rw-r--r-- | src/c_api.cpp | 26 | ||||
| -rw-r--r-- | src/crs.cpp | 6 | ||||
| -rw-r--r-- | src/proj_experimental.h | 3 | ||||
| -rw-r--r-- | src/projinfo.cpp | 26 |
4 files changed, 44 insertions, 17 deletions
diff --git a/src/c_api.cpp b/src/c_api.cpp index 78ca1c24..03a0c0bd 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -1319,11 +1319,19 @@ PJ_OBJ *proj_obj_crs_create_bound_crs(PJ_CONTEXT *ctx, const PJ_OBJ *base_crs, * * @param ctx PROJ context, or NULL for default context * @param crs Objet of type CRS (must not be NULL) + * @param options null-terminated list of options, or NULL. Currently + * supported options are: + * <ul> + * <li>ALLOW_INTERMEDIATE_CRS=YES/NO. Defaults to NO. When set to YES, + * intermediate CRS may be considered when computing the possible + * tranformations. Slower.</li> + * </ul> * @return Object that must be unreferenced with proj_obj_unref(), or NULL * in case of error. */ PJ_OBJ *proj_obj_crs_create_bound_crs_to_WGS84(PJ_CONTEXT *ctx, - const PJ_OBJ *crs) { + const PJ_OBJ *crs, + const char *const *options) { SANITIZE_CTX(ctx); assert(crs); auto l_crs = dynamic_cast<const CRS *>(crs->obj.get()); @@ -1333,8 +1341,20 @@ PJ_OBJ *proj_obj_crs_create_bound_crs_to_WGS84(PJ_CONTEXT *ctx, } auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); try { - return PJ_OBJ::create( - l_crs->createBoundCRSToWGS84IfPossible(dbContext)); + bool allowIntermediateCRS = false; + for (auto iter = options; iter && iter[0]; ++iter) { + const char *value; + if ((value = getOptionValue(*iter, "ALLOW_INTERMEDIATE_CRS="))) { + allowIntermediateCRS = ci_equal(value, "YES"); + } else { + std::string msg("Unknown option :"); + msg += *iter; + proj_log_error(ctx, __FUNCTION__, msg.c_str()); + return nullptr; + } + } + return PJ_OBJ::create(l_crs->createBoundCRSToWGS84IfPossible( + dbContext, allowIntermediateCRS)); } catch (const std::exception &e) { proj_log_error(ctx, __FUNCTION__, e.what()); return nullptr; diff --git a/src/crs.cpp b/src/crs.cpp index 81e9a300..639fc3a9 100644 --- a/src/crs.cpp +++ b/src/crs.cpp @@ -375,8 +375,9 @@ VerticalCRSPtr CRS::extractVerticalCRS() const { * * @return a CRS. */ -CRSNNPtr CRS::createBoundCRSToWGS84IfPossible( - const io::DatabaseContextPtr &dbContext) const { +CRSNNPtr +CRS::createBoundCRSToWGS84IfPossible(const io::DatabaseContextPtr &dbContext, + bool allowIntermediateCRS) const { auto thisAsCRS = NN_NO_CHECK( std::static_pointer_cast<CRS>(shared_from_this().as_nullable())); auto boundCRS = util::nn_dynamic_pointer_cast<BoundCRS>(thisAsCRS); @@ -441,6 +442,7 @@ CRSNNPtr CRS::createBoundCRSToWGS84IfPossible( authority == "any" ? std::string() : authority); auto ctxt = operation::CoordinateOperationContext::create( authFactory, extent, 0.0); + ctxt->setAllowUseIntermediateCRS(allowIntermediateCRS); // ctxt->setSpatialCriterion( // operation::CoordinateOperationContext::SpatialCriterion::PARTIAL_INTERSECTION); auto list = diff --git a/src/proj_experimental.h b/src/proj_experimental.h index b8c37054..9af7c389 100644 --- a/src/proj_experimental.h +++ b/src/proj_experimental.h @@ -244,7 +244,8 @@ PJ_OBJ PROJ_DLL *proj_obj_crs_create_bound_crs(PJ_CONTEXT *ctx, const PJ_OBJ *transformation); PJ_OBJ PROJ_DLL *proj_obj_crs_create_bound_crs_to_WGS84(PJ_CONTEXT *ctx, - const PJ_OBJ *crs); + const PJ_OBJ *crs, + const char *const *options); /* BEGIN: Generated by scripts/create_c_api_projections.py*/ PJ_OBJ PROJ_DLL *proj_obj_create_conversion_utm( diff --git a/src/projinfo.cpp b/src/projinfo.cpp index ba19b8d2..d6fa37bc 100644 --- a/src/projinfo.cpp +++ b/src/projinfo.cpp @@ -136,7 +136,8 @@ static std::string c_ify_string(const std::string &str) { static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext, const std::string &user_string, bool kindIsCRS, const std::string &context, - bool buildBoundCRSToWGS84) { + bool buildBoundCRSToWGS84, + bool allowPivots) { BaseObjectPtr obj; std::string l_user_string(user_string); @@ -192,7 +193,8 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext, if (buildBoundCRSToWGS84) { auto crs = std::dynamic_pointer_cast<CRS>(obj); if (crs) { - obj = crs->createBoundCRSToWGS84IfPossible(dbContext).as_nullable(); + obj = crs->createBoundCRSToWGS84IfPossible(dbContext, allowPivots) + .as_nullable(); } } @@ -202,7 +204,7 @@ static BaseObjectNNPtr buildObject(DatabaseContextPtr dbContext, // --------------------------------------------------------------------------- static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, - const OutputOptions &outputOpt) { + bool allowPivots, const OutputOptions &outputOpt) { auto identified = dynamic_cast<const IdentifiedObject *>(obj.get()); if (!outputOpt.quiet && identified && identified->isDeprecated()) { @@ -263,7 +265,8 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, if (crs) { objToExport = nn_dynamic_pointer_cast<IPROJStringExportable>( - crs->createBoundCRSToWGS84IfPossible(dbContext)); + crs->createBoundCRSToWGS84IfPossible(dbContext, + allowPivots)); } if (!objToExport) { objToExport = projStringExportable; @@ -398,7 +401,8 @@ static void outputObject(DatabaseContextPtr dbContext, BaseObjectNNPtr obj, std::shared_ptr<IWKTExportable> objToExport; if (crs) { objToExport = nn_dynamic_pointer_cast<IWKTExportable>( - crs->createBoundCRSToWGS84IfPossible(dbContext)); + crs->createBoundCRSToWGS84IfPossible(dbContext, + allowPivots)); } if (!objToExport) { objToExport = wktExportable; @@ -506,7 +510,7 @@ static void outputOperations( const std::string &authority, bool usePROJGridAlternatives, bool showSuperseded, const OutputOptions &outputOpt, bool summary) { auto sourceObj = - buildObject(dbContext, sourceCRSStr, true, "source CRS", false); + buildObject(dbContext, sourceCRSStr, true, "source CRS", false, false); auto sourceCRS = nn_dynamic_pointer_cast<CRS>(sourceObj); if (!sourceCRS) { std::cerr << "source CRS string is not a CRS" << std::endl; @@ -514,7 +518,7 @@ static void outputOperations( } auto targetObj = - buildObject(dbContext, targetCRSStr, true, "target CRS", false); + buildObject(dbContext, targetCRSStr, true, "target CRS", false, false); auto targetCRS = nn_dynamic_pointer_cast<CRS>(targetObj); if (!targetCRS) { std::cerr << "target CRS string is not a CRS" << std::endl; @@ -545,7 +549,7 @@ static void outputOperations( std::exit(1); } if (outputOpt.quiet && !list.empty()) { - outputObject(dbContext, list[0], outputOpt); + outputObject(dbContext, list[0], allowPivots, outputOpt); return; } if (summary) { @@ -571,7 +575,7 @@ static void outputOperations( } outputOperationSummary(op); std::cout << std::endl; - outputObject(dbContext, op, outputOpt); + outputObject(dbContext, op, allowPivots, outputOpt); } } } @@ -906,7 +910,7 @@ int main(int argc, char **argv) { if (!user_string.empty()) { auto obj(buildObject(dbContext, user_string, kindIsCRS, "input string", - buildBoundCRSToWGS84)); + buildBoundCRSToWGS84, allowPivots)); if (guessDialect) { auto dialect = WKTParser().guessDialect(user_string); std::cout << "Guessed WKT dialect: "; @@ -923,7 +927,7 @@ int main(int argc, char **argv) { } std::cout << std::endl; } - outputObject(dbContext, obj, outputOpt); + outputObject(dbContext, obj, allowPivots, outputOpt); if (identify) { auto crs = dynamic_cast<CRS *>(obj.get()); if (crs) { |
