make geometry precision configurable for build

This commit is contained in:
Patrick Brosi 2018-08-10 16:42:38 +02:00
parent 486a8136fd
commit 8446db5c4b
25 changed files with 222 additions and 208 deletions

View file

@ -29,12 +29,12 @@ bool BBoxIdx::contains(const Point<double>& p) const {
}
// _____________________________________________________________________________
util::geo::Box<double> BBoxIdx::getFullWebMercBox() const {
return util::geo::DBox(
util::geo::latLngToWebMerc<double>(_root.box.getLowerLeft().getY(),
_root.box.getLowerLeft().getX()),
util::geo::latLngToWebMerc<double>(_root.box.getUpperRight().getY(),
_root.box.getUpperRight().getX()));
BOX BBoxIdx::getFullWebMercBox() const {
return BOX(
util::geo::latLngToWebMerc<PFAEDLE_PRECISION>(
_root.box.getLowerLeft().getY(), _root.box.getLowerLeft().getX()),
util::geo::latLngToWebMerc<PFAEDLE_PRECISION>(
_root.box.getUpperRight().getY(), _root.box.getUpperRight().getX()));
}
// _____________________________________________________________________________

View file

@ -6,6 +6,7 @@
#define PFAEDLE_OSM_BBOXIDX_H_
#include <vector>
#include "pfaedle/Def.h"
#include "util/geo/Geo.h"
namespace pfaedle {
@ -35,7 +36,7 @@ class BBoxIdx {
bool contains(const Point<double>& box) const;
// Return the full total bounding box of this index
util::geo::Box<double> getFullWebMercBox() const;
BOX getFullWebMercBox() const;
// Return the size of this index
size_t size() const;

View file

@ -12,6 +12,7 @@
#include <string>
#include <utility>
#include <vector>
#include "pfaedle/Def.h"
#include "pfaedle/osm/BBoxIdx.h"
#include "pfaedle/osm/Osm.h"
#include "pfaedle/osm/OsmBuilder.h"
@ -136,7 +137,7 @@ void OsmBuilder::read(const std::string& path, const OsmReadOpts& opts,
for (double d : opts.maxSnapDistances) {
for (auto s : orphanStations) {
DPoint geom = *s->pl().getGeom();
POINT geom = *s->pl().getGeom();
NodePL pl = s->pl();
pl.getSI()->setIsFromOsm(false);
const auto& r = snapStation(g, &pl, &eg, &sng, opts, res, false, d);
@ -374,9 +375,10 @@ void OsmBuilder::readWriteWays(xml::File* i, util::xml::XmlWriter* o,
// _____________________________________________________________________________
NodePL OsmBuilder::plFromGtfs(const Stop* s, const OsmReadOpts& ops) const {
NodePL ret(util::geo::latLngToWebMerc<double>(s->getLat(), s->getLng()),
StatInfo(ops.statNormzer(s->getName()),
ops.trackNormzer(s->getPlatformCode()), false));
NodePL ret(
util::geo::latLngToWebMerc<PFAEDLE_PRECISION>(s->getLat(), s->getLng()),
StatInfo(ops.statNormzer(s->getName()),
ops.trackNormzer(s->getPlatformCode()), false));
if (s->getParentStation()) {
ret.getSI()->addAltName(ops.statNormzer(s->getParentStation()->getName()));
@ -705,7 +707,7 @@ void OsmBuilder::readNodes(xml::File* xml, Graph* g, const RelLst& rels,
keepAttrs, fl))
.id) {
Node* n = 0;
auto pos = util::geo::latLngToWebMerc<double>(nd.lat, nd.lng);
auto pos = util::geo::latLngToWebMerc<PFAEDLE_PRECISION>(nd.lat, nd.lng);
if (nodes->count(nd.id)) {
n = (*nodes)[nd.id];
n->pl().setGeom(pos);
@ -930,7 +932,7 @@ std::string OsmBuilder::getAttr(const DeepAttrRule& s, osmid id,
// _____________________________________________________________________________
Nullable<StatInfo> OsmBuilder::getStatInfo(Node* node, osmid nid,
const DPoint& pos, const AttrMap& m,
const POINT& pos, const AttrMap& m,
StAttrGroups* groups,
const RelMap& nodeRels,
const RelLst& rels,
@ -994,7 +996,7 @@ double OsmBuilder::dist(const Node* a, const Node* b) const {
}
// _____________________________________________________________________________
double OsmBuilder::webMercDistFactor(const util::geo::DPoint& a) const {
double OsmBuilder::webMercDistFactor(const POINT& a) const {
// euclidean distance on web mercator is in meters on equator,
// and proportional to cos(lat) in both y directions
@ -1035,7 +1037,7 @@ void OsmBuilder::fixGaps(Graph* g, NodeGrid* ng) const {
otherN = (*nb->getAdjListOut().begin())->getOtherNd(nb);
else
otherN = (*nb->getAdjListIn().begin())->getOtherNd(nb);
DLine l;
LINE l;
l.push_back(*otherN->pl().getGeom());
l.push_back(*n->pl().getGeom());
@ -1057,7 +1059,7 @@ void OsmBuilder::fixGaps(Graph* g, NodeGrid* ng) const {
// _____________________________________________________________________________
EdgeGrid OsmBuilder::buildEdgeIdx(Graph* g, size_t size,
const Box<double>& webMercBox) const {
const BOX& webMercBox) const {
EdgeGrid ret(size, size, webMercBox, false);
for (auto* n : *g->getNds()) {
for (auto* e : n->getAdjListOut()) {
@ -1070,7 +1072,7 @@ EdgeGrid OsmBuilder::buildEdgeIdx(Graph* g, size_t size,
// _____________________________________________________________________________
NodeGrid OsmBuilder::buildNodeIdx(Graph* g, size_t size,
const Box<double>& webMercBox,
const BOX& webMercBox,
bool which) const {
NodeGrid ret(size, size, webMercBox, false);
for (auto* n : *g->getNds()) {
@ -1083,9 +1085,8 @@ NodeGrid OsmBuilder::buildNodeIdx(Graph* g, size_t size,
}
// _____________________________________________________________________________
Node* OsmBuilder::depthSearch(const Edge* e, const StatInfo* si,
const util::geo::DPoint& p, double maxD,
int maxFullTurns, double minAngle,
Node* OsmBuilder::depthSearch(const Edge* e, const StatInfo* si, const POINT& p,
double maxD, int maxFullTurns, double minAngle,
const SearchFunc& sfunc) const {
// shortcuts
double dFrom = webMercMeterDist(*e->getFrom()->pl().getGeom(), p);
@ -1125,10 +1126,10 @@ Node* OsmBuilder::depthSearch(const Edge* e, const StatInfo* si,
if (cur.fromEdge &&
cur.node->getInDeg() + cur.node->getOutDeg() >
2) { // only intersection angles
const DPoint& toP = *cand->pl().getGeom();
const DPoint& fromP =
const POINT& toP = *cand->pl().getGeom();
const POINT& fromP =
*cur.fromEdge->getOtherNd(cur.node)->pl().getGeom();
const DPoint& nodeP = *cur.node->pl().getGeom();
const POINT& nodeP = *cur.node->pl().getGeom();
if (util::geo::innerProd(nodeP, fromP, toP) < minAngle) fullTurn = 1;
}
@ -1149,25 +1150,25 @@ Node* OsmBuilder::depthSearch(const Edge* e, const StatInfo* si,
}
// _____________________________________________________________________________
bool OsmBuilder::isBlocked(const Edge* e, const StatInfo* si,
const util::geo::DPoint& p, double maxD,
int maxFullTurns, double minAngle) const {
bool OsmBuilder::isBlocked(const Edge* e, const StatInfo* si, const POINT& p,
double maxD, int maxFullTurns,
double minAngle) const {
return depthSearch(e, si, p, maxD, maxFullTurns, minAngle, BlockSearch());
}
// _____________________________________________________________________________
Node* OsmBuilder::eqStatReach(const Edge* e, const StatInfo* si,
const util::geo::DPoint& p, double maxD,
int maxFullTurns, double minAngle) const {
Node* OsmBuilder::eqStatReach(const Edge* e, const StatInfo* si, const POINT& p,
double maxD, int maxFullTurns,
double minAngle) const {
return depthSearch(e, si, p, maxD, maxFullTurns, minAngle, EqSearch());
}
// _____________________________________________________________________________
void OsmBuilder::getEdgCands(const DPoint& geom, EdgeCandPQ* ret, EdgeGrid* eg,
void OsmBuilder::getEdgCands(const POINT& geom, EdgeCandPQ* ret, EdgeGrid* eg,
double d) const {
double distor = webMercDistFactor(geom);
std::set<Edge*> neighs;
Box<double> box = util::geo::pad(util::geo::getBoundingBox(geom), d / distor);
BOX box = util::geo::pad(util::geo::getBoundingBox(geom), d / distor);
eg->get(box, &neighs);
for (auto* e : neighs) {
@ -1186,7 +1187,7 @@ std::set<Node*> OsmBuilder::getMatchingNds(const NodePL& s, NodeGrid* ng,
std::set<Node*> ret;
double distor = webMercDistFactor(*s.getGeom());
std::set<Node*> neighs;
Box<double> box =
BOX box =
util::geo::pad(util::geo::getBoundingBox(*s.getGeom()), d / distor);
ng->get(box, &neighs);
@ -1204,7 +1205,7 @@ std::set<Node*> OsmBuilder::getMatchingNds(const NodePL& s, NodeGrid* ng,
Node* OsmBuilder::getMatchingNd(const NodePL& s, NodeGrid* ng, double d) const {
double distor = webMercDistFactor(*s.getGeom());
std::set<Node*> neighs;
Box<double> box =
BOX box =
util::geo::pad(util::geo::getBoundingBox(*s.getGeom()), d / distor);
ng->get(box, &neighs);
@ -1282,7 +1283,7 @@ std::set<Node*> OsmBuilder::snapStation(Graph* g, NodePL* s, EdgeGrid* eg,
auto ne = g->addEdg(e->getFrom(), n, e->pl());
ne->pl().setLength(webMercDist(n, e->getFrom()));
DLine l;
LINE l;
l.push_back(*e->getFrom()->pl().getGeom());
l.push_back(*n->pl().getGeom());
*ne->pl().getGeom() = l;
@ -1290,7 +1291,7 @@ std::set<Node*> OsmBuilder::snapStation(Graph* g, NodePL* s, EdgeGrid* eg,
auto nf = g->addEdg(n, e->getTo(), e->pl());
nf->pl().setLength(webMercDist(n, e->getTo()));
DLine ll;
LINE ll;
ll.push_back(*n->pl().getGeom());
ll.push_back(*e->getTo()->pl().getGeom());
*nf->pl().getGeom() = ll;

View file

@ -5,14 +5,15 @@
#ifndef PFAEDLE_OSM_OSMBUILDER_H_
#define PFAEDLE_OSM_OSMBUILDER_H_
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "ad/cppgtfs/gtfs/Feed.h"
#include "pfaedle/Def.h"
#include "pfaedle/osm/BBoxIdx.h"
#include "pfaedle/osm/OsmFilter.h"
#include "pfaedle/osm/OsmIdSet.h"
@ -23,6 +24,7 @@
#include "pfaedle/trgraph/Normalizer.h"
#include "pfaedle/trgraph/StatInfo.h"
#include "util/Nullable.h"
#include "util/geo/Geo.h"
#include "util/xml/XmlWriter.h"
#include "xml/File.h"
@ -89,7 +91,6 @@ class OsmBuilder {
const BBoxIdx& box, size_t gridSize, router::FeedStops* fs,
Restrictor* res);
// Based on the list of options, read an OSM file from in and output an
// OSM file to out which contains exactly the entities that are needed
// from the file at in
@ -162,7 +163,7 @@ class OsmBuilder {
OsmRel nextRel(xml::File* xml, const OsmFilter& filter,
const AttrKeySet& keepAttrs) const;
Nullable<StatInfo> getStatInfo(Node* node, osmid nid, const DPoint& pos,
Nullable<StatInfo> getStatInfo(Node* node, osmid nid, const POINT& pos,
const AttrMap& m, StAttrGroups* groups,
const RelMap& nodeRels, const RelLst& rels,
const OsmReadOpts& ops) const;
@ -172,14 +173,12 @@ class OsmBuilder {
void deleteOrphEdgs(Graph* g) const;
double dist(const Node* a, const Node* b) const;
double webMercDist(const Node* a, const Node* b) const;
double webMercDistFactor(const DPoint& a) const;
double webMercDistFactor(const POINT& a) const;
NodeGrid buildNodeIdx(Graph* g, size_t size,
const util::geo::Box<double>& webMercBox,
NodeGrid buildNodeIdx(Graph* g, size_t size, const BOX& webMercBox,
bool which) const;
EdgeGrid buildEdgeIdx(Graph* g, size_t size,
const util::geo::Box<double>& webMercBox) const;
EdgeGrid buildEdgeIdx(Graph* g, size_t size, const BOX& webMercBox) const;
void fixGaps(Graph* g, NodeGrid* ng) const;
void collapseEdges(Graph* g) const;
@ -190,7 +189,7 @@ class OsmBuilder {
uint32_t writeComps(Graph* g) const;
bool edgesSim(const Edge* a, const Edge* b) const;
const EdgePL& mergeEdgePL(Edge* a, Edge* b) const;
void getEdgCands(const DPoint& s, EdgeCandPQ* ret, EdgeGrid* eg,
void getEdgCands(const POINT& s, EdgeCandPQ* ret, EdgeGrid* eg,
double d) const;
std::set<Node*> getMatchingNds(const NodePL& s, NodeGrid* ng, double d) const;
@ -204,15 +203,15 @@ class OsmBuilder {
// Checks if from the edge e, a station similar to si can be reach with less
// than maxD distance and less or equal to "maxFullTurns" full turns. If
// such a station exists, it is returned. If not, 0 is returned.
Node* eqStatReach(const Edge* e, const StatInfo* si, const DPoint& p,
Node* eqStatReach(const Edge* e, const StatInfo* si, const POINT& p,
double maxD, int maxFullTurns, double maxAng) const;
Node* depthSearch(const Edge* e, const StatInfo* si,
const DPoint& p, double maxD, int maxFullTurns,
double minAngle, const SearchFunc& sfunc) const;
Node* depthSearch(const Edge* e, const StatInfo* si, const POINT& p,
double maxD, int maxFullTurns, double minAngle,
const SearchFunc& sfunc) const;
bool isBlocked(const Edge* e, const StatInfo* si, const DPoint& p,
double maxD, int maxFullTurns, double minAngle) const;
bool isBlocked(const Edge* e, const StatInfo* si, const POINT& p, double maxD,
int maxFullTurns, double minAngle) const;
StatGroup* groupStats(const NodeSet& s) const;