output all GeoJSON as WGS84 to be RFC 7946 conform

This commit is contained in:
Patrick Brosi 2019-07-23 22:47:35 +02:00
parent 27da2a9c9e
commit feacae92ef
9 changed files with 5369 additions and 4282 deletions

File diff suppressed because it is too large Load diff

View file

@ -257,7 +257,7 @@ int main(int argc, char** argv) {
util::geo::output::GeoGraphJsonOutput out; util::geo::output::GeoGraphJsonOutput out;
mkdir(cfg.dbgOutputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); mkdir(cfg.dbgOutputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
std::ofstream fstr(cfg.dbgOutputPath + "/graph.json"); std::ofstream fstr(cfg.dbgOutputPath + "/graph.json");
out.print(*shapeBuilder.getGraph(), fstr); out.printLatLng(*shapeBuilder.getGraph(), fstr);
fstr.close(); fstr.close();
} }
@ -270,9 +270,7 @@ int main(int argc, char** argv) {
auto l = shapeBuilder.shapeL(singleTrip); auto l = shapeBuilder.shapeL(singleTrip);
// reproject to WGS84 to match RFC 7946 // reproject to WGS84 to match RFC 7946
for (auto& p : l) { o.printLatLng(l, {});
p = util::geo::webMercToLatLng<double>(p.getX(), p.getY());
}
o.flush(); o.flush();
pstr.close(); pstr.close();
@ -288,7 +286,7 @@ int main(int argc, char** argv) {
LOG(INFO) << "Outputting trgraph" + filePost + ".json..."; LOG(INFO) << "Outputting trgraph" + filePost + ".json...";
mkdir(cfg.dbgOutputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); mkdir(cfg.dbgOutputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
std::ofstream fstr(cfg.dbgOutputPath + "/trgraph" + filePost + ".json"); std::ofstream fstr(cfg.dbgOutputPath + "/trgraph" + filePost + ".json");
out.print(ng, fstr); out.printLatLng(ng, fstr);
fstr.close(); fstr.close();
} }
} catch (const xml::XmlFileException& ex) { } catch (const xml::XmlFileException& ex) {

View file

@ -107,12 +107,12 @@ double Collector::add(const Trip* t, const Shape* oldS, const Shape& newS,
LINE newLCut; LINE newLCut;
for (auto oldL : oldSegs) { for (auto oldL : oldSegs) {
gjout.print(oldL, util::json::Dict{{"ver", "old"}}); gjout.printLatLng(oldL, util::json::Dict{{"ver", "old"}});
oldLCut.insert(oldLCut.end(), oldL.begin(), oldL.end()); oldLCut.insert(oldLCut.end(), oldL.begin(), oldL.end());
} }
for (auto newL : newSegs) { for (auto newL : newSegs) {
gjout.print(newL, util::json::Dict{{"ver", "new"}}); gjout.printLatLng(newL, util::json::Dict{{"ver", "new"}});
newLCut.insert(newLCut.end(), newL.begin(), newL.end()); newLCut.insert(newLCut.end(), newL.begin(), newL.end());
} }

View file

@ -57,6 +57,7 @@ struct RoutingOpts {
bool noSelfHops; bool noSelfHops;
}; };
// _____________________________________________________________________________
inline bool operator==(const RoutingOpts& a, const RoutingOpts& b) { inline bool operator==(const RoutingOpts& a, const RoutingOpts& b) {
return fabs(a.fullTurnPunishFac - b.fullTurnPunishFac) < 0.01 && return fabs(a.fullTurnPunishFac - b.fullTurnPunishFac) < 0.01 &&
fabs(a.fullTurnAngle - b.fullTurnAngle) < 0.01 && fabs(a.fullTurnAngle - b.fullTurnAngle) < 0.01 &&
@ -106,22 +107,27 @@ struct EdgeCost {
double getValue() const { return _cost; } double getValue() const { return _cost; }
}; };
// _____________________________________________________________________________
inline EdgeCost operator+(const EdgeCost& a, const EdgeCost& b) { inline EdgeCost operator+(const EdgeCost& a, const EdgeCost& b) {
return EdgeCost(a.getValue() + b.getValue()); return EdgeCost(a.getValue() + b.getValue());
} }
// _____________________________________________________________________________
inline bool operator<=(const EdgeCost& a, const EdgeCost& b) { inline bool operator<=(const EdgeCost& a, const EdgeCost& b) {
return a.getValue() <= b.getValue(); return a.getValue() <= b.getValue();
} }
// _____________________________________________________________________________
inline bool operator==(const EdgeCost& a, const EdgeCost& b) { inline bool operator==(const EdgeCost& a, const EdgeCost& b) {
return a.getValue() == b.getValue(); return a.getValue() == b.getValue();
} }
// _____________________________________________________________________________
inline bool operator>(const EdgeCost& a, const EdgeCost& b) { inline bool operator>(const EdgeCost& a, const EdgeCost& b) {
return a.getValue() > b.getValue(); return a.getValue() > b.getValue();
} }
// _____________________________________________________________________________
template <typename F> template <typename F>
inline bool angSmaller(const Point<F>& f, const Point<F>& m, const Point<F>& t, inline bool angSmaller(const Point<F>& f, const Point<F>& m, const Point<F>& t,
double ang) { double ang) {
@ -152,6 +158,7 @@ typedef std::vector<EdgeListHop> EdgeListHops;
typedef std::set<Route::TYPE> MOTs; typedef std::set<Route::TYPE> MOTs;
// _____________________________________________________________________________
inline MOTs motISect(const MOTs& a, const MOTs& b) { inline MOTs motISect(const MOTs& a, const MOTs& b) {
MOTs ret; MOTs ret;
for (auto mot : a) for (auto mot : a)
@ -159,6 +166,7 @@ inline MOTs motISect(const MOTs& a, const MOTs& b) {
return ret; return ret;
} }
// _____________________________________________________________________________
inline pfaedle::router::FeedStops writeMotStops(const pfaedle::gtfs::Feed* feed, inline pfaedle::router::FeedStops writeMotStops(const pfaedle::gtfs::Feed* feed,
const MOTs mots, const MOTs mots,
const std::string& tid) { const std::string& tid) {
@ -183,6 +191,7 @@ inline pfaedle::router::FeedStops writeMotStops(const pfaedle::gtfs::Feed* feed,
return ret; return ret;
} }
// _____________________________________________________________________________
inline std::string getMotStr(const MOTs& mots) { inline std::string getMotStr(const MOTs& mots) {
bool first = false; bool first = false;
std::string motStr; std::string motStr;

View file

@ -130,7 +130,7 @@ EdgeListHops ShapeBuilder::route(const router::NodeCandRoute& ncr,
LOG(INFO) << "Outputting combgraph.json..."; LOG(INFO) << "Outputting combgraph.json...";
std::ofstream pstr(_cfg.dbgOutputPath + "/combgraph.json"); std::ofstream pstr(_cfg.dbgOutputPath + "/combgraph.json");
GeoGraphJsonOutput o; GeoGraphJsonOutput o;
o.print(g, pstr); o.printLatLng(g, pstr);
} }
return ret; return ret;

View file

@ -18,13 +18,23 @@ namespace output {
class GeoGraphJsonOutput { class GeoGraphJsonOutput {
public: public:
inline GeoGraphJsonOutput(){}; inline GeoGraphJsonOutput(){};
// print a graph to the provided path
template <typename N, typename E> template <typename N, typename E>
void print(const util::graph::Graph<N, E>& outG, std::ostream& str); void print(const util::graph::Graph<N, E>& outG, std::ostream& str);
// print a graph to the provided path, but treat coordinates as Web Mercator coordinates and reproject to WGS84
template <typename N, typename E>
void printLatLng(const util::graph::Graph<N, E>& outG, std::ostream& str);
private: private:
template <typename T> template <typename T>
Line<T> createLine(const util::geo::Point<T>& a, Line<T> createLine(const util::geo::Point<T>& a,
const util::geo::Point<T>& b); const util::geo::Point<T>& b);
// print a graph to the provided path
template <typename N, typename E>
void printImpl(const util::graph::Graph<N, E>& outG, std::ostream& str, bool proj);
}; };
#include "util/geo/output/GeoGraphJsonOutput.tpp" #include "util/geo/output/GeoGraphJsonOutput.tpp"

View file

@ -16,6 +16,20 @@ Line<T> GeoGraphJsonOutput::createLine(const util::geo::Point<T>& a,
template <typename N, typename E> template <typename N, typename E>
void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG, void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG,
std::ostream& str) { std::ostream& str) {
printImpl(outG, str, false);
}
// _____________________________________________________________________________
template <typename N, typename E>
void GeoGraphJsonOutput::printLatLng(const util::graph::Graph<N, E>& outG,
std::ostream& str) {
printImpl(outG, str, true);
}
// _____________________________________________________________________________
template <typename N, typename E>
void GeoGraphJsonOutput::printImpl(const util::graph::Graph<N, E>& outG,
std::ostream& str, bool proj) {
GeoJsonOutput _out(str); GeoJsonOutput _out(str);
// first pass, nodes // first pass, nodes
@ -30,7 +44,11 @@ void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG,
auto addProps = n->pl().getAttrs(); auto addProps = n->pl().getAttrs();
props.insert(addProps.begin(), addProps.end()); props.insert(addProps.begin(), addProps.end());
_out.print(*n->pl().getGeom(), props); if (proj) {
_out.printLatLng(*n->pl().getGeom(), props);
} else {
_out.print(*n->pl().getGeom(), props);
}
} }
// second pass, edges // second pass, edges
@ -50,11 +68,19 @@ void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG,
auto a = *e->getFrom()->pl().getGeom(); auto a = *e->getFrom()->pl().getGeom();
if (e->getTo()->pl().getGeom()) { if (e->getTo()->pl().getGeom()) {
auto b = *e->getTo()->pl().getGeom(); auto b = *e->getTo()->pl().getGeom();
_out.print(createLine(a, b), props); if (proj) {
_out.printLatLng(createLine(a, b), props);
} else {
_out.print(createLine(a, b), props);
}
} }
} }
} else { } else {
_out.print(*e->pl().getGeom(), props); if (proj) {
_out.printLatLng(*e->pl().getGeom(), props);
} else {
_out.print(*e->pl().getGeom(), props);
}
} }
} }
} }

