Skip to content

Commit

Permalink
Changed the way OSM input/output is done.
Browse files Browse the repository at this point in the history
Before including <osmium.hpp> you now need to define one or more of the
following macros:
    #define OSMIUM_WITH_PBF_INPUT
    #define OSMIUM_WITH_XML_INPUT
    #define OSMIUM_WITH_PBF_OUTPUT
    #define OSMIUM_WITH_XML_OUTPUT
which enable PBF and XML input and output, respectively. If you don't want
any file input/output you don't need to include <osmium.hpp> at all.

Instead of writing
    infile.read(handler)
you now write
    Osmium::Input::read(infile, handler)

Instead of writing
    outfile.create_output_file()
you now write
    Osmium::Output::open(outfile)

The OSMIUM_WITH_OUTPUT_OSM_XML macros is gone.

Sorry for the changes needed in user code, but this makes the library easier
and more straightforward to use. You can now decide whether you need XML/PBF
support for reading/writing. What you don't need is not included, so it
compiles faster and you don't have to link with libraries you don't need.
  • Loading branch information
joto committed Jul 15, 2012
1 parent c4966b7 commit cfe4cb8
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 138 deletions.
3 changes: 2 additions & 1 deletion Doxyfile
Expand Up @@ -1244,7 +1244,8 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.

PREDEFINED = OSMIUM_WITH_GEOS OSMIUM_WITH_SHPLIB OSMIUM_WITH_OUTPUT_OSM_XML
PREDEFINED = OSMIUM_WITH_GEOS OSMIUM_WITH_SHPLIB OSMIUM_WITH_PBF_INPUT OSMIUM_WITH_PBF_OUTPUT OSMIUM_WITH_XML_INPUT OSMIUM_WITH_XML_OUTPUT


# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.
Expand Down
34 changes: 17 additions & 17 deletions examples/Makefile
Expand Up @@ -17,20 +17,20 @@ CXXFLAGS += -Wall -Wextra -Wredundant-decls -Wdisabled-optimization -pedantic -W
#CXXFLAGS += -DOSMIUM_WITH_MULTIPOLYGON_PROFILING

CXXFLAGS_GEOS = -DOSMIUM_WITH_GEOS $(shell geos-config --cflags)
CXXFLAGS_LIBXML2 = -DOSMIUM_WITH_OUTPUT_OSM_XML $(shell xml2-config --cflags)
CXXFLAGS_LIBXML2 = $(shell xml2-config --cflags)
CXXFLAGS_OGR = $(shell gdal-config --cflags)

CXXFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

CXXFLAGS += -I../include

LDFLAGS = -L/usr/local/lib -lexpat -lpthread
LDFLAGS = -L/usr/local/lib -lexpat

LIB_GD = -lgd -lz -lm
LIB_SQLITE = -lsqlite3
LIB_GEOS = $(shell geos-config --libs)
LIB_SHAPE = -lshp $(LIB_GEOS)
LIB_PROTOBUF = -lz -lprotobuf-lite -losmpbf
LIB_PBF = -lz -lpthread -lprotobuf-lite -losmpbf
LIB_XML2 = $(shell xml2-config --libs)
LIB_OGR = $(shell gdal-config --libs)

Expand All @@ -54,44 +54,44 @@ PROGRAMS = \
all: $(PROGRAMS)

osmium_convert: osmium_convert.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_XML2)
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_XML2)

osmium_store_and_debug: osmium_store_and_debug.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF)

osmium_debug: osmium_debug.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF)
# $(CXX) $(CXXFLAGS) -DOSMIUM_DEBUG_WITH_ENDTIME -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF)
# $(CXX) $(CXXFLAGS) -DOSMIUM_DEBUG_WITH_ENDTIME -o $@ $< $(LDFLAGS) $(LIB_PBF)

osmium_find_bbox: osmium_find_bbox.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF)

osmium_progress: osmium_progress.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF)

osmium_range_from_history: osmium_range_from_history.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF)
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_XML2)

osmium_sizeof: osmium_sizeof.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_XML2)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS)

osmium_stats: osmium_stats.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_SQLITE)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_SQLITE)

osmium_time: osmium_time.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF)

osmium_toogr: osmium_toogr.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_OGR)
$(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_OGR)

osmium_toogr2: osmium_toogr2.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_OGR) $(LIB_GEOS)
$(CXX) $(CXXFLAGS) $(CXXFLAGS_OGR) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_OGR) $(LIB_GEOS)

