]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/example/c10_custom_cs_example.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 // Example: Custom coordinate system example
15 #include <boost/geometry/geometry.hpp>
17 // 1: declare a coordinate system. For example for Mars
18 // Like for the Earth, we let the use choose between degrees or radians
19 // (Unfortunately, in real life Mars has two coordinate systems:
20 // http://planetarynames.wr.usgs.gov/Page/MARS/system)
21 template<typename DegreeOrRadian
>
24 typedef DegreeOrRadian units
;
27 // 2: give it also a family
30 // 3: register to which coordinate system family it belongs to
31 // this must be done in namespace boost::geometry::traits
32 namespace boost
{ namespace geometry
{ namespace traits
35 template <typename DegreeOrRadian
>
36 struct cs_tag
<martian
<DegreeOrRadian
> >
38 typedef martian_tag type
;
44 // NOTE: if the next steps would not be here,
45 // compiling a distance function call with martian coordinates
46 // would result in a MPL assertion
48 // 4: so register a distance strategy as its default strategy
49 namespace boost
{ namespace geometry
{ namespace strategy
{ namespace distance
{ namespace services
52 template <typename Point1
, typename Point2
>
53 struct default_strategy
<point_tag
, point_tag
, Point1
, Point2
, martian_tag
, martian_tag
>
55 typedef haversine
<double> type
;
60 // 5: not worked out. To implement a specific distance strategy for Mars,
61 // e.g. with the Mars radius given by default,
62 // you will have to implement (/register) several other metafunctions:
63 // tag, return_type, similar_type, comparable_type,
65 // get_similar, get_comparable, result_from_distance
66 // See e.g. .../boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp
70 typedef boost::geometry::model::point
72 double, 2, martian
<boost::geometry::degree
>
76 // (Source: http://nssdc.gsfc.nasa.gov/planetary/mars_mileage_guide.html)
77 // (Other sources: Wiki and Google give slightly different coordinates, resulting
78 // in other distance, 20 km off)
79 mars_point
viking1(-48.23, 22.54); // Viking 1 landing site in Chryse Planitia
80 mars_point
pathfinder(-33.55, 19.33); // Pathfinder landing site in Ares Vallis
82 double d
= boost::geometry::distance(viking1
, pathfinder
); // Distance in radians on unit-sphere
84 // Using the Mars mean radius
85 // (Source: http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html)
86 std::cout
<< "Distance between Viking1 and Pathfinder landing sites: "
87 << d
* 3389.5 << " km" << std::endl
;
89 // We would get 832.616 here, same order as the 835 (rounded on 5 km) listed
90 // on the mentioned site
92 #ifdef OPTIONALLY_ELLIPSOIDAL
93 // Optionally the distance can be calculated more accurate by an Ellipsoidal approach,
95 d
= boost::geometry::distance(viking1
, pathfinder
,
96 boost::geometry::strategy::distance::andoyer
<mars_point
>
97 (boost::geometry::srs::spheroid
<double>(3396.2, 3376.2)));
98 std::cout
<< "Ellipsoidal distance: " << d
<< " km" << std::endl
;