]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/PolyLine.hxx
Core data class for PolyLine handling.
[flightgear.git] / src / Navaids / PolyLine.hxx
1 /**
2  * Polyline - store geographic line-segments */
3
4 // Written by James Turner, started 2013.
5 //
6 // Copyright (C) 2013 James Turner <zakalawe@mac.com>
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifndef FG_POLY_LINE_HXX
23 #define FG_POLY_LINE_HXX
24
25 #include <vector>
26
27 #include <simgear/sg_inlines.h>
28 #include <simgear/structure/SGSharedPtr.hxx>
29 #include <simgear/math/SGMath.hxx>
30
31 namespace flightgear
32 {
33
34 typedef std::vector<SGGeod> SGGeodVec;
35     
36 class PolyLine;
37     
38 typedef SGSharedPtr<PolyLine> PolyLineRef;
39
40 typedef std::vector<PolyLineRef> PolyLineList;
41     
42 /**
43  * @class Store geographical linear data, with a type code.
44  *
45  * This is a basic in-memory model of GIS line data, without support for
46  * many features; especially there is no support for per-node attributes.
47  *
48  * PolyLines are added to the spatial index and can be queried by passing
49  * a search centre and cutoff distance.
50  */
51 class PolyLine : public SGReferenced
52 {
53 public:
54     virtual ~PolyLine();
55     
56     enum Type
57     {
58         INVALID = 0,
59         COASTLINE,
60         NATIONAL_BOUNDARY, /// aka a border
61         REGIONAL_BOUNDARY, /// state / province / country / department
62         RIVER,
63         // airspace types in the future
64         LAST_TYPE
65     };
66     
67     Type type() const
68     { return m_type; }
69     
70     /**
71      * number of points in this line - at least two.
72      */
73     unsigned int numPoints() const;
74     
75     SGGeod point(unsigned int aIndex) const;
76     
77     const SGGeodVec& points() const
78     { return m_data; }
79     
80     /**
81      * create poly line objects from raw input points and a type.
82      * input points will be subdivided so the bounding area of each
83      * polyline stays within some threshold.
84      *
85      */
86     static PolyLineList createChunked(Type aTy, const SGGeodVec& aRawPoints);
87     
88     /**
89      * retrieve all the lines within a range of a search point.
90      * lines are returned if any point is near the search location.
91      */
92     static PolyLineList linesNearPos(const SGGeod& aPos, double aRangeNm, Type aTy);
93     
94     class TypeFilter
95     {
96     public:
97         virtual bool pass(Type aTy) const = 0;
98     };
99     
100     static PolyLineList linesNearPos(const SGGeod& aPos, double aRangeNm, const TypeFilter& aFilter);
101 private:
102     void addToSpatialIndex() const;
103     
104     PolyLine(Type aTy, const SGGeodVec& aPoints);
105     
106     Type m_type;
107     SGGeodVec m_data;
108     // cache the bounding box?
109 };
110     
111
112     
113 } // of namespace flightgear
114
115 #endif