osmium_toshape: osmium_toshape.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_SHAPE)
$(CXX) $(CXXFLAGS) $(CXXFLAGS_GEOS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_SHAPE)

nodedensity: nodedensity.cpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_GD)
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PBF) $(LIB_GD)

clean:
rm -f *.o core $(PROGRAMS)
Expand Down
5 changes: 4 additions & 1 deletion examples/nodedensity.cpp
Expand Up @@ -24,6 +24,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see
#include <cstdio>
#include <gd.h>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>

/* ================================================== */
Expand Down Expand Up @@ -119,6 +122,6 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
NodeDensityHandler handler(size, min, max);
infile.read(handler);
Osmium::Input::read(infile, handler);
}

8 changes: 6 additions & 2 deletions examples/osmium_convert.cpp
Expand Up @@ -28,6 +28,10 @@ You should have received a copy of the Licenses along with Osmium. If not, see
#include <cstdlib>
#include <getopt.h>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT
#define OSMIUM_WITH_PBF_OUTPUT
#define OSMIUM_WITH_XML_OUTPUT
#include <osmium.hpp>
#include <osmium/handler/progress.hpp>

Expand All @@ -50,7 +54,7 @@ class ConvertHandler : public Osmium::Handler::Base {
}

void init(Osmium::OSM::Meta& meta) {
output = m_outfile.create_output_file();
output = Osmium::Output::open(m_outfile);
output->debug_level(m_debug_level);
output->init(meta);
m_progress_handler.init(meta);
Expand Down Expand Up @@ -181,6 +185,6 @@ int main(int argc, char *argv[]) {
}

ConvertHandler handler(outfile, debug ? 1 : 0);
infile.read(handler);
Osmium::Input::read(infile, handler);
}

5 changes: 4 additions & 1 deletion examples/osmium_debug.cpp
Expand Up @@ -28,6 +28,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see
*/

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/handler/debug.hpp>

Expand All @@ -50,6 +53,6 @@ int main(int argc, char *argv[]) {
#else
Osmium::Handler::Debug handler;
#endif // OSMIUM_DEBUG_WITH_ENDTIME
infile.read(handler);
Osmium::Input::read(infile, handler);
}

5 changes: 4 additions & 1 deletion examples/osmium_find_bbox.cpp
Expand Up @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see

#include <cstdlib>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/handler/find_bbox.hpp>

Expand All @@ -40,7 +43,7 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
Osmium::Handler::FindBbox handler;
infile.read(handler);
Osmium::Input::read(infile, handler);

Osmium::OSM::Bounds b = handler.bounds();
std::cout << "minlon=" << b.bl().lon()
Expand Down
5 changes: 4 additions & 1 deletion examples/osmium_progress.cpp
Expand Up @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see

#include <cstdlib>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/handler/progress.hpp>

Expand All @@ -40,6 +43,6 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
Osmium::Handler::Progress handler;
infile.read(handler);
Osmium::Input::read(infile, handler);
}

9 changes: 7 additions & 2 deletions examples/osmium_range_from_history.cpp
Expand Up @@ -25,6 +25,11 @@ You should have received a copy of the Licenses along with Osmium. If not, see
*/

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT
#define OSMIUM_WITH_PBF_OUTPUT
#define OSMIUM_WITH_XML_OUTPUT

#include <osmium.hpp>
#include <osmium/handler/debug.hpp>
#include <osmium/handler/endtime.hpp>
Expand All @@ -38,8 +43,8 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
Osmium::OSMFile outfile(argv[2]);
Osmium::Handler::RangeFromHistory<Osmium::Output::Base> range_handler(outfile.create_output_file(), time(0), time(0));
Osmium::Handler::RangeFromHistory<Osmium::Output::Base> range_handler(Osmium::Output::open(outfile), time(0), time(0));
Osmium::Handler::EndTime<Osmium::Handler::RangeFromHistory<Osmium::Output::Base> > handler(&range_handler);
infile.read(handler);
Osmium::Input::read(infile, handler);
}

11 changes: 6 additions & 5 deletions examples/osmium_sizeof.cpp
Expand Up @@ -27,9 +27,13 @@ You should have received a copy of the Licenses along with Osmium. If not, see
*/

#include <cstdlib>
#include <osmpbf/osmpbf.h>

