31 #include <boost/archive/binary_iarchive.hpp> 32 #include <boost/archive/binary_oarchive.hpp> 33 #include <boost/serialization/base_object.hpp> 34 #include <boost/filesystem/operations.hpp> 35 #include <boost/filesystem/path.hpp> 51 if (
nodes->size() > 0)
53 std::vector<FixedPoint> points;;
54 for (
auto& n : *
nodes)
55 points.push_back(n.getLocation());
62 std::vector<FixedRect> rects;
71 std::vector<FixedRect> rects;
75 relTree->build(rects, relationPath);
82 if (
nodes->size() > 0)
109 shared_ptr<std::vector<NodeId> > nodeIDs = boost::make_shared< std::vector<NodeId> >();
117 shared_ptr<std::vector<WayId> > wayIDs = boost::make_shared< std::vector<WayId> >();
125 shared_ptr<std::vector<RelId> > relationIDs = boost::make_shared< std::vector<RelId> >();
127 relTree->search(relationIDs, rect);
133 return &
nodes->at(
id.getRaw());
138 return &
ways->at(
id.getRaw());
148 LOG_SEV(geo_log, info) <<
"Load geodata from \"" << path <<
"\"";
151 std::vector<Archive::entry_t> entries;
155 std::ifstream ifs(path, std::ios::binary | std::ios::in);
156 ifs.seekg(entries[i++].offset);
157 boost::archive::binary_iarchive ia(ifs);
162 nodesTree->setLeafFile(path, entries[i].offset, entries[i].length);
166 waysTree->setLeafFile(path, entries[i].offset, entries[i].length);
170 relTree->setLeafFile(path, entries[i].offset, entries[i].length);
177 LOG_SEV(geo_log, info) <<
"Serialize to \"" << serPath <<
"\"";
179 std::ofstream ofs(serPath, std::ios::binary | std::ios::out);
180 boost::archive::binary_oarchive oa(ofs);
186 boost::filesystem::path out = boost::filesystem::absolute(boost::filesystem::path(outPath));
187 boost::filesystem::path base = out.parent_path();
188 string serPath = (base /
"data.ser").
string();
189 string nodesPath = (base /
"nodes.bin").
string();
190 string waysPath = (base /
"ways.bin").
string();
191 string relationsPath = (base /
"relations.bin").
string();
193 buildTrees(nodesPath, waysPath, relationsPath);
197 LOG_SEV(geo_log, info) <<
"Save geodata to \"" << outPath <<
"\"";
209 remove(serPath.c_str());
211 remove(nodesPath.c_str());
213 remove(waysPath.c_str());
215 remove(relationsPath.c_str());
225 coord_t maxX = std::numeric_limits<coord_t>::min();
226 coord_t maxY = std::numeric_limits<coord_t>::min();
227 coord_t minX = std::numeric_limits<coord_t>::max();
228 coord_t minY = std::numeric_limits<coord_t>::max();
230 const std::vector<NodeId>& nodeIDs = relation.
getNodeIDs();
231 if (nodeIDs.size() > 0)
240 const std::vector<WayId>& wayIDs = relation.
getWayIDs();
241 if (wayIDs.size() > 0)
244 minX = std::min(minX, result.
minX);
245 minY = std::min(minY, result.
minY);
246 maxX = std::max(maxX, result.
maxX);
247 maxY = std::max(maxY, result.
maxY);
250 if (maxX < minX || maxY < minY)
253 return FixedRect(minX, minY, maxX, maxY);
259 coord_t maxX = std::numeric_limits<coord_t>::min();
260 coord_t maxY = std::numeric_limits<coord_t>::min();
261 coord_t minX = std::numeric_limits<coord_t>::max();
262 coord_t minY = std::numeric_limits<coord_t>::max();
264 for (
NodeId i : nodeIDs) {
265 help =
nodes->at(i.getRaw()).getLocation();
267 maxX = std::max(maxX, help.
x);
268 maxY = std::max(maxY, help.
y);
269 minX = std::min(minX, help.
x);
270 minY = std::min(minY, help.
y);
273 if (maxX < minX || maxY < minY)
276 return FixedRect(minX, minY, maxX, maxY);
281 coord_t maxX = std::numeric_limits<coord_t>::min();
282 coord_t maxY = std::numeric_limits<coord_t>::min();
283 coord_t minX = std::numeric_limits<coord_t>::max();
284 coord_t minY = std::numeric_limits<coord_t>::max();
286 for (
WayId i : wayIDs) {
288 minX = std::min(minX, bounds.
minX);
289 minY = std::min(minY, bounds.
minY);
290 maxX = std::max(maxX, bounds.
maxX);
291 maxY = std::max(maxY, bounds.
maxY);
294 if (maxX < minX || maxY < minY)
297 return FixedRect(minX, minY, maxX, maxY);
TESTABLE FixedRect calculateBoundingBox(const Way &way) const
basic_rect< coord_t > FixedRect
void getEntries(std::vector< entry_t > &entries)
shared_ptr< std::vector< Relation > > relations
TESTABLE shared_ptr< std::vector< WayId > > getWayIDs(const FixedRect &rect) const
bool containsData(const FixedRect &rect) const
TESTABLE const std::vector< NodeId > & getNodeIDs() const
shared_ptr< std::vector< Way > > ways
TESTABLE void save(const string &path)
TESTABLE Way * getWay(WayId id) const
TESTABLE const std::vector< WayId > & getWayIDs() const
TESTABLE void insertWays(const shared_ptr< std::vector< Way > > &ways)
#define LOG_SEV(log, lvl)
shared_ptr< RTree< NodeId, FixedPoint > > nodesTree
note the trees are initialized by buildTree on serialisation
void addFile(const string &filePath)
void buildTrees(const string &nodePath, const string &wayPath, const string &relationPath)
This file is part of alaCarte.
void serialize(const string &serPath) const
TESTABLE shared_ptr< std::vector< RelId > > getRelationIDs(const FixedRect &rect) const
shared_ptr< RTree< RelId, FixedRect > > relTree
TESTABLE void insertRelations(const shared_ptr< std::vector< Relation > > &relations)
shared_ptr< RTree< WayId, FixedRect > > waysTree
TESTABLE Node * getNode(NodeId id) const
shared_ptr< std::vector< Node > > nodes
TESTABLE void load(const string &path)
static const char * help
Use Configuration::has to check weather the user wanted help.
TESTABLE void insertNodes(const shared_ptr< std::vector< Node > > &nodes)
TESTABLE Relation * getRelation(RelId id) const
TESTABLE shared_ptr< std::vector< NodeId > > getNodeIDs(const FixedRect &rect) const
const std::vector< NodeId > & getNodeIDs() const