diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-03-21 15:45:20 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-03-21 15:46:37 +0900 |
commit | 733b5d5ae2c5d625211e2985ac25728ac3f54883 (patch) | |
tree | a5b214744b256f07e1dc2bd7273035a7808c659f /boost/geometry/strategies/geographic | |
parent | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (diff) | |
download | boost-733b5d5ae2c5d625211e2985ac25728ac3f54883.tar.gz boost-733b5d5ae2c5d625211e2985ac25728ac3f54883.tar.bz2 boost-733b5d5ae2c5d625211e2985ac25728ac3f54883.zip |
Imported Upstream version 1.58.0upstream/1.58.0
Change-Id: If0072143aa26874812e0db6872e1efb10a3e5e94
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/geometry/strategies/geographic')
3 files changed, 570 insertions, 0 deletions
diff --git a/boost/geometry/strategies/geographic/distance_andoyer.hpp b/boost/geometry/strategies/geographic/distance_andoyer.hpp new file mode 100644 index 0000000000..64de8c1a41 --- /dev/null +++ b/boost/geometry/strategies/geographic/distance_andoyer.hpp @@ -0,0 +1,224 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ANDOYER_HPP +#define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ANDOYER_HPP + + +#include <boost/geometry/core/coordinate_type.hpp> +#include <boost/geometry/core/radian_access.hpp> +#include <boost/geometry/core/radius.hpp> +#include <boost/geometry/core/srs.hpp> + +#include <boost/geometry/algorithms/detail/flattening.hpp> + +#include <boost/geometry/strategies/distance.hpp> + +#include <boost/geometry/util/math.hpp> +#include <boost/geometry/util/promote_floating_point.hpp> +#include <boost/geometry/util/select_calculation_type.hpp> + + +namespace boost { namespace geometry +{ + +namespace strategy { namespace distance +{ + + +/*! +\brief Point-point distance approximation taking flattening into account +\ingroup distance +\tparam Spheroid The reference spheroid model +\tparam CalculationType \tparam_calculation +\author After Andoyer, 19xx, republished 1950, republished by Meeus, 1999 +\note Although not so well-known, the approximation is very good: in all cases the results +are about the same as Vincenty. In my (Barend's) testcases the results didn't differ more than 6 m +\see http://nacc.upc.es/tierra/node16.html +\see http://sci.tech-archive.net/Archive/sci.geo.satellite-nav/2004-12/2724.html +\see http://home.att.net/~srschmitt/great_circle_route.html (implementation) +\see http://www.codeguru.com/Cpp/Cpp/algorithms/article.php/c5115 (implementation) +\see http://futureboy.homeip.net/frinksamp/navigation.frink (implementation) +\see http://www.voidware.com/earthdist.htm (implementation) +*/ +template +< + typename Spheroid, + typename CalculationType = void +> +class andoyer +{ +public : + template <typename Point1, typename Point2> + struct calculation_type + : promote_floating_point + < + typename select_calculation_type + < + Point1, + Point2, + CalculationType + >::type + > + {}; + + typedef Spheroid model_type; + + inline andoyer() + : m_spheroid() + {} + + explicit inline andoyer(Spheroid const& spheroid) + : m_spheroid(spheroid) + {} + + + template <typename Point1, typename Point2> + inline typename calculation_type<Point1, Point2>::type + apply(Point1 const& point1, Point2 const& point2) const + { + return calc<typename calculation_type<Point1, Point2>::type> + ( + get_as_radian<0>(point1), get_as_radian<1>(point1), + get_as_radian<0>(point2), get_as_radian<1>(point2) + ); + } + + inline Spheroid const& model() const + { + return m_spheroid; + } + +private : + template <typename CT, typename T> + inline CT calc(T const& lon1, + T const& lat1, + T const& lon2, + T const& lat2) const + { + CT const G = (lat1 - lat2) / 2.0; + CT const lambda = (lon1 - lon2) / 2.0; + + if (geometry::math::equals(lambda, 0.0) + && geometry::math::equals(G, 0.0)) + { + return 0.0; + } + + CT const F = (lat1 + lat2) / 2.0; + + CT const sinG2 = math::sqr(sin(G)); + CT const cosG2 = math::sqr(cos(G)); + CT const sinF2 = math::sqr(sin(F)); + CT const cosF2 = math::sqr(cos(F)); + CT const sinL2 = math::sqr(sin(lambda)); + CT const cosL2 = math::sqr(cos(lambda)); + + CT const S = sinG2 * cosL2 + cosF2 * sinL2; + CT const C = cosG2 * cosL2 + sinF2 * sinL2; + + CT const c0 = 0; + CT const c1 = 1; + CT const c2 = 2; + CT const c3 = 3; + + if (geometry::math::equals(S, c0) || geometry::math::equals(C, c0)) + { + return c0; + } + + CT const radius_a = CT(get_radius<0>(m_spheroid)); + CT const flattening = geometry::detail::flattening<CT>(m_spheroid); + + CT const omega = atan(math::sqrt(S / C)); + CT const r3 = c3 * math::sqrt(S * C) / omega; // not sure if this is r or greek nu + CT const D = c2 * omega * radius_a; + CT const H1 = (r3 - c1) / (c2 * C); + CT const H2 = (r3 + c1) / (c2 * S); + + return D * (c1 + flattening * (H1 * sinF2 * cosG2 - H2 * cosF2 * sinG2) ); + } + + Spheroid m_spheroid; +}; + + +#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS +namespace services +{ + +template <typename Spheroid, typename CalculationType> +struct tag<andoyer<Spheroid, CalculationType> > +{ + typedef strategy_tag_distance_point_point type; +}; + + +template <typename Spheroid, typename CalculationType, typename P1, typename P2> +struct return_type<andoyer<Spheroid, CalculationType>, P1, P2> + : andoyer<Spheroid, CalculationType>::template calculation_type<P1, P2> +{}; + + +template <typename Spheroid, typename CalculationType> +struct comparable_type<andoyer<Spheroid, CalculationType> > +{ + typedef andoyer<Spheroid, CalculationType> type; +}; + + +template <typename Spheroid, typename CalculationType> +struct get_comparable<andoyer<Spheroid, CalculationType> > +{ + static inline andoyer<Spheroid, CalculationType> apply(andoyer<Spheroid, CalculationType> const& input) + { + return input; + } +}; + +template <typename Spheroid, typename CalculationType, typename P1, typename P2> +struct result_from_distance<andoyer<Spheroid, CalculationType>, P1, P2> +{ + template <typename T> + static inline typename return_type<andoyer<Spheroid, CalculationType>, P1, P2>::type + apply(andoyer<Spheroid, CalculationType> const& , T const& value) + { + return value; + } +}; + + +template <typename Point1, typename Point2> +struct default_strategy<point_tag, point_tag, Point1, Point2, geographic_tag, geographic_tag> +{ + typedef strategy::distance::andoyer + < + srs::spheroid + < + typename select_coordinate_type<Point1, Point2>::type + > + > type; +}; + + +} // namespace services +#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS + + +}} // namespace strategy::distance + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_ANDOYER_HPP diff --git a/boost/geometry/strategies/geographic/distance_vincenty.hpp b/boost/geometry/strategies/geographic/distance_vincenty.hpp new file mode 100644 index 0000000000..56dd14bbdc --- /dev/null +++ b/boost/geometry/strategies/geographic/distance_vincenty.hpp @@ -0,0 +1,161 @@ +// Boost.Geometry + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP +#define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP + + +#include <boost/geometry/core/coordinate_type.hpp> +#include <boost/geometry/core/radian_access.hpp> + +#include <boost/geometry/strategies/distance.hpp> + +#include <boost/geometry/util/promote_floating_point.hpp> +#include <boost/geometry/util/select_calculation_type.hpp> + +#include <boost/geometry/algorithms/detail/vincenty_inverse.hpp> + +namespace boost { namespace geometry +{ + +namespace strategy { namespace distance +{ + +/*! +\brief Distance calculation formulae on latlong coordinates, after Vincenty, 1975 +\ingroup distance +\tparam Spheroid The reference spheroid model +\tparam CalculationType \tparam_calculation +\author See + - http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf + - http://www.icsm.gov.au/gda/gdav2.3.pdf +\author Adapted from various implementations to get it close to the original document + - http://www.movable-type.co.uk/scripts/LatLongVincenty.html + - http://exogen.case.edu/projects/geopy/source/geopy.distance.html + - http://futureboy.homeip.net/fsp/colorize.fsp?fileName=navigation.frink + +*/ +template +< + typename Spheroid, + typename CalculationType = void +> +class vincenty +{ +public : + template <typename Point1, typename Point2> + struct calculation_type + : promote_floating_point + < + typename select_calculation_type + < + Point1, + Point2, + CalculationType + >::type + > + {}; + + typedef Spheroid model_type; + + inline vincenty() + : m_spheroid() + {} + + explicit inline vincenty(Spheroid const& spheroid) + : m_spheroid(spheroid) + {} + + template <typename Point1, typename Point2> + inline typename calculation_type<Point1, Point2>::type + apply(Point1 const& point1, Point2 const& point2) const + { + return geometry::detail::vincenty_inverse + < + typename calculation_type<Point1, Point2>::type + >(get_as_radian<0>(point1), + get_as_radian<1>(point1), + get_as_radian<0>(point2), + get_as_radian<1>(point2), + m_spheroid).distance(); + } + + inline Spheroid const& model() const + { + return m_spheroid; + } + +private : + Spheroid m_spheroid; +}; + +#ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS +namespace services +{ + +template <typename Spheroid, typename CalculationType> +struct tag<vincenty<Spheroid, CalculationType> > +{ + typedef strategy_tag_distance_point_point type; +}; + + +template <typename Spheroid, typename CalculationType, typename P1, typename P2> +struct return_type<vincenty<Spheroid, CalculationType>, P1, P2> + : vincenty<Spheroid, CalculationType>::template calculation_type<P1, P2> +{}; + + +template <typename Spheroid, typename CalculationType> +struct comparable_type<vincenty<Spheroid, CalculationType> > +{ + typedef vincenty<Spheroid, CalculationType> type; +}; + + +template <typename Spheroid, typename CalculationType> +struct get_comparable<vincenty<Spheroid, CalculationType> > +{ + static inline vincenty<Spheroid, CalculationType> apply(vincenty<Spheroid, CalculationType> const& input) + { + return input; + } +}; + +template <typename Spheroid, typename CalculationType, typename P1, typename P2> +struct result_from_distance<vincenty<Spheroid, CalculationType>, P1, P2 > +{ + template <typename T> + static inline typename return_type<vincenty<Spheroid, CalculationType>, P1, P2>::type + apply(vincenty<Spheroid, CalculationType> const& , T const& value) + { + return value; + } +}; + + +} // namespace services +#endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS + + +// We might add a vincenty-like strategy also for point-segment distance, but to calculate the projected point is not trivial + + + +}} // namespace strategy::distance + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_VINCENTY_HPP diff --git a/boost/geometry/strategies/geographic/mapping_ssf.hpp b/boost/geometry/strategies/geographic/mapping_ssf.hpp new file mode 100644 index 0000000000..3beedc7809 --- /dev/null +++ b/boost/geometry/strategies/geographic/mapping_ssf.hpp @@ -0,0 +1,185 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP +#define BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP + + +#include <boost/core/ignore_unused.hpp> + +#include <boost/geometry/core/radius.hpp> + +#include <boost/geometry/util/math.hpp> +#include <boost/geometry/util/promote_floating_point.hpp> +#include <boost/geometry/util/select_calculation_type.hpp> + +#include <boost/geometry/strategies/side.hpp> +#include <boost/geometry/strategies/spherical/ssf.hpp> + + +namespace boost { namespace geometry +{ + +namespace strategy { namespace side +{ + + +// An enumeration type defining types of mapping of geographical +// latitude to spherical latitude. +// See: http://en.wikipedia.org/wiki/Great_ellipse +// http://en.wikipedia.org/wiki/Latitude#Auxiliary_latitudes +enum mapping_type { mapping_geodetic, mapping_reduced, mapping_geocentric }; + + +#ifndef DOXYGEN_NO_DETAIL +namespace detail +{ + +template <typename Spheroid, mapping_type Mapping> +struct mapper +{ + explicit inline mapper(Spheroid const& /*spheroid*/) {} + + template <typename CalculationType> + static inline CalculationType const& apply(CalculationType const& lat) + { + return lat; + } +}; + +template <typename Spheroid> +struct mapper<Spheroid, mapping_reduced> +{ + typedef typename promote_floating_point + < + typename radius_type<Spheroid>::type + >::type fraction_type; + + explicit inline mapper(Spheroid const& spheroid) + { + fraction_type const a = geometry::get_radius<0>(spheroid); + fraction_type const b = geometry::get_radius<2>(spheroid); + b_div_a = b / a; + } + + template <typename CalculationType> + inline CalculationType apply(CalculationType const& lat) const + { + return atan(static_cast<CalculationType>(b_div_a) * tan(lat)); + } + + fraction_type b_div_a; +}; + +template <typename Spheroid> +struct mapper<Spheroid, mapping_geocentric> +{ + typedef typename promote_floating_point + < + typename radius_type<Spheroid>::type + >::type fraction_type; + + explicit inline mapper(Spheroid const& spheroid) + { + fraction_type const a = geometry::get_radius<0>(spheroid); + fraction_type const b = geometry::get_radius<2>(spheroid); + sqr_b_div_a = b / a; + sqr_b_div_a *= sqr_b_div_a; + } + + template <typename CalculationType> + inline CalculationType apply(CalculationType const& lat) const + { + return atan(static_cast<CalculationType>(sqr_b_div_a) * tan(lat)); + } + + fraction_type sqr_b_div_a; +}; + +} +#endif // DOXYGEN_NO_DETAIL + + +/*! +\brief Check at which side of a geographical segment a point lies + left of segment (> 0), right of segment (< 0), on segment (0). + The check is performed by mapping the geographical coordinates + to spherical coordinates and using spherical_side_formula. +\ingroup strategies +\tparam Spheroid The reference spheroid model +\tparam Mapping The type of mapping of geographical to spherical latitude +\tparam CalculationType \tparam_calculation + */ +template <typename Spheroid, + mapping_type Mapping = mapping_geodetic, + typename CalculationType = void> +class mapping_spherical_side_formula +{ + +public : + inline mapping_spherical_side_formula() + : m_mapper(Spheroid()) + {} + + explicit inline mapping_spherical_side_formula(Spheroid const& spheroid) + : m_mapper(spheroid) + {} + + template <typename P1, typename P2, typename P> + inline int apply(P1 const& p1, P2 const& p2, P const& p) + { + typedef typename promote_floating_point + < + typename select_calculation_type_alt + < + CalculationType, + P1, P2, P + >::type + >::type calculation_type; + + calculation_type lon1 = get_as_radian<0>(p1); + calculation_type lat1 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p1)); + calculation_type lon2 = get_as_radian<0>(p2); + calculation_type lat2 = m_mapper.template apply<calculation_type>(get_as_radian<1>(p2)); + calculation_type lon = get_as_radian<0>(p); + calculation_type lat = m_mapper.template apply<calculation_type>(get_as_radian<1>(p)); + + return detail::spherical_side_formula(lon1, lat1, lon2, lat2, lon, lat); + } + +private: + side::detail::mapper<Spheroid, Mapping> const m_mapper; +}; + +// The specialization for geodetic latitude which can be used directly +template <typename Spheroid, + typename CalculationType> +class mapping_spherical_side_formula<Spheroid, mapping_geodetic, CalculationType> +{ + +public : + inline mapping_spherical_side_formula() {} + explicit inline mapping_spherical_side_formula(Spheroid const& /*spheroid*/) {} + + template <typename P1, typename P2, typename P> + static inline int apply(P1 const& p1, P2 const& p2, P const& p) + { + return spherical_side_formula<CalculationType>::apply(p1, p2, p); + } +}; + +}} // namespace strategy::side + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_STRATEGIES_GEOGRAPHIC_MAPPING_SSF_HPP |