#include <osmium.hpp>
#include <osmium/output/xml.hpp>
#include <osmium/osm/object.hpp>
#include <osmium/osm/node.hpp>
#include <osmium/osm/way.hpp>
#include <osmium/osm/relation.hpp>
#include <osmium/osm/area.hpp>

int main() {
std::cout << "sizeof(Osmium::OSM::Object)=" << sizeof(Osmium::OSM::Object) << "\n";
Expand All @@ -52,8 +56,5 @@ int main() {
std::cout << "sizeof(OSMPBF::Relation)=" << sizeof(OSMPBF::Relation) << "\n";
std::cout << "sizeof(OSMPBF::DenseNodes)=" << sizeof(OSMPBF::DenseNodes) << "\n";
std::cout << "sizeof(OSMPBF::StringTable)=" << sizeof(OSMPBF::StringTable) << "\n";

std::cout << "sizeof(Osmium::Output::PBF)=" << sizeof(Osmium::Output::PBF) << "\n";
std::cout << "sizeof(Osmium::Output::XML)=" << sizeof(Osmium::Output::XML) << "\n";
}

5 changes: 4 additions & 1 deletion examples/osmium_stats.cpp
Expand Up @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see

#include <cstdlib>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/handler/statistics.hpp>

Expand All @@ -40,6 +43,6 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
Osmium::Handler::Statistics handler;
infile.read(handler);
Osmium::Input::read(infile, handler);
}

7 changes: 5 additions & 2 deletions examples/osmium_store_and_debug.cpp
Expand Up @@ -26,6 +26,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see
*/

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/handler/debug.hpp>
#include <osmium/storage/objectstore.hpp>
Expand All @@ -40,11 +43,11 @@ int main(int argc, char *argv[]) {
Osmium::OSMFile infile2(argv[2]);

Osmium::Storage::ObjectStore os;
infile1.read(os);
Osmium::Input::read(infile1, os);

Osmium::Handler::Debug debug;
Osmium::OSM::Meta meta;
Osmium::Storage::ObjectStore::ApplyHandler<Osmium::Handler::Debug> ah(os, &debug, meta);
infile2.read(ah);
Osmium::Input::read(infile2, ah);
}

5 changes: 4 additions & 1 deletion examples/osmium_time.cpp
Expand Up @@ -29,6 +29,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see
#include <time.h>
#include <sys/times.h>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>

class MyTimerHandler : public Osmium::Handler::Base {
Expand Down Expand Up @@ -71,7 +74,7 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
MyTimerHandler handler;
infile.read(handler);
Osmium::Input::read(infile, handler);

struct tms tms;
times(&tms);
Expand Down
5 changes: 4 additions & 1 deletion examples/osmium_toogr.cpp
Expand Up @@ -30,6 +30,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see

#include <ogrsf_frmts.h>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/storage/byid/sparse_table.hpp>
#include <osmium/storage/byid/mmap_file.hpp>
Expand Down Expand Up @@ -201,6 +204,6 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
MyOGRHandler handler;
infile.read(handler);
Osmium::Input::read(infile, handler);
}

8 changes: 5 additions & 3 deletions examples/osmium_toogr2.cpp
Expand Up @@ -32,6 +32,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see

#include <ogrsf_frmts.h>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/storage/byid/sparse_table.hpp>
#include <osmium/storage/byid/mmap_file.hpp>
Expand Down Expand Up @@ -193,12 +196,11 @@ int main(int argc, char *argv[]) {

// first pass
MyOGRHandlerPass1 handler_pass1(&handler_multipolygon);
infile.read(handler_pass1);
Osmium::Input::read(infile, handler_pass1);

// second pass
MyOGRHandlerPass2 handler_pass2(&handler_multipolygon);
hpass2 = &handler_pass2;

infile.read(handler_pass2);
Osmium::Input::read(infile, handler_pass2);
}

5 changes: 4 additions & 1 deletion examples/osmium_toshape.cpp
Expand Up @@ -27,6 +27,9 @@ You should have received a copy of the Licenses along with Osmium. If not, see

#include <cstdlib>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>
#include <osmium/storage/byid/sparse_table.hpp>
#include <osmium/storage/byid/mmap_file.hpp>
Expand Down Expand Up @@ -116,6 +119,6 @@ int main(int argc, char *argv[]) {

Osmium::OSMFile infile(argv[1]);
MyShapeHandler handler;
infile.read(handler);
Osmium::Input::read(infile, handler);
}

0 comments on commit cfe4cb8

Please sign in to comment.