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
|
|
@ -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…
Add table
Add a link
Reference in a new issue