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