libosmscout  1.1.1
Preprocess.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_IMPORT_PREPROCESS_H
2 #define OSMSCOUT_IMPORT_PREPROCESS_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 <thread>
24 #include <memory>
25 #include <unordered_map>
26 
27 #include <osmscout/Tag.h>
29 
32 
33 #include <osmscout/import/Import.h>
38 #include <osmscout/import/RawWay.h>
40 
42 
43 namespace osmscout {
44  class Preprocess CLASS_FINAL : public ImportModule
45  {
46  public:
47  static const char* const RAWCOORDS_DAT;
48  static const char* const RAWNODES_DAT;
49  static const char* const RAWWAYS_DAT;
50  static const char* const RAWRELS_DAT;
51  static const char* const RAWCOASTLINE_DAT;
52  static const char* const RAWDATAPOLYGON_DAT;
53  static const char* const RAWTURNRESTR_DAT;
54  static const char* const RAWROUTEMASTER_DAT;
55  static const char* const RAWROUTE_DAT;
56 
57  private:
58  class Callback : public PreprocessorCallback
59  {
60  private:
61  struct ProcessedData
62  {
63  std::vector<RawCoord> rawCoords;
64  std::vector<RawNode> rawNodes;
65  std::vector<RawWay> rawWays;
66  std::vector<RawCoastline> rawCoastlines;
67  std::vector<RawCoastline> rawDatapolygon;
68  std::vector<RawRelation> multipolygons;
69  std::vector<TurnRestriction> turnRestriction;
70  std::vector<RawRelation> routeMasters;
71  std::vector<RawRelation> routes;
72  };
73 
74  // Should be unique_ptr but I get compiler errors if passing it to the WriteWorkerQueue
75  typedef std::shared_ptr<ProcessedData> ProcessedDataRef;
76 
77  private:
78  const TypeConfigRef typeConfig;
79  const ImportParameter& parameter;
80  Progress& progress;
81 
82  WorkQueue<ProcessedDataRef> blockWorkerQueue;
83  std::vector<std::thread> blockWorkerThreads;
84  WorkQueue<void> writeWorkerQueue;
85  std::thread writeWorkerThread;
86 
87  FileWriter rawCoordWriter;
88  FileWriter nodeWriter;
89  FileWriter wayWriter;
90  FileWriter coastlineWriter;
91  FileWriter datapolygonWriter;
92  FileWriter turnRestrictionWriter;
93  FileWriter multipolygonWriter;
94  FileWriter routeMasterWriter;
95  FileWriter routeWriter;
96 
97  bool readNodes;
98  bool readWays;
99  bool readRelations;
100 
101  uint32_t coordCount;
102  uint32_t nodeCount;
103  uint32_t wayCount;
104  uint32_t areaCount;
105  uint32_t relationCount;
106  uint32_t coastlineCount;
107  uint32_t datapolygonCount;
108  uint32_t turnRestrictionCount;
109  uint32_t multipolygonCount;
110  uint32_t routeMasterCount;
111  uint32_t routeCount;
112 
113  OSMId lastNodeId;
114  OSMId lastWayId;
115  OSMId lastRelationId;
116 
117  OSMId minNodeId;
118  OSMId maxNodeId;
119  OSMId minWayId;
120  OSMId maxWayId;
121  OSMId minRelationId;
122  OSMId maxRelationId;
123 
124  bool nodeSortingError;
125  bool waySortingError;
126  bool relationSortingError;
127 
128  GeoCoord minCoord;
129  GeoCoord maxCoord;
130 
131  std::vector<uint32_t> nodeStat;
132  std::vector<uint32_t> areaStat;
133  std::vector<uint32_t> wayStat;
134  std::vector<uint32_t> relStat;
135 
136  private:
137  bool IsTurnRestriction(const TagMap& tags,
138  TurnRestriction::Type& type) const;
139 
140 
141  bool IsMultipolygon(const TagMap& tags,
142  TypeInfoRef& type);
143 
144  bool IsRouteMaster(const TagMap& tags,
145  TypeInfoRef& type);
146 
147  bool IsRoute(const TagMap& tags,
148  TypeInfoRef& type);
149 
150  bool DumpDistribution();
151  bool DumpBoundingBox();
152 
153  void NodeSubTask(const RawNodeData& data,
154  ProcessedData& processed);
155  void WaySubTask(const RawWayData& data,
156  ProcessedData& processed);
157  void TurnRestrictionSubTask(const std::vector<RawRelation::Member>& members,
158  TurnRestriction::Type type,
159  ProcessedData& processed);
160  void MultipolygonSubTask(const TagMap& tags,
161  const std::vector<RawRelation::Member>& members,
162  OSMId id,
163  const TypeInfoRef& type,
164  ProcessedData& processed);
165  void RouteMasterSubTask(const TagMap& tags,
166  const std::vector<RawRelation::Member>& members,
167  OSMId id,
168  const TypeInfoRef& type,
169  ProcessedData& processed);
170  void RouteSubTask(const TagMap& tags,
171  const std::vector<RawRelation::Member>& members,
172  OSMId id,
173  const TypeInfoRef& type,
174  ProcessedData& processed);
175  void RelationSubTask(const RawRelationData& data,
176  ProcessedData& processed);
177 
178  ProcessedDataRef BlockTask(const RawBlockDataRef& data);
179  void BlockWorkerLoop();
180 
181  void WriteTask(std::shared_future<ProcessedDataRef>& processed);
182  void WriteWorkerLoop();
183 
184  public:
185  Callback(const TypeConfigRef& typeConfig,
186  const ImportParameter& parameter,
187  Progress& progress);
188 
189  bool Initialize();
190 
191  void ProcessBlock(RawBlockDataRef data) override;
192 
193  bool Cleanup(bool success);
194  };
195 
196  private:
197  bool ProcessFiles(const TypeConfigRef& typeConfig,
198  const ImportParameter& parameter,
199  Progress& progress,
200  Callback& callback);
201 
202  public:
203  void GetDescription(const ImportParameter& parameter,
204  ImportModuleDescription& description) const override;
205 
206  bool Import(const TypeConfigRef& typeConfig,
207  const ImportParameter& parameter,
208  Progress& progress) override;
209  };
210 }
211 
212 #endif
static const char *const RAWCOASTLINE_DAT
Definition: Preprocess.h:51
static const char *const RAWCOORDS_DAT
Definition: Preprocess.h:47
int64_t OSMId
Definition: OSMScoutTypes.h:34
static const char *const RAWTURNRESTR_DAT
Definition: Preprocess.h:53
Definition: Area.h:38
#define CLASS_FINAL
Definition: Compiler.h:26
Setup internal state of renderer for executing next steps with current projection and parameters...
Definition: MapPainter.h:57
Definition: Preprocessor.h:35
static const char *const RAWROUTEMASTER_DAT
Definition: Preprocess.h:54
static const char *const RAWNODES_DAT
Definition: Preprocess.h:48
static const char *const RAWROUTE_DAT
Definition: Preprocess.h:55
static const char *const RAWRELS_DAT
Definition: Preprocess.h:50
static const char *const RAWWAYS_DAT
Definition: Preprocess.h:49
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
static const char *const RAWDATAPOLYGON_DAT
Definition: Preprocess.h:52
std::unordered_map< TagId, std::string > TagMap
Definition: Tag.h:41
Definition: Progress.h:34
std::shared_ptr< TypeConfig > TypeConfigRef
Definition: TypeConfig.h:1227