Remove libosmium
This commit is contained in:
-92
@@ -1,92 +0,0 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# CMake Config
|
||||
#
|
||||
# Libosmium examples
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
message(STATUS "Configuring examples")
|
||||
|
||||
set(EXAMPLES
|
||||
area_test
|
||||
convert
|
||||
count
|
||||
create_node_cache
|
||||
debug
|
||||
filter_discussions
|
||||
index
|
||||
read
|
||||
serdump
|
||||
use_node_cache
|
||||
CACHE STRING "Example programs"
|
||||
)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Examples depending on wingetopt
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
set(GETOPT_EXAMPLES area_test convert serdump)
|
||||
if(NOT GETOPT_MISSING)
|
||||
foreach(example ${GETOPT_EXAMPLES})
|
||||
list(APPEND EXAMPLE_LIBS_${example} ${GETOPT_LIBRARY})
|
||||
endforeach()
|
||||
else()
|
||||
message(STATUS "Configuring examples - Skipping examples because on Visual Studio the wingetopt library is needed and was not found:")
|
||||
foreach(example ${GETOPT_EXAMPLES})
|
||||
message(STATUS " - osmium_${example}")
|
||||
list(REMOVE_ITEM EXAMPLES ${example})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Examples depending on SparseHash
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
if(NOT SPARSEHASH_FOUND)
|
||||
list(REMOVE_ITEM EXAMPLES area_test)
|
||||
message(STATUS "Configuring examples - Skipping examples because Google SparseHash not found:")
|
||||
message(STATUS " - osmium_area_test")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Examples depending on Boost Program Options
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
unset(Boost_LIBRARIES)
|
||||
unset(Boost_FOUND)
|
||||
find_package(Boost 1.38 COMPONENTS program_options)
|
||||
|
||||
if(Boost_PROGRAM_OPTIONS_FOUND)
|
||||
list(APPEND EXAMPLE_LIBS_index ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
else()
|
||||
list(REMOVE_ITEM EXAMPLES index)
|
||||
message(STATUS "Configuring examples - Skipping examples because Boost program_options not found:")
|
||||
message(STATUS " - osmium_index")
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Configure examples
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
message(STATUS "Configuring examples - Building these examples:")
|
||||
foreach(example ${EXAMPLES})
|
||||
message(STATUS " - osmium_${example}")
|
||||
add_executable(osmium_${example} "osmium_${example}.cpp")
|
||||
target_link_libraries(osmium_${example} ${OSMIUM_IO_LIBRARIES} ${EXAMPLE_LIBS_${example}})
|
||||
endforeach()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
message(STATUS "Configuring examples - done")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
-136
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
|
||||
This is an example tool that creates multipolygons from OSM data
|
||||
and dumps them to stdout.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include <osmium/area/assembler.hpp>
|
||||
#include <osmium/area/multipolygon_collector.hpp>
|
||||
#include <osmium/dynamic_handler.hpp>
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
#include <osmium/handler/dump.hpp>
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/index/map/dummy.hpp>
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
#include <osmium/io/any_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_neg_type;
|
||||
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
|
||||
typedef osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type> location_handler_type;
|
||||
|
||||
class WKTDump : public osmium::handler::Handler {
|
||||
|
||||
osmium::geom::WKTFactory<> m_factory ;
|
||||
|
||||
std::ostream& m_out;
|
||||
|
||||
public:
|
||||
|
||||
WKTDump(std::ostream& out) :
|
||||
m_out(out) {
|
||||
}
|
||||
|
||||
void area(const osmium::Area& area) {
|
||||
try {
|
||||
m_out << m_factory.create_multipolygon(area) << "\n";
|
||||
} catch (osmium::geometry_error& e) {
|
||||
m_out << "GEOMETRY ERROR: " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}; // class WKTDump
|
||||
|
||||
void print_help() {
|
||||
std::cout << "osmium_area_test [OPTIONS] OSMFILE\n\n"
|
||||
<< "Read OSMFILE and build multipolygons from it.\n"
|
||||
<< "\nOptions:\n"
|
||||
<< " -h, --help This help message\n"
|
||||
<< " -w, --dump-wkt Dump area geometries as WKT\n"
|
||||
<< " -o, --dump-objects Dump area objects\n";
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"dump-wkt", no_argument, 0, 'w'},
|
||||
{"dump-objects", no_argument, 0, 'o'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
osmium::handler::DynamicHandler handler;
|
||||
|
||||
while (true) {
|
||||
int c = getopt_long(argc, argv, "hwo", long_options, 0);
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
print_help();
|
||||
exit(0);
|
||||
case 'w':
|
||||
handler.set<WKTDump>(std::cout);
|
||||
break;
|
||||
case 'o':
|
||||
handler.set<osmium::handler::Dump>(std::cout);
|
||||
break;
|
||||
default:
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int remaining_args = argc - optind;
|
||||
if (remaining_args != 1) {
|
||||
std::cerr << "Usage: " << argv[0] << " [OPTIONS] OSMFILE\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
osmium::io::File infile(argv[optind]);
|
||||
|
||||
osmium::area::Assembler::config_type assembler_config;
|
||||
osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);
|
||||
|
||||
std::cout << "Pass 1...\n";
|
||||
osmium::io::Reader reader1(infile, osmium::osm_entity_bits::relation);
|
||||
collector.read_relations(reader1);
|
||||
reader1.close();
|
||||
std::cout << "Pass 1 done\n";
|
||||
|
||||
std::cout << "Memory:\n";
|
||||
collector.used_memory();
|
||||
|
||||
index_pos_type index_pos;
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler(index_pos, index_neg);
|
||||
location_handler.ignore_errors(); // XXX
|
||||
|
||||
std::cout << "Pass 2...\n";
|
||||
osmium::io::Reader reader2(infile);
|
||||
osmium::apply(reader2, location_handler, collector.handler([&handler](osmium::memory::Buffer&& buffer) {
|
||||
osmium::apply(buffer, handler);
|
||||
}));
|
||||
reader2.close();
|
||||
std::cout << "Pass 2 done\n";
|
||||
|
||||
std::cout << "Memory:\n";
|
||||
collector.used_memory();
|
||||
|
||||
std::vector<const osmium::Relation*> incomplete_relations = collector.get_incomplete_relations();
|
||||
if (!incomplete_relations.empty()) {
|
||||
std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
|
||||
for (const auto* relation : incomplete_relations) {
|
||||
std::cerr << " " << relation->id();
|
||||
}
|
||||
std::cerr << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
|
||||
Convert OSM files from one format into another.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
|
||||
#include <osmium/io/any_input.hpp>
|
||||
|
||||
#include <osmium/io/any_output.hpp>
|
||||
|
||||
void print_help() {
|
||||
std::cout << "osmium_convert [OPTIONS] [INFILE [OUTFILE]]\n\n" \
|
||||
<< "If INFILE or OUTFILE is not given stdin/stdout is assumed.\n" \
|
||||
<< "File format is autodetected from file name suffix.\n" \
|
||||
<< "Use -f and -t options to force file format.\n" \
|
||||
<< "\nFile types:\n" \
|
||||
<< " osm normal OSM file\n" \
|
||||
<< " osc OSM change file\n" \
|
||||
<< " osh OSM file with history information\n" \
|
||||
<< "\nFile format:\n" \
|
||||
<< " (default) XML encoding\n" \
|
||||
<< " pbf binary PBF encoding\n" \
|
||||
<< " opl OPL encoding\n" \
|
||||
<< "\nFile compression\n" \
|
||||
<< " gz compressed with gzip\n" \
|
||||
<< " bz2 compressed with bzip2\n" \
|
||||
<< "\nOptions:\n" \
|
||||
<< " -h, --help This help message\n" \
|
||||
<< " -f, --from-format=FORMAT Input format\n" \
|
||||
<< " -t, --to-format=FORMAT Output format\n";
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"from-format", required_argument, 0, 'f'},
|
||||
{"to-format", required_argument, 0, 't'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
std::string input_format;
|
||||
std::string output_format;
|
||||
|
||||
while (true) {
|
||||
int c = getopt_long(argc, argv, "dhf:t:", long_options, 0);
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
print_help();
|
||||
exit(0);
|
||||
case 'f':
|
||||
input_format = optarg;
|
||||
break;
|
||||
case 't':
|
||||
output_format = optarg;
|
||||
break;
|
||||
default:
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
std::string input;
|
||||
std::string output;
|
||||
int remaining_args = argc - optind;
|
||||
if (remaining_args > 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " [OPTIONS] [INFILE [OUTFILE]]" << std::endl;
|
||||
exit(1);
|
||||
} else if (remaining_args == 2) {
|
||||
input = argv[optind];
|
||||
output = argv[optind+1];
|
||||
} else if (remaining_args == 1) {
|
||||
input = argv[optind];
|
||||
}
|
||||
|
||||
osmium::io::File infile(input, input_format);
|
||||
|
||||
osmium::io::File outfile(output, output_format);
|
||||
|
||||
if (infile.has_multiple_object_versions() && !outfile.has_multiple_object_versions()) {
|
||||
std::cerr << "Warning! You are converting from an OSM file with (potentially) several versions of the same object to one that is not marked as such.\n";
|
||||
}
|
||||
|
||||
int exit_code = 0;
|
||||
|
||||
try {
|
||||
osmium::io::Reader reader(infile);
|
||||
osmium::io::Header header = reader.header();
|
||||
header.set("generator", "osmium_convert");
|
||||
|
||||
osmium::io::Writer writer(outfile, header, osmium::io::overwrite::allow);
|
||||
while (osmium::memory::Buffer buffer = reader.read()) {
|
||||
writer(std::move(buffer));
|
||||
}
|
||||
writer.close();
|
||||
reader.close();
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << "\n";
|
||||
exit_code = 1;
|
||||
}
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
|
||||
This is a small tool that counts the number of nodes, ways, and relations in
|
||||
the input file.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include <osmium/io/any_input.hpp>
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
struct CountHandler : public osmium::handler::Handler {
|
||||
|
||||
uint64_t nodes = 0;
|
||||
uint64_t ways = 0;
|
||||
uint64_t relations = 0;
|
||||
|
||||
void node(osmium::Node&) {
|
||||
++nodes;
|
||||
}
|
||||
|
||||
void way(osmium::Way&) {
|
||||
++ways;
|
||||
}
|
||||
|
||||
void relation(osmium::Relation&) {
|
||||
++relations;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
osmium::io::File infile(argv[1]);
|
||||
osmium::io::Reader reader(infile);
|
||||
|
||||
CountHandler handler;
|
||||
osmium::apply(reader, handler);
|
||||
reader.close();
|
||||
|
||||
std::cout << "Nodes: " << handler.nodes << "\n";
|
||||
std::cout << "Ways: " << handler.ways << "\n";
|
||||
std::cout << "Relations: " << handler.relations << "\n";
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
|
||||
This reads an OSM file and writes out the node locations to a cache
|
||||
file.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <osmium/io/any_input.hpp>
|
||||
|
||||
#include <osmium/index/map/dummy.hpp>
|
||||
#include <osmium/index/map/dense_mmap_array.hpp>
|
||||
#include <osmium/index/map/dense_file_array.hpp>
|
||||
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_neg_type;
|
||||
//typedef osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
|
||||
typedef osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
|
||||
|
||||
typedef osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type> location_handler_type;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "Usage: " << argv[0] << " OSM_FILE CACHE_FILE\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string input_filename(argv[1]);
|
||||
osmium::io::Reader reader(input_filename, osmium::osm_entity_bits::node);
|
||||
|
||||
int fd = open(argv[2], O_RDWR | O_CREAT, 0666);
|
||||
if (fd == -1) {
|
||||
std::cerr << "Can not open node cache file '" << argv[2] << "': " << strerror(errno) << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
index_pos_type index_pos {fd};
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler(index_pos, index_neg);
|
||||
location_handler.ignore_errors();
|
||||
|
||||
osmium::apply(reader, location_handler);
|
||||
reader.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
|
||||
This is a small tool to dump the contents of the input file.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <osmium/handler/dump.hpp>
|
||||
#include <osmium/io/any_input.hpp>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
|
||||
if (argc < 2 || argc > 3) {
|
||||
std::cerr << "Usage: " << argv[0] << " OSMFILE [TYPES]\n";
|
||||
std::cerr << "TYPES can be any combination of 'n', 'w', 'r', and 'c' to indicate what types of OSM entities you want (default: all).\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
osmium::osm_entity_bits::type read_types = osmium::osm_entity_bits::all;
|
||||
|
||||
if (argc == 3) {
|
||||
read_types = osmium::osm_entity_bits::nothing;
|
||||
std::string types = argv[2];
|
||||
if (types.find('n') != std::string::npos) read_types |= osmium::osm_entity_bits::node;
|
||||
if (types.find('w') != std::string::npos) read_types |= osmium::osm_entity_bits::way;
|
||||
if (types.find('r') != std::string::npos) read_types |= osmium::osm_entity_bits::relation;
|
||||
if (types.find('c') != std::string::npos) read_types |= osmium::osm_entity_bits::changeset;
|
||||
}
|
||||
|
||||
osmium::io::Reader reader(argv[1], read_types);
|
||||
osmium::io::Header header = reader.header();
|
||||
|
||||
std::cout << "HEADER:\n generator=" << header.get("generator") << "\n";
|
||||
|
||||
for (auto& bbox : header.boxes()) {
|
||||
std::cout << " bbox=" << bbox << "\n";
|
||||
}
|
||||
|
||||
osmium::handler::Dump dump(std::cout);
|
||||
while (osmium::memory::Buffer buffer = reader.read()) {
|
||||
osmium::apply(buffer, dump);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
|
||||
Read OSM changesets with discussions from a changeset dump like the one
|
||||
you get from http://planet.osm.org/planet/discussions-latest.osm.bz2
|
||||
and write out only those changesets which have discussions (ie comments).
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <algorithm> // for std::copy_if
|
||||
#include <iostream> // for std::cout, std::cerr
|
||||
|
||||
// we want to read OSM files in XML format
|
||||
// (other formats don't support full changesets, so only XML is needed here)
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/io/input_iterator.hpp>
|
||||
|
||||
// we want to write OSM files in XML format
|
||||
#include <osmium/io/xml_output.hpp>
|
||||
#include <osmium/io/output_iterator.hpp>
|
||||
|
||||
// we want to support any compressioon (.gz2 and .bz2)
|
||||
#include <osmium/io/any_compression.hpp>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 3) {
|
||||
std::cout << "Usage: " << argv[0] << " INFILE OUTFILE\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// The input file, deduce file format from file suffix
|
||||
osmium::io::File infile(argv[1]);
|
||||
|
||||
// The output file, force class XML OSM file format
|
||||
osmium::io::File outfile(argv[2], "osm");
|
||||
|
||||
// Initialize Reader for the input file.
|
||||
// Read only changesets (will ignore nodes, ways, and
|
||||
// relations if there are any).
|
||||
osmium::io::Reader reader(infile, osmium::osm_entity_bits::changeset);
|
||||
|
||||
// Get the header from the input file
|
||||
osmium::io::Header header = reader.header();
|
||||
|
||||
// Initialize writer for the output file. Use the header from the input
|
||||
// file for the output file. This will copy over some header information.
|
||||
// The last parameter will tell the writer that it is allowed to overwrite
|
||||
// an existing file. Without it, it will refuse to do so.
|
||||
osmium::io::Writer writer(outfile, header, osmium::io::overwrite::allow);
|
||||
|
||||
// Create range of input iterators that will iterator over all changesets
|
||||
// delivered from input file through the "reader".
|
||||
auto input_range = osmium::io::make_input_iterator_range<osmium::Changeset>(reader);
|
||||
|
||||
// Create an output iterator writing through the "writer" object to the
|
||||
// output file.
|
||||
auto output_iterator = osmium::io::make_output_iterator(writer);
|
||||
|
||||
// Copy all changesets from input to output that have at least one comment.
|
||||
std::copy_if(input_range.begin(), input_range.end(), output_iterator, [](const osmium::Changeset& changeset) {
|
||||
return changeset.num_comments() > 0;
|
||||
});
|
||||
|
||||
// Explicitly close the writer and reader. Will throw an exception if
|
||||
// there is a problem. If you wait for the destructor to close the writer
|
||||
// and reader, you will not notice the problem, because destructors must
|
||||
// not throw.
|
||||
writer.close();
|
||||
reader.close();
|
||||
}
|
||||
|
||||
-237
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
|
||||
Example program to look at Osmium indexes on disk.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <osmium/index/map/dense_file_array.hpp>
|
||||
#include <osmium/index/map/sparse_file_array.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
template <typename TKey, typename TValue>
|
||||
class IndexSearch {
|
||||
|
||||
typedef typename osmium::index::map::DenseFileArray<TKey, TValue> dense_index_type;
|
||||
typedef typename osmium::index::map::SparseFileArray<TKey, TValue> sparse_index_type;
|
||||
|
||||
int m_fd;
|
||||
bool m_dense_format;
|
||||
|
||||
void dump_dense() {
|
||||
dense_index_type index(m_fd);
|
||||
|
||||
for (size_t i = 0; i < index.size(); ++i) {
|
||||
if (index.get(i) != TValue()) {
|
||||
std::cout << i << " " << index.get(i) << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dump_sparse() {
|
||||
sparse_index_type index(m_fd);
|
||||
|
||||
for (auto& element : index) {
|
||||
std::cout << element.first << " " << element.second << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
bool search_dense(TKey key) {
|
||||
dense_index_type index(m_fd);
|
||||
|
||||
try {
|
||||
TValue value = index.get(key);
|
||||
std::cout << key << " " << value << std::endl;
|
||||
} catch (...) {
|
||||
std::cout << key << " not found" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool search_sparse(TKey key) {
|
||||
typedef typename sparse_index_type::element_type element_type;
|
||||
sparse_index_type index(m_fd);
|
||||
|
||||
element_type elem {key, TValue()};
|
||||
auto positions = std::equal_range(index.begin(), index.end(), elem, [](const element_type& lhs, const element_type& rhs) {
|
||||
return lhs.first < rhs.first;
|
||||
});
|
||||
if (positions.first == positions.second) {
|
||||
std::cout << key << " not found" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& it = positions.first; it != positions.second; ++it) {
|
||||
std::cout << it->first << " " << it->second << "\n";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
IndexSearch(int fd, bool dense_format) :
|
||||
m_fd(fd),
|
||||
m_dense_format(dense_format) {
|
||||
}
|
||||
|
||||
void dump() {
|
||||
if (m_dense_format) {
|
||||
dump_dense();
|
||||
} else {
|
||||
dump_sparse();
|
||||
}
|
||||
}
|
||||
|
||||
bool search(TKey key) {
|
||||
if (m_dense_format) {
|
||||
return search_dense(key);
|
||||
} else {
|
||||
return search_sparse(key);
|
||||
}
|
||||
}
|
||||
|
||||
bool search(std::vector<TKey> keys) {
|
||||
bool found_all = true;
|
||||
|
||||
for (const auto key : keys) {
|
||||
if (!search(key)) {
|
||||
found_all = false;
|
||||
}
|
||||
}
|
||||
|
||||
return found_all;
|
||||
}
|
||||
|
||||
}; // class IndexSearch
|
||||
|
||||
enum return_code : int {
|
||||
okay = 0,
|
||||
not_found = 1,
|
||||
error = 2,
|
||||
fatal = 3
|
||||
};
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
class Options {
|
||||
|
||||
po::variables_map vm;
|
||||
|
||||
public:
|
||||
|
||||
Options(int argc, char* argv[]) {
|
||||
try {
|
||||
po::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help,h", "Print this help message")
|
||||
("array,a", po::value<std::string>(), "Read given index file in array format")
|
||||
("list,l", po::value<std::string>(), "Read given index file in list format")
|
||||
("dump,d", "Dump contents of index file to STDOUT")
|
||||
("search,s", po::value<std::vector<osmium::unsigned_object_id_type>>(), "Search for given id (Option can appear multiple times)")
|
||||
("type,t", po::value<std::string>(), "Type of value ('location' or 'offset')")
|
||||
;
|
||||
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << "\n";
|
||||
exit(return_code::okay);
|
||||
}
|
||||
|
||||
if (vm.count("array") && vm.count("list")) {
|
||||
std::cerr << "Only option --array or --list allowed." << std::endl;
|
||||
exit(return_code::fatal);
|
||||
}
|
||||
|
||||
if (!vm.count("array") && !vm.count("list")) {
|
||||
std::cerr << "Need one of option --array or --list." << std::endl;
|
||||
exit(return_code::fatal);
|
||||
}
|
||||
|
||||
if (!vm.count("type")) {
|
||||
std::cerr << "Need --type argument." << std::endl;
|
||||
exit(return_code::fatal);
|
||||
}
|
||||
|
||||
const std::string& type = vm["type"].as<std::string>();
|
||||
if (type != "location" && type != "offset") {
|
||||
std::cerr << "Unknown type '" << type << "'. Must be 'location' or 'offset'." << std::endl;
|
||||
exit(return_code::fatal);
|
||||
}
|
||||
} catch (boost::program_options::error& e) {
|
||||
std::cerr << "Error parsing command line: " << e.what() << std::endl;
|
||||
exit(return_code::fatal);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& filename() const {
|
||||
if (vm.count("array")) {
|
||||
return vm["array"].as<std::string>();
|
||||
} else {
|
||||
return vm["list"].as<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
bool dense_format() const {
|
||||
return vm.count("array") != 0;
|
||||
}
|
||||
|
||||
bool do_dump() const {
|
||||
return vm.count("dump") != 0;
|
||||
}
|
||||
|
||||
std::vector<osmium::unsigned_object_id_type> search_keys() const {
|
||||
return vm["search"].as<std::vector<osmium::unsigned_object_id_type>>();
|
||||
}
|
||||
|
||||
bool type_is(const char* type) const {
|
||||
return vm["type"].as<std::string>() == type;
|
||||
}
|
||||
|
||||
}; // class Options
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
|
||||
Options options(argc, argv);
|
||||
|
||||
std::cout << std::fixed << std::setprecision(7);
|
||||
int fd = open(options.filename().c_str(), O_RDWR);
|
||||
|
||||
bool result_okay = true;
|
||||
|
||||
if (options.type_is("location")) {
|
||||
IndexSearch<osmium::unsigned_object_id_type, osmium::Location> is(fd, options.dense_format());
|
||||
|
||||
if (options.do_dump()) {
|
||||
is.dump();
|
||||
} else {
|
||||
result_okay = is.search(options.search_keys());
|
||||
}
|
||||
} else {
|
||||
IndexSearch<osmium::unsigned_object_id_type, size_t> is(fd, options.dense_format());
|
||||
|
||||
if (options.do_dump()) {
|
||||
is.dump();
|
||||
} else {
|
||||
result_okay = is.search(options.search_keys());
|
||||
}
|
||||
}
|
||||
|
||||
exit(result_okay ? return_code::okay : return_code::not_found);
|
||||
}
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
|
||||
This is a small tool that reads and discards the contents of the input file.
|
||||
(Used for timing.)
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <osmium/io/any_input.hpp>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " OSMFILE\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
osmium::io::File infile(argv[1]);
|
||||
osmium::io::Reader reader(infile);
|
||||
|
||||
while (osmium::memory::Buffer buffer = reader.read()) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
reader.close();
|
||||
}
|
||||
|
||||
-206
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
|
||||
This is a small tool to dump the contents of the input file
|
||||
in serialized format to stdout.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <getopt.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# include <direct.h>
|
||||
#endif
|
||||
|
||||
#include <osmium/io/any_input.hpp>
|
||||
#include <osmium/handler/disk_store.hpp>
|
||||
#include <osmium/handler/object_relations.hpp>
|
||||
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
#include <osmium/index/multimap/sparse_mem_multimap.hpp>
|
||||
#include <osmium/index/multimap/sparse_mem_array.hpp>
|
||||
#include <osmium/index/multimap/hybrid.hpp>
|
||||
|
||||
// ==============================================================================
|
||||
// Choose the following depending on the size of the input OSM files:
|
||||
// ==============================================================================
|
||||
// for smaller OSM files (extracts)
|
||||
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, size_t> offset_index_type;
|
||||
//typedef osmium::index::map::SparseMapMmap<osmium::unsigned_object_id_type, size_t> offset_index_type;
|
||||
//typedef osmium::index::map::SparseMapFile<osmium::unsigned_object_id_type, size_t> offset_index_type;
|
||||
|
||||
typedef osmium::index::multimap::SparseMemArray<osmium::unsigned_object_id_type, osmium::unsigned_object_id_type> map_type;
|
||||
//typedef osmium::index::multimap::SparseMemMultimap<osmium::unsigned_object_id_type, osmium::unsigned_object_id_type> map_type;
|
||||
//typedef osmium::index::multimap::Hybrid<osmium::unsigned_object_id_type, osmium::unsigned_object_id_type> map_type;
|
||||
|
||||
// ==============================================================================
|
||||
// for very large OSM files (planet)
|
||||
//typedef osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, size_t> offset_index_type;
|
||||
// ==============================================================================
|
||||
|
||||
void print_help() {
|
||||
std::cout << "osmium_serdump OSMFILE DIR\n" \
|
||||
<< "Serialize content of OSMFILE into data file in DIR.\n" \
|
||||
<< "\nOptions:\n" \
|
||||
<< " -h, --help This help message\n";
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
while (true) {
|
||||
int c = getopt_long(argc, argv, "h", long_options, 0);
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
print_help();
|
||||
exit(0);
|
||||
default:
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
int remaining_args = argc - optind;
|
||||
|
||||
if (remaining_args != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " OSMFILE DIR\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
std::string dir(argv[optind+1]);
|
||||
#ifndef _WIN32
|
||||
int result = ::mkdir(dir.c_str(), 0777);
|
||||
#else
|
||||
int result = mkdir(dir.c_str());
|
||||
#endif
|
||||
if (result == -1 && errno != EEXIST) {
|
||||
std::cerr << "Problem creating directory '" << dir << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
std::string data_file(dir + "/data.osm.ser");
|
||||
int data_fd = ::open(data_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (data_fd < 0) {
|
||||
std::cerr << "Can't open data file '" << data_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
|
||||
offset_index_type node_index;
|
||||
offset_index_type way_index;
|
||||
offset_index_type relation_index;
|
||||
|
||||
osmium::handler::DiskStore disk_store_handler(data_fd, node_index, way_index, relation_index);
|
||||
|
||||
map_type map_node2way;
|
||||
map_type map_node2relation;
|
||||
map_type map_way2relation;
|
||||
map_type map_relation2relation;
|
||||
|
||||
osmium::handler::ObjectRelations object_relations_handler(map_node2way, map_node2relation, map_way2relation, map_relation2relation);
|
||||
|
||||
osmium::io::Reader reader(argv[1]);
|
||||
|
||||
while (osmium::memory::Buffer buffer = reader.read()) {
|
||||
disk_store_handler(buffer); // XXX
|
||||
osmium::apply(buffer, object_relations_handler);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
{
|
||||
std::string index_file(dir + "/nodes.idx");
|
||||
int fd = ::open(index_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
std::cerr << "Can't open nodes index file '" << index_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
node_index.dump_as_list(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
{
|
||||
std::string index_file(dir + "/ways.idx");
|
||||
int fd = ::open(index_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
std::cerr << "Can't open ways index file '" << index_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
way_index.dump_as_list(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
{
|
||||
std::string index_file(dir + "/relations.idx");
|
||||
int fd = ::open(index_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
std::cerr << "Can't open relations index file '" << index_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
relation_index.dump_as_list(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
{
|
||||
map_node2way.sort();
|
||||
std::string index_file(dir + "/node2way.map");
|
||||
int fd = ::open(index_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
std::cerr << "Can't open node->way map file '" << index_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
map_node2way.dump_as_list(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
{
|
||||
map_node2relation.sort();
|
||||
std::string index_file(dir + "/node2rel.map");
|
||||
int fd = ::open(index_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
std::cerr << "Can't open node->rel map file '" << index_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
map_node2relation.dump_as_list(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
{
|
||||
map_way2relation.sort();
|
||||
std::string index_file(dir + "/way2rel.map");
|
||||
int fd = ::open(index_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
std::cerr << "Can't open way->rel map file '" << index_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
map_way2relation.dump_as_list(fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
{
|
||||
map_relation2relation.sort();
|
||||
std::string index_file(dir + "/rel2rel.map");
|
||||
int fd = ::open(index_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
std::cerr << "Can't open rel->rel map file '" << index_file << "': " << strerror(errno) << "\n";
|
||||
exit(2);
|
||||
}
|
||||
map_relation2relation.dump_as_list(fd);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
|
||||
This reads ways from an OSM file and writes out the node locations
|
||||
it got from a node cache generated with osmium_create_node_cache.
|
||||
|
||||
The code in this example file is released into the Public Domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <osmium/io/any_input.hpp>
|
||||
|
||||
#include <osmium/index/map/dummy.hpp>
|
||||
#include <osmium/index/map/dense_file_array.hpp>
|
||||
#include <osmium/index/map/dense_mmap_array.hpp>
|
||||
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_neg_type;
|
||||
//typedef osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
|
||||
typedef osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
|
||||
|
||||
typedef osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type> location_handler_type;
|
||||
|
||||
class MyHandler : public osmium::handler::Handler {
|
||||
|
||||
public:
|
||||
|
||||
void way(osmium::Way& way) {
|
||||
for (auto& nr : way.nodes()) {
|
||||
std::cout << nr << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}; // class MyHandler
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 3) {
|
||||
std::cerr << "Usage: " << argv[0] << " OSM_FILE CACHE_FILE\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string input_filename(argv[1]);
|
||||
osmium::io::Reader reader(input_filename, osmium::osm_entity_bits::way);
|
||||
|
||||
int fd = open(argv[2], O_RDWR);
|
||||
if (fd == -1) {
|
||||
std::cerr << "Can not open node cache file '" << argv[2] << "': " << strerror(errno) << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
index_pos_type index_pos {fd};
|
||||
index_neg_type index_neg;
|
||||
location_handler_type location_handler(index_pos, index_neg);
|
||||
location_handler.ignore_errors();
|
||||
|
||||
MyHandler handler;
|
||||
osmium::apply(reader, location_handler, handler);
|
||||
reader.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user