From 22f49ce7b4ac15bf8d16f67a64ab406d4de02fac Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Thu, 22 Mar 2018 22:11:53 +0100 Subject: [PATCH] [srs] Allow defining prime meridian in DMS format. --- .../geometry/srs/projections/impl/pj_init.hpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/include/boost/geometry/srs/projections/impl/pj_init.hpp b/include/boost/geometry/srs/projections/impl/pj_init.hpp index 3401646a4..8b93343bc 100644 --- a/include/boost/geometry/srs/projections/impl/pj_init.hpp +++ b/include/boost/geometry/srs/projections/impl/pj_init.hpp @@ -306,25 +306,32 @@ inline parameters pj_init(BGParams const& bg_params, R const& arguments, bool std::string value; int n = sizeof(pj_prime_meridians) / sizeof(pj_prime_meridians[0]); - int index = -1; - for (int i = 0; i < n && index == -1; i++) + for (int i = 0; i < n ; i++) { if(pj_prime_meridians[i].id == pm) { value = pj_prime_meridians[i].defn; - index = i; + break; } } - if (index == -1) { - BOOST_THROW_EXCEPTION( projection_exception(-7) ); + dms_parser parser; + + // TODO: Handle case when lexical_cast is not used consistently. + // This should probably be done in dms_parser. + BOOST_TRY + { + if (value.empty()) { + pin.from_greenwich = parser.apply(pm).angle(); + } else { + pin.from_greenwich = parser.apply(value).angle(); + } } - if (value.empty()) { + BOOST_CATCH(boost::bad_lexical_cast const&) + { BOOST_THROW_EXCEPTION( projection_exception(-46) ); } - - dms_parser parser; - pin.from_greenwich = parser.apply(value.c_str()).angle(); + BOOST_CATCH_END } else {