forked from hans/Nominatim
move scenes directory to new test directory
This commit is contained in:
27
test/scenes/bin/Makefile
Normal file
27
test/scenes/bin/Makefile
Normal file
@@ -0,0 +1,27 @@
|
||||
CXXFLAGS += -O3
|
||||
#CXXFLAGS += -g
|
||||
CXXFLAGS += -std=c++11 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
|
||||
CXXFLAGS += -I../../../../libosmium/include
|
||||
|
||||
OS:=$(shell uname -s)
|
||||
ifeq ($(OS),Darwin)
|
||||
CXXFLAGS += -stdlib=libc++
|
||||
LDFLAGS += -stdlib=libc++
|
||||
endif
|
||||
|
||||
CXXFLAGS_WARNINGS := -Wall -Wextra -pedantic -Wredundant-decls -Wdisabled-optimization -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual -Wsign-promo -Wold-style-cast
|
||||
|
||||
LIB_EXPAT := -lexpat
|
||||
LIB_PBF := -pthread -lz -lprotobuf-lite -losmpbf
|
||||
LIB_GZIP := -lz
|
||||
LIB_BZIP2 := -lbz2
|
||||
|
||||
LIB_IO := $(LIB_EXPAT) $(LIB_PBF) $(LIB_GZIP) $(LIB_BZIP2)
|
||||
|
||||
all:
|
||||
|
||||
osm2wkt: osm2wkt.cc
|
||||
$(CXX) $(CXXFLAGS) $(CXXFLAGS_WARNINGS) -o $@ $< $(LDFLAGS) $(LIB_IO)
|
||||
|
||||
scenarios: osm2wkt
|
||||
./make_scenes.sh
|
||||
29
test/scenes/bin/make_scenes.sh
Executable file
29
test/scenes/bin/make_scenes.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash -e
|
||||
#
|
||||
# Regenerates wkts for scenarios.
|
||||
#
|
||||
|
||||
datadir="$( cd "$( dirname "$0" )" && cd ../data && pwd )"
|
||||
|
||||
if [ ! -d "$datadir" ]; then
|
||||
echo "Cannot find data dir.";
|
||||
exit -1;
|
||||
fi
|
||||
|
||||
echo "Using datadir $datadir"
|
||||
cd $datadir
|
||||
|
||||
# remove old wkts
|
||||
rm -f $datadir/*.wkt
|
||||
|
||||
# create wkts from SQL scripts
|
||||
for fl in *.sql; do
|
||||
echo "Processing $fl.."
|
||||
cat $fl | psql -d nominatim -t -o ${fl/.sql/.wkt}
|
||||
done
|
||||
|
||||
# create wkts from .osm files
|
||||
for fl in *.osm; do
|
||||
echo "Processing $fl.."
|
||||
../bin/osm2wkt $fl
|
||||
done
|
||||
97
test/scenes/bin/osm2wkt.cc
Normal file
97
test/scenes/bin/osm2wkt.cc
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
// The code in this file is released into the Public Domain.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <osmium/area/assembler.hpp>
|
||||
#include <osmium/area/multipolygon_collector.hpp>
|
||||
#include <osmium/area/problem_reporter_exception.hpp>
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/io/any_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
|
||||
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
|
||||
typedef osmium::handler::NodeLocationsForWays<index_type, index_type> location_handler_type;
|
||||
|
||||
|
||||
class ExportToWKTHandler : public osmium::handler::Handler {
|
||||
|
||||
osmium::geom::WKTFactory<> m_factory;
|
||||
std::unordered_map<std::string, std::ofstream> m_files;
|
||||
|
||||
public:
|
||||
|
||||
void node(const osmium::Node& node) {
|
||||
print_geometry(node.tags(), m_factory.create_point(node));
|
||||
}
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
if (!way.is_closed() || !way.tags().get_value_by_key("area"))
|
||||
print_geometry(way.tags(), m_factory.create_linestring(way));
|
||||
}
|
||||
|
||||
void area(const osmium::Area& area) {
|
||||
if (!area.from_way() || area.tags().get_value_by_key("area"))
|
||||
print_geometry(area.tags(), m_factory.create_multipolygon(area));
|
||||
}
|
||||
|
||||
void close() {
|
||||
for (auto& fd : m_files)
|
||||
fd.second.close();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void print_geometry(const osmium::TagList& tags, const std::string& wkt) {
|
||||
const char* scenario = tags.get_value_by_key("test:section");
|
||||
const char* id = tags.get_value_by_key("test:id");
|
||||
if (scenario && id) {
|
||||
auto& fd = m_files[std::string(scenario)];
|
||||
if (!fd.is_open())
|
||||
fd.open(std::string(scenario) + ".wkt");
|
||||
fd << id << " | " << wkt << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}; // class ExportToWKTHandler
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string input_filename {argv[1]};
|
||||
|
||||
osmium::area::ProblemReporterException problem_reporter;
|
||||
osmium::area::Assembler::config_type assembler_config(&problem_reporter);
|
||||
osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);
|
||||
|
||||
std::cerr << "Pass 1...\n";
|
||||
osmium::io::Reader reader1(input_filename, osmium::osm_entity_bits::relation);
|
||||
collector.read_relations(reader1);
|
||||
std::cerr << "Pass 1 done\n";
|
||||
|
||||
index_type index_pos;
|
||||
index_type index_neg;
|
||||
location_handler_type location_handler(index_pos, index_neg);
|
||||
|
||||
std::cerr << "Pass 2...\n";
|
||||
ExportToWKTHandler export_handler;
|
||||
osmium::io::Reader reader2(input_filename);
|
||||
osmium::apply(reader2, location_handler, export_handler, collector.handler([&export_handler](osmium::memory::Buffer&& buffer) {
|
||||
osmium::apply(buffer, export_handler);
|
||||
}));
|
||||
reader2.close();
|
||||
export_handler.close();
|
||||
std::cerr << "Pass 2 done\n";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user