libosmscout  1.1.1
Way.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_WAY_H
2 #define OSMSCOUT_WAY_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2009 Tim Teulings
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <memory>
24 
25 #include <osmscout/GeoCoord.h>
26 #include <osmscout/Point.h>
27 #include <osmscout/Tag.h>
28 #include <osmscout/TypeConfig.h>
29 
32 #include <osmscout/util/GeoBox.h>
33 #include <osmscout/util/Geometry.h>
34 #include <osmscout/util/Progress.h>
35 
37 
38 namespace osmscout {
39 
40  class OSMSCOUT_API Way CLASS_FINAL
41  {
42  private:
43  FeatureValueBuffer featureValueBuffer;
44 
45  FileOffset fileOffset=0;
46  FileOffset nextFileOffset=0;
47 
48 
49  public:
56  std::vector<Point> nodes;
57  std::vector<SegmentGeoBox> segments;
58  GeoBox bbox;
59 
60  public:
61  Way() = default;
62 
64  {
65  return fileOffset;
66  }
67 
69  {
70  return nextFileOffset;
71  }
72 
73  ObjectFileRef GetObjectFileRef() const
74  {
75  return {fileOffset,refWay};
76  }
77 
79  {
80  return featureValueBuffer.GetType();
81  }
82 
83  size_t GetFeatureCount() const
84  {
85  return featureValueBuffer.GetType()->GetFeatureCount();
86  }
87 
88  bool HasFeature(size_t idx) const
89  {
90  return featureValueBuffer.HasFeature(idx);
91  }
92 
93  const FeatureInstance& GetFeature(size_t idx) const
94  {
95  return featureValueBuffer.GetType()->GetFeature(idx);
96  }
97 
98  FeatureValue* GetFeatureValue(size_t idx) const
99  {
100  return featureValueBuffer.GetValue(idx);
101  }
102 
103  void UnsetFeature(size_t idx)
104  {
105  featureValueBuffer.FreeValue(idx);
106  }
107 
108  const FeatureValueBuffer& GetFeatureValueBuffer() const
109  {
110  return featureValueBuffer;
111  }
112 
113  bool IsCircular() const
114  {
115  return nodes[0].GetId()!=0 &&
116  nodes[0].GetId()==nodes[nodes.size()-1].GetId();
117  }
118 
119  Id GetSerial(size_t index) const
120  {
121  return nodes[index].GetSerial();
122  }
123 
124  Id GetId(size_t index) const
125  {
126  return nodes[index].GetId();
127  }
128 
129  Id GetFrontId() const
130  {
131  return nodes.front().GetId();
132  }
133 
134  Id GetBackId() const
135  {
136  return nodes.back().GetId();
137  }
138 
139  const Point& GetPoint(size_t index) const
140  {
141  return nodes[index];
142  }
143 
144  const GeoCoord& GetCoord(size_t index) const
145  {
146  return nodes[index].GetCoord();
147  }
148 
149  GeoBox GetBoundingBox() const
150  {
151  if (bbox.IsValid() || nodes.empty()) {
152  return bbox;
153  }
154  GeoBox boundingBox;
155 
157  boundingBox);
158 
159  return boundingBox;
160  }
161 
171  bool Intersects(const GeoBox& boundingBox) const
172  {
173  return GetBoundingBox().Intersects(boundingBox);
174  }
175 
176  bool GetCenter(GeoCoord& center) const;
177 
178  bool GetNodeIndexByNodeId(Id id,
179  size_t& index) const;
180 
181  void SetType(const TypeInfoRef& type)
182  {
183  featureValueBuffer.SetType(type);
184  }
185 
186  void SetFeatures(const FeatureValueBuffer& buffer)
187  {
188  featureValueBuffer.Set(buffer);
189  }
190 
191  void Read(const TypeConfig& typeConfig,
192  FileScanner& scanner);
193  void ReadOptimized(const TypeConfig& typeConfig,
194  FileScanner& scanner);
195 
196  void Write(const TypeConfig& typeConfig,
197  FileWriter& writer) const;
198  void WriteOptimized(const TypeConfig& typeConfig,
199  FileWriter& writer) const;
200  };
201 
202  using WayRef = std::shared_ptr<Way>;
203 }
204 
205 #endif
Id GetBackId() const
Definition: Way.h:134
std::vector< SegmentGeoBox > segments
Precomputed (cache) segment bounding boxes for optimisation.
Definition: Way.h:57
FileOffset GetFileOffset() const
Definition: Way.h:63
bool Intersects(const GeoBox &boundingBox) const
Definition: Way.h:171
uint64_t Id
Definition: OSMScoutTypes.h:41
bool IsCircular() const
Definition: Way.h:113
const FeatureValueBuffer & GetFeatureValueBuffer() const
Definition: Way.h:108
Id GetSerial(size_t index) const
Definition: Way.h:119
Id GetId(size_t index) const
Definition: Way.h:124
ObjectFileRef GetObjectFileRef() const
Definition: Way.h:73
TypeInfoRef GetType() const
Definition: Way.h:78
std::shared_ptr< Way > WayRef
Definition: Way.h:202
void GetBoundingBox(const std::vector< N > &nodes, double &minLon, double &maxLon, double &minLat, double &maxLat)
Definition: Geometry.h:107
FileOffset GetNextFileOffset() const
Definition: Way.h:68
void SetType(const TypeInfoRef &type)
Definition: Way.h:181
bool HasFeature(size_t idx) const
Definition: Way.h:88
Definition: Area.h:38
GeoBox GetBoundingBox() const
Definition: Way.h:149
std::vector< Point > nodes
List of nodes.
Definition: Way.h:56
const Point & GetPoint(size_t index) const
Definition: Way.h:139
size_t GetFeatureCount() const
Definition: Way.h:83
Definition: TypeFeature.h:40
Id GetFrontId() const
Definition: Way.h:129
FeatureValue * GetFeatureValue(size_t idx) const
Definition: Way.h:98
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
void UnsetFeature(size_t idx)
Definition: Way.h:103
const GeoCoord & GetCoord(size_t index) const
Definition: Way.h:144
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
const FeatureInstance & GetFeature(size_t idx) const
Definition: Way.h:93
Definition: ObjectRef.h:136
void SetFeatures(const FeatureValueBuffer &buffer)
Definition: Way.h:186