initial commit

This commit is contained in:
Patrick Brosi 2018-06-09 17:14:08 +02:00
commit efcd3e1892
106 changed files with 27000 additions and 0 deletions

View file

@ -0,0 +1,38 @@
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
#ifndef UTIL_GEO_OUTPUT_GEOGRAPHJSONOUTPUT_H_
#define UTIL_GEO_OUTPUT_GEOGRAPHJSONOUTPUT_H_
#include <ostream>
#include <string>
#include "util/String.h"
#include "util/geo/output/GeoJsonOutput.h"
#include "util/graph/Graph.h"
using util::toString;
using util::graph::Graph;
namespace util {
namespace geo {
namespace output {
class GeoGraphJsonOutput {
public:
inline GeoGraphJsonOutput(){};
template <typename N, typename E>
void print(const 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);
};
#include "util/geo/output/GeoGraphJsonOutput.tpp"
}
}
}
#endif // UTIL_GEO_OUTPUT_GEOGRAPHJSONOUTPUT_H_

View file

@ -0,0 +1,62 @@
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
using util::geo::output::Attrs;
// _____________________________________________________________________________
template <typename T>
Line<T> GeoGraphJsonOutput::createLine(const util::geo::Point<T>& a,
const util::geo::Point<T>& b) {
Line<T> ret;
ret.push_back(a);
ret.push_back(b);
return ret;
}
// _____________________________________________________________________________
template <typename N, typename E>
void GeoGraphJsonOutput::print(const util::graph::Graph<N, E>& outG,
std::ostream& str) {
GeoJsonOutput _out(str);
// first pass, nodes
for (util::graph::Node<N, E>* n : outG.getNds()) {
if (!n->pl().getGeom()) continue;
Attrs props = {{"id", toString(n)},
{"deg", toString(n->getInDeg() + n->getOutDeg())},
{"deg_out", toString(n->getOutDeg())},
{"deg_in", toString(n->getInDeg())}};
n->pl().getAttrs(&props);
_out.print(*n->pl().getGeom(), props);
}
// second pass, edges
for (graph::Node<N, E>* n : outG.getNds()) {
for (graph::Edge<N, E>* e : n->getAdjListOut()) {
// to avoid double output for undirected graphs
if (e->getFrom() != n) continue;
Attrs props{{"from", toString(e->getFrom())},
{"to", toString(e->getTo())},
{"id", toString(e)}};
e->pl().getAttrs(&props);
if (!e->pl().getGeom() || !e->pl().getGeom()->size()) {
if (e->getFrom()->pl().getGeom()) {
auto a = *e->getFrom()->pl().getGeom();
if (e->getTo()->pl().getGeom()) {
auto b = *e->getTo()->pl().getGeom();
_out.print(createLine(a, b), props);
}
}
} else {
_out.print(*e->pl().getGeom(), props);
}
}
}
_out.flush();
}

View file

@ -0,0 +1,25 @@
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
//
#include "util/geo/output/GeoJsonOutput.h"
using namespace util;
using namespace geo;
using namespace output;
// _____________________________________________________________________________
GeoJsonOutput::GeoJsonOutput(std::ostream& str) : _wr(&str, 10, true) {
_wr.obj();
_wr.keyVal("type", "FeatureCollection");
_wr.key("features");
_wr.arr();
}
// _____________________________________________________________________________
GeoJsonOutput::~GeoJsonOutput() {
flush();
}
// _____________________________________________________________________________
void GeoJsonOutput::flush() { _wr.closeAll(); }

View file

@ -0,0 +1,41 @@
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
#ifndef UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_
#define UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_
#include <ostream>
#include <string>
#include <map>
#include "util/String.h"
#include "util/geo/Geo.h"
#include "util/json/JsonWriter.h"
namespace util {
namespace geo {
namespace output {
typedef std::map<std::string, std::string> Attrs;
class GeoJsonOutput {
public:
GeoJsonOutput(std::ostream& str);
~GeoJsonOutput();
template <typename T>
void print(const Point<T>& p, Attrs attrs);
template <typename T>
void print(const Line<T>& l, Attrs attrs);
void flush();
private:
json::JsonWriter _wr;
};
#include "util/geo/output/GeoJsonOutput.tpp"
}
}
}
#endif // UTIL_GEO_OUTPUT_GEOJSONOUTPUT_H_

View file

@ -0,0 +1,48 @@
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
// _____________________________________________________________________________
template <typename T>
void GeoJsonOutput::print(const Point<T>& p, Attrs attrs) {
_wr.obj();
_wr.keyVal("type", "Feature");
_wr.key("geometry");
_wr.obj();
_wr.keyVal("type", "Point");
_wr.key("coordinates");
_wr.arr();
_wr.val(p.template get<0>());
_wr.val(p.template get<1>());
_wr.close();
_wr.close();
_wr.key("properties");
_wr.obj(attrs);
_wr.close();
}
// _____________________________________________________________________________
template <typename T>
void GeoJsonOutput::print(const Line<T>& line, Attrs attrs) {
if (!line.size()) return;
_wr.obj();
_wr.keyVal("type", "Feature");
_wr.key("geometry");
_wr.obj();
_wr.keyVal("type", "LineString");
_wr.key("coordinates");
_wr.arr();
for (auto p : line) {
_wr.arr();
_wr.val(p.template get<0>());
_wr.val(p.template get<1>());
_wr.close();
}
_wr.close();
_wr.close();
_wr.key("properties");
_wr.obj(attrs);
_wr.close();
}