if no GTFS feed is supplied, use the XML input bounding box (this allows XML filtering without GTFS feeds), write <osm> tag with "version" and "generator" attributes. Fixes #26

This commit is contained in:
Patrick Brosi 2022-11-03 13:26:54 +01:00
parent 3e6e7ebfed
commit 59d4f96c68

View file

@ -3,6 +3,7 @@
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de> // Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
#include <float.h> #include <float.h>
#include <algorithm> #include <algorithm>
#include <exception> #include <exception>
#include <iostream> #include <iostream>
@ -12,7 +13,9 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "pfaedle/Def.h" #include "pfaedle/Def.h"
#include "pfaedle/_config.h"
#include "pfaedle/osm/BBoxIdx.h" #include "pfaedle/osm/BBoxIdx.h"
#include "pfaedle/osm/Osm.h" #include "pfaedle/osm/Osm.h"
#include "pfaedle/osm/OsmBuilder.h" #include "pfaedle/osm/OsmBuilder.h"
@ -185,8 +188,8 @@ void OsmBuilder::read(const std::string& path, const OsmReadOpts& opts,
// _____________________________________________________________________________ // _____________________________________________________________________________
void OsmBuilder::osmfilterRuleWrite(std::ostream* out, void OsmBuilder::osmfilterRuleWrite(std::ostream* out,
const std::vector<OsmReadOpts>& opts, const std::vector<OsmReadOpts>& opts,
const BBoxIdx& latLngBox) const { const BBoxIdx& latLngBox) const {
UNUSED(latLngBox); UNUSED(latLngBox);
OsmIdSet bboxNodes, noHupNodes; OsmIdSet bboxNodes, noHupNodes;
MultAttrMap emptyF; MultAttrMap emptyF;
@ -313,7 +316,7 @@ void OsmBuilder::overpassQryWrite(std::ostream* out,
// _____________________________________________________________________________ // _____________________________________________________________________________
void OsmBuilder::filterWrite(const std::string& in, const std::string& out, void OsmBuilder::filterWrite(const std::string& in, const std::string& out,
const std::vector<OsmReadOpts>& opts, const std::vector<OsmReadOpts>& opts,
const BBoxIdx& latLngBox) { const BBoxIdx& box) {
OsmIdSet bboxNodes, noHupNodes; OsmIdSet bboxNodes, noHupNodes;
MultAttrMap emptyF; MultAttrMap emptyF;
@ -333,10 +336,56 @@ void OsmBuilder::filterWrite(const std::string& in, const std::string& out,
std::ofstream outstr; std::ofstream outstr;
outstr.open(out); outstr.open(out);
BBoxIdx latLngBox = box;
if (latLngBox.size() == 0) {
skipUntil(&xml, "bounds");
const pfxml::tag& cur = xml.get();
if (strcmp(cur.name, "bounds") != 0) {
throw pfxml::parse_exc(
std::string("Could not find required <bounds> tag"), in, 0, 0, 0);
}
if (!cur.attr("minlat")) {
throw pfxml::parse_exc(
std::string(
"Could not find required attribute \"minlat\" for <bounds> tag"),
in, 0, 0, 0);
}
if (!cur.attr("minlon")) {
throw pfxml::parse_exc(
std::string(
"Could not find required attribute \"minlon\" for <bounds> tag"),
in, 0, 0, 0);
}
if (!cur.attr("maxlat")) {
throw pfxml::parse_exc(
std::string(
"Could not find required attribute \"maxlat\" for <bounds> tag"),
in, 0, 0, 0);
}
if (!cur.attr("maxlon")) {
throw pfxml::parse_exc(
std::string(
"Could not find required attribute \"maxlon\" for <bounds> tag"),
in, 0, 0, 0);
}
double minlat = atof(cur.attr("minlat"));
double minlon = atof(cur.attr("minlon"));
double maxlat = atof(cur.attr("maxlat"));
double maxlon = atof(cur.attr("maxlon"));
latLngBox.add(Box<double>({minlon, minlat}, {maxlon, maxlat}));
}
util::xml::XmlWriter wr(&outstr, true, 4); util::xml::XmlWriter wr(&outstr, true, 4);
outstr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; outstr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
wr.openTag("osm"); wr.openTag("osm", {{"version", "0.6"},
{"generator", std::string("pfaedle/") + VERSION_FULL}});
wr.openTag( wr.openTag(
"bounds", "bounds",
{{"minlat", std::to_string(latLngBox.getFullBox().getLowerLeft().getY())}, {{"minlat", std::to_string(latLngBox.getFullBox().getLowerLeft().getY())},