output all GeoJSON as WGS84 to be RFC 7946 conform
This commit is contained in:
parent
27da2a9c9e
commit
feacae92ef
9 changed files with 5369 additions and 4282 deletions
9558
geo/pfaedle.qgs
9558
geo/pfaedle.qgs
File diff suppressed because it is too large
Load diff
|
@ -257,7 +257,7 @@ int main(int argc, char** argv) {
|
|||
util::geo::output::GeoGraphJsonOutput out;
|
||||
mkdir(cfg.dbgOutputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
std::ofstream fstr(cfg.dbgOutputPath + "/graph.json");
|
||||
out.print(*shapeBuilder.getGraph(), fstr);
|
||||
out.printLatLng(*shapeBuilder.getGraph(), fstr);
|
||||
fstr.close();
|
||||
}
|
||||
|
||||
|
@ -270,9 +270,7 @@ int main(int argc, char** argv) {
|
|||
auto l = shapeBuilder.shapeL(singleTrip);
|
||||
|
||||
// reproject to WGS84 to match RFC 7946
|
||||
for (auto& p : l) {
|
||||
p = util::geo::webMercToLatLng<double>(p.getX(), p.getY());
|
||||
}
|
||||
o.printLatLng(l, {});
|
||||
|
||||
o.flush();
|
||||
pstr.close();
|
||||
|
@ -288,7 +286,7 @@ int main(int argc, char** argv) {
|
|||
LOG(INFO) << "Outputting trgraph" + filePost + ".json...";
|
||||
mkdir(cfg.dbgOutputPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
std::ofstream fstr(cfg.dbgOutputPath + "/trgraph" + filePost + ".json");
|
||||
out.print(ng, fstr);
|
||||
out.printLatLng(ng, fstr);
|
||||
fstr.close();
|
||||
}
|
||||
} catch (const xml::XmlFileException& ex) {
|
||||
|
|
|
@ -107,12 +107,12 @@ double Collector::add(const Trip* t, const Shape* oldS, const Shape& newS,
|
|||
LINE newLCut;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ struct RoutingOpts {
|
|||
bool noSelfHops;
|
||||
};
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline bool operator==(const RoutingOpts& a, const RoutingOpts& b) {
|
||||
return fabs(a.fullTurnPunishFac - b.fullTurnPunishFac) < 0.01 &&
|
||||
fabs(a.fullTurnAngle - b.fullTurnAngle) < 0.01 &&
|
||||
|
@ -106,22 +107,27 @@ struct EdgeCost {
|
|||
double getValue() const { return _cost; }
|
||||
};
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline EdgeCost operator+(const EdgeCost& a, const EdgeCost& b) {
|
||||
return EdgeCost(a.getValue() + b.getValue());
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline bool operator<=(const EdgeCost& a, const EdgeCost& b) {
|
||||
return a.getValue() <= b.getValue();
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline bool operator==(const EdgeCost& a, const EdgeCost& b) {
|
||||
return a.getValue() == b.getValue();
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline bool operator>(const EdgeCost& a, const EdgeCost& b) {
|
||||
return a.getValue() > b.getValue();
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
template <typename F>
|
||||
inline bool angSmaller(const Point<F>& f, const Point<F>& m, const Point<F>& t,
|
||||
double ang) {
|
||||
|
@ -152,6 +158,7 @@ typedef std::vector<EdgeListHop> EdgeListHops;
|
|||
|
||||
typedef std::set<Route::TYPE> MOTs;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline MOTs motISect(const MOTs& a, const MOTs& b) {
|
||||
MOTs ret;
|
||||
for (auto mot : a)
|
||||
|
@ -159,6 +166,7 @@ inline MOTs motISect(const MOTs& a, const MOTs& b) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline pfaedle::router::FeedStops writeMotStops(const pfaedle::gtfs::Feed* feed,
|
||||
const MOTs mots,
|
||||
const std::string& tid) {
|
||||
|
@ -183,6 +191,7 @@ inline pfaedle::router::FeedStops writeMotStops(const pfaedle::gtfs::Feed* feed,
|
|||
return ret;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
inline std::string getMotStr(const MOTs& mots) {
|
||||
bool first = false;
|
||||
std::string motStr;
|
||||
|
|
|
@ -130,7 +130,7 @@ EdgeListHops ShapeBuilder::route(const router::NodeCandRoute& ncr,
|
|||
LOG(INFO) << "Outputting combgraph.json...";
|
||||
std::ofstream pstr(_cfg.dbgOutputPath + "/combgraph.json");
|
||||
GeoGraphJsonOutput o;
|
||||
o.print(g, pstr);
|
||||
o.printLatLng(g, pstr);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -18,13 +18,23 @@ namespace output {
|
|||
class GeoGraphJsonOutput {
|
||||
public:
|
||||
inline GeoGraphJsonOutput(){};
|
||||
|
||||
// print a graph to the provided path
|
||||
template <typename N, typename E>
|
||||
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:
|
||||
template <typename T>
|
||||
Line<T> createLine(const util::geo::Point<T>& a,
|
||||
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"
|
||||
|
|
|
@ -16,6 +16,20 @@ Line<T> GeoGraphJsonOutput::createLine(const util::geo::Point<T>& a,
|
|||
template <typename N, typename E>
|
||||
void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG,
|
||||
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);
|
||||
|
||||
// first pass, nodes
|
||||
|
@ -30,7 +44,11 @@ void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG,
|
|||
auto addProps = n->pl().getAttrs();
|
||||
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
|
||||
|
@ -50,11 +68,19 @@ void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG,
|
|||
auto a = *e->getFrom()->pl().getGeom();
|
||||
if (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 {
|
||||
_out.print(*e->pl().getGeom(), props);
|
||||
if (proj) {
|
||||
_out.printLatLng(*e->pl().getGeom(), props);
|
||||
} else {
|
||||
_out.print(*e->pl().getGeom(), props);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#ifndef UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_
|
||||
#define UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_
|
||||
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "util/String.h"
|
||||
#include "util/geo/Geo.h"
|
||||
#include "util/json/Writer.h"
|
||||
|
@ -21,10 +21,19 @@ class GeoJsonOutput {
|
|||
GeoJsonOutput(std::ostream& str);
|
||||
GeoJsonOutput(std::ostream& str, json::Val attrs);
|
||||
~GeoJsonOutput();
|
||||
|
||||
template <typename T>
|
||||
void print(const Point<T>& p, json::Val attrs);
|
||||
|
||||
template <typename T>
|
||||
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();
|
||||
|
||||
private:
|
||||
|
@ -32,7 +41,6 @@ class GeoJsonOutput {
|
|||
};
|
||||
|
||||
#include "util/geo/output/GeoJsonOutput.tpp"
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,3 +46,19 @@ void GeoJsonOutput::print(const Line<T>& line, json::Val attrs) {
|
|||
_wr.val(attrs);
|
||||
_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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue