mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-13 12:32:09 +00:00
150 lines
7.4 KiB
HTML
150 lines
7.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Boost.Geometry (aka GGL, Generic Geometry Library)</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
<link href="tabs.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
|
|
<table cellpadding="2" width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td valign="top">
|
|
<img alt="Boost.Geometry" src="images/ggl-logo-big.png" height="80" width="200">
|
|
|
|
</td>
|
|
<td valign="top" align="right">
|
|
<a href="http://www.boost.org">
|
|
<img alt="Boost C++ Libraries" src="images/accepted_by_boost.png" height="80" width="230" border="0">
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- Generated by Doxygen 1.5.9 -->
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>c03_custom_linestring_example.cpp</h1>GPS tracks are shown in this example: a custom linestring with GPS points<p>
|
|
<div class="fragment"><pre class="fragment"><span class="comment">// Boost.Geometry (aka GGL, Generic Geometry Library)</span>
|
|
<span class="comment">//</span>
|
|
<span class="comment">// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands</span>
|
|
<span class="comment">// Copyright Bruno Lalande 2008, 2009</span>
|
|
<span class="comment">// Use, modification and distribution is subject to the Boost Software License,</span>
|
|
<span class="comment">// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
|
|
<span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span>
|
|
<span class="comment">//</span>
|
|
<span class="comment">// Custom Linestring Example</span>
|
|
|
|
<span class="preprocessor">#include <iostream></span>
|
|
<span class="preprocessor">#include <string></span>
|
|
<span class="preprocessor">#include <vector></span>
|
|
|
|
<span class="preprocessor">#include <boost/geometry/geometry.hpp></span>
|
|
<span class="preprocessor">#include <<a class="code" href="register_2point_8hpp.html">boost/geometry/geometries/register/point.hpp</a>></span>
|
|
<span class="preprocessor">#include <<a class="code" href="register_2linestring_8hpp.html">boost/geometry/geometries/register/linestring.hpp</a>></span>
|
|
|
|
<span class="comment">// To register the 'geographic' distance function to calculate distance over the earth:</span>
|
|
<span class="preprocessor">#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp></span>
|
|
<span class="preprocessor">#include <boost/geometry/algorithms/parse.hpp></span>
|
|
|
|
<span class="comment">// Define a GPS point with coordinates in latitude/longitude and some additional values</span>
|
|
<span class="keyword">struct </span>gps_point
|
|
{
|
|
<span class="keywordtype">double</span> latitude, longitude, height;
|
|
<span class="keywordtype">double</span> speed;
|
|
<span class="comment">// Date/time, heading, etc could be added</span>
|
|
|
|
<span class="comment">// The default constructor is required if being used in a vector</span>
|
|
gps_point() {}
|
|
|
|
<span class="comment">// Define a constructor to create the point in one line. Order of latitude/longitude</span>
|
|
<span class="comment">// does not matter as long as "E", "N", etc are included</span>
|
|
gps_point(std::string <span class="keyword">const</span>& c1, std::string <span class="keyword">const</span>& c2, <span class="keywordtype">double</span> h, <span class="keywordtype">double</span> s)
|
|
: height(h)
|
|
, speed(s)
|
|
{
|
|
boost::geometry::parse(*<span class="keyword">this</span>, c1, c2);
|
|
}
|
|
};
|
|
|
|
<span class="comment">// Declare a custom linestring which will have the GPS points</span>
|
|
<span class="keyword">struct </span>gps_track : std::vector<gps_point>
|
|
{
|
|
std::string owner;
|
|
<span class="keywordtype">int</span> route_identifier;
|
|
<span class="comment">// etc</span>
|
|
|
|
gps_track(<span class="keywordtype">int</span> i, std::string <span class="keyword">const</span>& o)
|
|
: owner(o)
|
|
, route_identifier(i)
|
|
{}
|
|
};
|
|
|
|
|
|
<span class="comment">// Register this point as being a recognizable point by the GGL</span>
|
|
<a name="a0"></a><a class="code" href="register_2point_8hpp.html#040a8280aaf06372fc637e1a436019d8">BOOST_GEOMETRY_REGISTER_POINT_2D</a>(gps_point, <span class="keywordtype">double</span>, cs::geographic<degree>, longitude, latitude)
|
|
|
|
|
|
<span class="comment">// Register the track as well, as being a "linestring"</span>
|
|
<a name="a1"></a><a class="code" href="register_2linestring_8hpp.html#1d26e8196d719505669ecdb89e11bd2b">BOOST_GEOMETRY_REGISTER_LINESTRING</a>(gps_track)
|
|
|
|
|
|
<span class="keywordtype">int</span> main()
|
|
{
|
|
<span class="comment">// Declare a "GPS Track" and add some GPS points</span>
|
|
gps_track track(23, <span class="stringliteral">"Mister G"</span>);
|
|
track.push_back(gps_point(<span class="stringliteral">"52 22 23 N"</span>, <span class="stringliteral">"4 53 32 E"</span>, 50, 180));
|
|
track.push_back(gps_point(<span class="stringliteral">"52 10 00 N"</span>, <span class="stringliteral">"4 59 59 E"</span>, 110, 170));
|
|
track.push_back(gps_point(<span class="stringliteral">"52 5 20 N"</span>, <span class="stringliteral">"5 6 56 E"</span>, 0, 90));
|
|
|
|
std::cout
|
|
<< <span class="stringliteral">"track: "</span> << track.route_identifier << std::endl
|
|
<< <span class="stringliteral">"from: "</span> << track.owner << std::endl
|
|
<< <span class="stringliteral">"as wkt: "</span> << <a name="a2"></a><a class="code" href="group__utility.html#g62cc5db4d3bb1147591298b3500f8f1a" title="Main DSV-streaming function.">boost::geometry::dsv</a>(track) << std::endl
|
|
<< <span class="stringliteral">"length: "</span> << <a name="a3"></a><a class="code" href="group__length.html#g1537537131cd91037cf3ad9fd80d50f1" title="Calculate length of a geometry.">boost::geometry::length</a>(track)/1000.0 << <span class="stringliteral">" km"</span> << std::endl;
|
|
|
|
<span class="comment">// Above gives the idea, shows that custom linestrings can be useful.</span>
|
|
<span class="comment">// We could of course do anything with this track which the library can handle, e.g.:</span>
|
|
<span class="comment">// - simplify it</span>
|
|
<span class="comment">// - calculate distance of point-to-line</span>
|
|
<span class="comment">// - project it to UTM, then transform it to a GIF image (see p03_example)</span>
|
|
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div> </div>
|
|
<hr size="1">
|
|
<table width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><small>
|
|
<p>December 1, 2009</p>
|
|
</small></td>
|
|
<td align="right">
|
|
<small>Copyright © 1995-2009 Barend Gehrels, Geodan, Amsterdam<br>
|
|
Copyright © 2008-2009 Bruno Lalande, Paris<br>
|
|
Copyright © 2009 Mateusz Loskot, Cadcorp, London<br>
|
|
</small>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<address style="text-align: right;"><small>
|
|
Documentation is generated by <a href="http://www.doxygen.org/index.html">Doxygen</a>
|
|
</small></address>
|
|
</body>
|
|
</html>
|