View file

@ -5,9 +5,9 @@
#ifndef UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_ #ifndef UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_
#define UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_ #define UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_
#include <map>
#include <ostream> #include <ostream>
#include <string> #include <string>
#include <map>
#include "util/String.h" #include "util/String.h"
#include "util/geo/Geo.h" #include "util/geo/Geo.h"
#include "util/json/Writer.h" #include "util/json/Writer.h"
@ -21,10 +21,19 @@ class GeoJsonOutput {
GeoJsonOutput(std::ostream& str); GeoJsonOutput(std::ostream& str);
GeoJsonOutput(std::ostream& str, json::Val attrs); GeoJsonOutput(std::ostream& str, json::Val attrs);
~GeoJsonOutput(); ~GeoJsonOutput();
template <typename T> template <typename T>
void print(const Point<T>& p, json::Val attrs); void print(const Point<T>& p, json::Val attrs);
template <typename T> template <typename T>
void print(const Line<T>& l, json::Val attrs); void print(const Line<T>& l, json::Val attrs);
template <typename T>
void printLatLng(const Point<T>& p, json::Val attrs);
template <typename T>
void printLatLng(const Line<T>& l, json::Val attrs);
void flush(); void flush();
private: private:
@ -32,7 +41,6 @@ class GeoJsonOutput {
}; };
#include "util/geo/output/GeoJsonOutput.tpp" #include "util/geo/output/GeoJsonOutput.tpp"
} }
} }
} }

View file

@ -46,3 +46,19 @@ void GeoJsonOutput::print(const Line<T>& line, json::Val attrs) {
_wr.val(attrs); _wr.val(attrs);
_wr.close(); _wr.close();
} }
// _____________________________________________________________________________
template <typename T>
void GeoJsonOutput::printLatLng(const Point<T>& p, json::Val attrs) {
auto projP = util::geo::webMercToLatLng<double>(p.getX(), p.getY());
print(projP, attrs);
}
// _____________________________________________________________________________
template <typename T>
void GeoJsonOutput::printLatLng(const Line<T>& line, json::Val attrs) {
Line<T> projL;
for (auto p : line) projL.push_back(util::geo::webMercToLatLng<double>(p.getX(), p.getY()));
print(projL, attrs);
}