Commit 373bcb54 authored by Bas Couwenberg's avatar Bas Couwenberg

Imported Upstream version 2.1.2

parent 2e10bf9a
......@@ -29,7 +29,7 @@ flags = [
'-x',
'c++',
# libosmium include dirs
'-Iinclude',
'-I%s/../libosmium/include' % basedir,
'-I/usr/include/gdal',
......
......@@ -13,6 +13,26 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
## [2.1.2] - 2016-01-05
### Added
- Add --help/-h and --version/-V options to all programs.
### Changed
- Use a better approximation for the southernmost coordinate for Mercator
projection.
- Updated for newest libosmium version (2.5.2).
- Uses gdalcpp.hpp from https://github.com/joto/gdalcpp instead of directly
talking to GDAL/OGR. Makes this compatible with GDAL 2.
- Improved internal code using unique_ptr where possible.
### Fixed
- "Fixed" flag in rings layer now correct.
## [2.1.1] - 2015-08-31
### Changed
......@@ -39,7 +59,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added man pages
[unreleased]: https://github.com/osmcode/osmium-tool/compare/v2.1.1...HEAD
[unreleased]: https://github.com/osmcode/osmium-tool/compare/v2.1.2...HEAD
[2.1.2]: https://github.com/osmcode/osmium-tool/compare/v2.1.1...v2.1.2
[2.1.1]: https://github.com/osmcode/osmium-tool/compare/v2.1.0...v2.1.1
[2.1.0]: https://github.com/osmcode/osmium-tool/compare/v2.0.1...v2.1.0
[2.0.1]: https://github.com/osmcode/osmium-tool/compare/v2.0.0...v2.0.1
......
......@@ -22,11 +22,13 @@ project(osmcoastline)
set(OSMCOASTLINE_VERSION_MAJOR 2)
set(OSMCOASTLINE_VERSION_MINOR 1)
set(OSMCOASTLINE_VERSION_PATCH 1)
set(OSMCOASTLINE_VERSION_PATCH 2)
set(OSMCOASTLINE_VERSION
${OSMCOASTLINE_VERSION_MAJOR}.${OSMCOASTLINE_VERSION_MINOR}.${OSMCOASTLINE_VERSION_PATCH})
add_definitions(-DOSMCOASTLINE_VERSION="${OSMCOASTLINE_VERSION}")
set(AUTHOR "Jochen Topf <jochen@topf.org>")
......@@ -36,6 +38,8 @@ set(AUTHOR "Jochen Topf <jochen@topf.org>")
#
#-----------------------------------------------------------------------------
include_directories(include)
find_package(Osmium COMPONENTS io gdal)
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS})
......@@ -242,7 +246,7 @@ configure_file(
configure_file(
${PROJECT_SOURCE_DIR}/osmcoastline_readmeta
${PROJECT_BINARY_DIR}/osmcoastline_readmeta
COPYONLY
@ONLY
)
install(PROGRAMS osmcoastline_readmeta DESTINATION bin)
......
......@@ -13,8 +13,21 @@ https://github.com/osmcode/osmcoastline
### Libosmium
http://github.com/osmcode/libosmium
https://github.com/osmcode/libosmium
http://osmcode.org/libosmium
At least version 2.5.0 is needed.
### Protozero
https://github.com/mapbox/protozero
Debian/Ubuntu: protozero
Also included in the libosmium repository.
### Utfcpp
http://utfcpp.sourceforge.net/
Debian/Ubuntu: libutfcpp-dev
Also included in the libosmium repository.
### zlib (for PBF support)
......
......@@ -62,6 +62,8 @@ find_path(OSMIUM_INCLUDE_DIR osmium/osm.hpp
/opt
)
set(OSMIUM_INCLUDE_DIRS "${OSMIUM_INCLUDE_DIR}")
#----------------------------------------------------------------------
#
# Check for optional components
......@@ -251,20 +253,15 @@ endif()
# Check that all required libraries are available
#
#----------------------------------------------------------------------
list(REMOVE_DUPLICATES OSMIUM_EXTRA_FIND_VARS)
if (OSMIUM_EXTRA_FIND_VARS)
list(REMOVE_DUPLICATES OSMIUM_EXTRA_FIND_VARS)
endif()
# Handle the QUIETLY and REQUIRED arguments and set OSMIUM_FOUND to TRUE if
# all listed variables are TRUE.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Osmium REQUIRED_VARS OSMIUM_INCLUDE_DIR ${OSMIUM_EXTRA_FIND_VARS})
unset(OSMIUM_EXTRA_FIND_VARS)
# Copy the results to the output variables.
if(OSMIUM_FOUND)
set(OSMIUM_INCLUDE_DIRS ${OSMIUM_INCLUDE_DIR} ${OSMIUM_INCLUDE_DIRS})
else()
set(OSMIUM_INCLUDE_DIRS "")
endif()
#----------------------------------------------------------------------
#
# Add compiler flags
......
This diff is collapsed.
......@@ -15,7 +15,7 @@ $endfor$
$if(author)$
.SH COPYRIGHT
.PP
Copyright (C) 2012\-2015 Jochen Topf <jochen@topf.org>.
Copyright (C) 2012\-2016 Jochen Topf <jochen@topf.org>.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
......
......@@ -91,6 +91,9 @@ description of the options below and the README.md for details.
: Gives you detailed information on what **osmcoastline** is doing,
including timing.
-V, --version
: Display program version and license information.
# NOTES
......
......@@ -40,6 +40,9 @@ the **osmcoastline** and **osmcoastline_ways** programs work fine with it.
-o, --output=OSMFILE
: Where to write output (default: none)
-V, --version
: Display program version and license information.
# EXAMPLES
......
......@@ -9,6 +9,15 @@ osmcoastline_readmeta - display metadata from database create by osmcoastline
**osmcoastline_readmeta** \[*COASTLINE-DB*\]
# OPTIONS
-h, --help
: Display usage information.
-V, --version
: Display program version and license information.
# DESCRIPTION
This program displays various meta data from a database created by the
......
......@@ -31,6 +31,9 @@ coastline changes between different runs of the **osmcoastline** program.
-f, --format=FORMAT
: OGR format for writing out geometries.
-V, --version
: Display program version and license information.
# DIAGNOSTICS
......
......@@ -9,6 +9,15 @@ osmcoastline_ways - extract coastline ways from OSM data
**osmcoastline_ways** *INPUT-FILE* \[*OUTPUT-DB*\]
# OPTIONS
-h, --help
: Display usage information.
-V, --version
: Display program version and license information.
# DESCRIPTION
**osmcoastline_ways** extracts coastline ways from OSM data and writes them
......
......@@ -3,8 +3,24 @@
# osmcoastline_readmeta [COASTLINEDB]
#
OSMCOASTLINE_VERSION=@OSMCOASTLINE_VERSION@
SQLEXEC="sqlite3"
if [ "x$1" = "x--help" -o "x$1" = "x-h" ]; then
echo "Usage: osmcoastline_readmeta [COASTLINEDB]"
exit 0
fi
if [ "x$1" = "x--version" -o "x$1" = "x-V" ]; then
echo "osmcoastline_readmeta version $OSMCOASTLINE_VERSION"
echo "Copyright (C) 2012-2016 Jochen Topf <jochen@topf.org>"
echo "License: GNU GENERAL PUBLIC LICENSE Version 3 <http://gnu.org/licenses/gpl.html>."
echo "This is free software: you are free to change and redistribute it."
echo "There is NO WARRANTY, to the extent permitted by law.";
exit 0
fi
if [ "x$1" = "x" ]; then
DBFILE=testdata.db
else
......
......@@ -6,7 +6,7 @@
#
#-----------------------------------------------------------------------------
add_executable(osmcoastline osmcoastline.cpp coastline_ring.cpp coastline_ring_collection.cpp coastline_polygons.cpp output_database.cpp output_layers.cpp srs.cpp options.cpp)
add_executable(osmcoastline osmcoastline.cpp coastline_ring.cpp coastline_ring_collection.cpp coastline_polygons.cpp output_database.cpp srs.cpp options.cpp)
target_link_libraries(osmcoastline ${OSMIUM_IO_LIBRARIES} ${GDAL_LIBRARIES} ${GEOS_C_LIBRARIES})
install(TARGETS osmcoastline DESTINATION bin)
......@@ -18,7 +18,7 @@ add_executable(osmcoastline_segments osmcoastline_segments.cpp srs.cpp)
target_link_libraries(osmcoastline_segments ${GDAL_LIBRARIES})
install(TARGETS osmcoastline_segments DESTINATION bin)
add_executable(osmcoastline_ways osmcoastline_ways.cpp osmcoastline.hpp)
add_executable(osmcoastline_ways osmcoastline_ways.cpp return_codes.hpp)
target_link_libraries(osmcoastline_ways ${OSMIUM_IO_LIBRARIES} ${GDAL_LIBRARIES})
install(TARGETS osmcoastline_ways DESTINATION bin)
......@@ -3,7 +3,7 @@
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......@@ -34,7 +34,7 @@ class OGRMultiPolygon;
class OGREnvelope;
class OutputDatabase;
typedef std::vector<OGRPolygon*> polygon_vector_type;
typedef std::vector<std::unique_ptr<OGRPolygon>> polygon_vector_type;
/**
* A collection of land polygons created out of coastlines.
......@@ -74,12 +74,13 @@ class CoastlinePolygons {
std::unique_ptr<OGRPolygon> create_rectangular_polygon(double x1, double y1, double x2, double y2, double expand=0) const;
void split_geometry(std::unique_ptr<OGRGeometry> geom, int level);
void split_polygon(OGRPolygon* polygon, int level);
void split_geometry(std::unique_ptr<OGRGeometry>&& geom, int level);
void split_polygon(std::unique_ptr<OGRPolygon>&& polygon, int level);
void split_bbox(OGREnvelope e, polygon_vector_type&& v);
bool add_segment_to_line(OGRLineString* line, OGRPoint* point1, OGRPoint* point2);
void output_polygon_ring_as_lines(int max_points, OGRLinearRing* ring);
void add_line_to_output(std::unique_ptr<OGRLineString> line, OGRSpatialReference* srs) const;
bool add_segment_to_line(OGRLineString* line, OGRPoint* point1, OGRPoint* point2) const;
void output_polygon_ring_as_lines(int max_points, const OGRLinearRing* ring) const;
public:
......@@ -120,7 +121,7 @@ public:
unsigned int output_water_polygons();
/// Write all coastlines to the output database (as lines).
void output_lines(int max_points);
void output_lines(int max_points) const;
};
......
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......@@ -90,18 +90,18 @@ void CoastlineRing::close_ring() {
}
void CoastlineRing::close_antarctica_ring(int epsg) {
double min = epsg == 4326 ? -90.0 : -85.0511;
double min = epsg == 4326 ? -90.0 : -85.0511288;
for (double lat = -78.0; lat > min; --lat) {
m_way_node_list.emplace_back(0, osmium::Location(-179.99999, static_cast<double>(lat)));
for (int lat = -78; lat > int(min); --lat) {
m_way_node_list.emplace_back(0, osmium::Location(-179.99999, double(lat)));
}
for (int lon = -180; lon < 180; ++lon) {
m_way_node_list.emplace_back(0, osmium::Location(static_cast<double>(lon), min));
m_way_node_list.emplace_back(0, osmium::Location(double(lon), min));
}
for (double lat = min; lat < -78.0; ++lat) {
m_way_node_list.emplace_back(0, osmium::Location(179.99999, static_cast<double>(lat)));
for (int lat = int(min); lat < -78; ++lat) {
m_way_node_list.emplace_back(0, osmium::Location(179.99999, double(lat)));
}
m_way_node_list.push_back(m_way_node_list.front());
......
......@@ -3,7 +3,7 @@
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......@@ -126,7 +126,16 @@ unsigned int CoastlineRingCollection::check_positions(bool output_missing) {
return missing_positions;
}
void CoastlineRingCollection::add_polygons_to_vector(std::vector<OGRGeometry*>& vector) {
bool is_valid_polygon(const OGRGeometry* geometry) {
if (geometry && geometry->getGeometryType() == wkbPolygon) {
const auto polygon = static_cast<const OGRPolygon*>(geometry);
return (polygon->getExteriorRing()->getNumPoints() > 3) && (polygon->getNumInteriorRings() == 0) && geometry->IsValid();
}
return false;
}
std::vector<OGRGeometry*> CoastlineRingCollection::add_polygons_to_vector() {
std::vector<OGRGeometry*> vector;
vector.reserve(m_list.size());
for (const auto& ring : m_list) {
......@@ -137,15 +146,17 @@ void CoastlineRingCollection::add_polygons_to_vector(std::vector<OGRGeometry*>&
vector.push_back(p.release());
} else {
std::unique_ptr<OGRGeometry> geom { p->Buffer(0) };
if (geom && (geom->getGeometryType() == wkbPolygon) && (static_cast<OGRPolygon*>(geom.get())->getExteriorRing()->getNumPoints() > 3) && (static_cast<OGRPolygon*>(geom.get())->getNumInteriorRings() == 0) && geom->IsValid()) {
if (is_valid_polygon(geom.get())) {
geom->assignSpatialReference(srs.wgs84());
vector.push_back(static_cast<OGRPolygon*>(geom.release()));
vector.push_back(geom.release());
} else {
std::cerr << "Ignoring invalid polygon geometry (ring_id=" << ring->ring_id() << ").\n";
}
}
}
}
return vector;
}
unsigned int CoastlineRingCollection::output_rings(OutputDatabase& output) {
......@@ -154,18 +165,18 @@ unsigned int CoastlineRingCollection::output_rings(OutputDatabase& output) {
for (const auto& ring : m_list) {
if (ring->is_closed()) {
if (ring->npoints() > 3) {
output.add_ring(ring->ogr_polygon(m_factory, true).release(), ring->ring_id(), ring->nways(), ring->npoints(), ring->is_fixed());
output.add_ring(ring->ogr_polygon(m_factory, true), ring->ring_id(), ring->nways(), ring->npoints(), ring->is_fixed());
} else if (ring->npoints() == 1) {
output.add_error_point(ring->ogr_first_point(), "single_point_in_ring", ring->first_node_id());
warnings++;
} else { // ring->npoints() == 2 or 3
output.add_error_line(ring->ogr_linestring(m_factory, true).release(), "not_a_ring", ring->ring_id());
output.add_error_line(ring->ogr_linestring(m_factory, true), "not_a_ring", ring->ring_id());
output.add_error_point(ring->ogr_first_point(), "not_a_ring", ring->first_node_id());
output.add_error_point(ring->ogr_last_point(), "not_a_ring", ring->last_node_id());
warnings++;
}
} else {
output.add_error_line(ring->ogr_linestring(m_factory, true).release(), "not_closed", ring->ring_id());
output.add_error_line(ring->ogr_linestring(m_factory, true), "not_closed", ring->ring_id());
output.add_error_point(ring->ogr_first_point(), "end_point", ring->first_node_id());
output.add_error_point(ring->ogr_last_point(), "end_point", ring->last_node_id());
warnings++;
......@@ -409,7 +420,7 @@ unsigned int CoastlineRingCollection::output_questionable(const CoastlinePolygon
// go through all the polygons that have been created before and mark the outer rings
for (const auto& polygon : polygons) {
OGRLinearRing* exterior_ring = polygon->getExteriorRing();
const OGRLinearRing* exterior_ring = polygon->getExteriorRing();
osmium::Location pos(exterior_ring->getX(0), exterior_ring->getY(0));
std::vector<pos_ring_ptr_t>::iterator rings_it = lower_bound(rings.begin(), rings.end(), std::make_pair<osmium::Location, CoastlineRing*>(std::move(pos), nullptr));
if (rings_it != rings.end()) {
......
......@@ -3,7 +3,7 @@
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......@@ -105,7 +105,7 @@ public:
unsigned int check_positions(bool output_missing);
void add_polygons_to_vector(std::vector<OGRGeometry*>& vector);
std::vector<OGRGeometry*> add_polygons_to_vector();
unsigned int output_rings(OutputDatabase& output);
......
#ifndef OGR_INCLUDE_HPP
#define OGR_INCLUDE_HPP
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4458)
# pragma warning(disable : 4251)
#else
# pragma GCC diagnostic push
# ifdef __clang__
# pragma GCC diagnostic ignored "-Wdocumentation-unknown-command"
# endif
# pragma GCC diagnostic ignored "-Wfloat-equal"
# pragma GCC diagnostic ignored "-Wold-style-cast"
# pragma GCC diagnostic ignored "-Wpadded"
# pragma GCC diagnostic ignored "-Wredundant-decls"
# pragma GCC diagnostic ignored "-Wshadow"
#endif
/* Strictly speaking the following include would be enough here,
but everybody using this file will very likely need the other includes,
so we are adding them here, so that not everybody will need all those
pragmas to disable warnings. */
//#include <ogr_geometry.h>
#include <ogr_api.h>
#include <ogrsf_frmts.h>
#ifdef _MSC_VER
# pragma warning(pop)
#else
# pragma GCC diagnostic pop
#endif
struct OGRDataSourceDestroyer {
void operator()(OGRDataSource* ptr) {
if (ptr) {
OGRDataSource::DestroyDataSource(ptr);
}
}
};
#endif // OGR_INCLUDE_HPP
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......@@ -25,7 +25,7 @@
#include <cstdlib>
#include <getopt.h>
#include "osmcoastline.hpp"
#include "return_codes.hpp"
#include "options.hpp"
Options::Options(int argc, char* argv[]) :
......@@ -62,11 +62,12 @@ Options::Options(int argc, char* argv[]) :
{"srs", required_argument, 0, 's'},
{"write-segments", required_argument, 0, 'S'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
while (1) {
int c = getopt_long(argc, argv, "b:c:idhlm:o:p:rfs:S:v", long_options, 0);
int c = getopt_long(argc, argv, "b:c:idhlm:o:p:rfs:S:vV", long_options, 0);
if (c == -1)
break;
......@@ -131,6 +132,13 @@ Options::Options(int argc, char* argv[]) :
case 'v':
verbose = true;
break;
case 'V':
std::cout << "osmcoastline version " OSMCOASTLINE_VERSION "\n"
<< "Copyright (C) 2012-2016 Jochen Topf <jochen@topf.org>\n"
<< "License: GNU GENERAL PUBLIC LICENSE Version 3 <http://gnu.org/licenses/gpl.html>.\n"
<< "This is free software: you are free to change and redistribute it.\n"
<< "There is NO WARRANTY, to the extent permitted by law.\n";
exit(return_code_ok);
default:
exit(return_code_cmdline);
}
......@@ -197,6 +205,7 @@ void Options::print_help() const {
<< " -s, --srs=EPSGCODE - Set SRS (4326 for WGS84 (default) or 3857)\n"
<< " -S, --write-segments=FILE - Write segments to given file\n"
<< " -v, --verbose - Verbose output\n"
<< " -V, --version - Show version and exit\n"
<< "\n";
}
......@@ -3,7 +3,7 @@
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......@@ -27,17 +27,17 @@
#include <osmium/io/any_input.hpp>
#include <osmium/visitor.hpp>
#include "osmcoastline.hpp"
#include "return_codes.hpp"
#include "coastline_ring.hpp"
#include "coastline_ring_collection.hpp"
#include "coastline_polygons.hpp"
#include "output_database.hpp"
#include "output_layers.hpp"
#include "options.hpp"
#include "stats.hpp"
#include "coastline_handlers.hpp"
#include "srs.hpp"
#include "util.hpp"
#include "verbose_output.hpp"
// The global SRS object is used in many places to transform
......@@ -56,8 +56,7 @@ const unsigned int max_warnings = 500;
* This function assembles all the coastline rings into one huge multipolygon.
*/
polygon_vector_type create_polygons(CoastlineRingCollection& coastline_rings, OutputDatabase& output, unsigned int* warnings, unsigned int* errors) {
std::vector<OGRGeometry*> all_polygons;
coastline_rings.add_polygons_to_vector(all_polygons);
std::vector<OGRGeometry*> all_polygons = coastline_rings.add_polygons_to_vector();
int is_valid;
const char* options[] = { "METHOD=ONLY_CCW", nullptr };
......@@ -69,8 +68,10 @@ polygon_vector_type create_polygons(CoastlineRingCollection& coastline_rings, Ou
std::cerr << "organizePolygons() done\n";
}
assert(mega_geometry->getGeometryType() == wkbMultiPolygon);
OGRMultiPolygon* mega_multipolygon = static_cast<OGRMultiPolygon*>(mega_geometry.get());
if (mega_geometry->getGeometryType() != wkbMultiPolygon) {
throw std::runtime_error("mega geometry isn't a multipolygon. Something is very wrong!");
}
OGRMultiPolygon* mega_multipolygon = static_cast<OGRMultiPolygon*>(mega_geometry.release());
polygon_vector_type polygons;
polygons.reserve(mega_multipolygon->getNumGeometries());
......@@ -79,13 +80,13 @@ polygon_vector_type create_polygons(CoastlineRingCollection& coastline_rings, Ou
assert(geom->getGeometryType() == wkbPolygon);
std::unique_ptr<OGRPolygon> p { static_cast<OGRPolygon*>(geom) };
if (p->IsValid()) {
polygons.push_back(p.release());
polygons.push_back(std::move(p));
} else {
output.add_error_line(static_cast<OGRLineString*>(p->getExteriorRing()->clone()), "invalid");
output.add_error_line(make_unique_ptr_clone<OGRLineString>(p->getExteriorRing()), "invalid");
std::unique_ptr<OGRGeometry> buf0 { p->Buffer(0) };
if (buf0 && buf0->getGeometryType() == wkbPolygon && buf0->IsValid()) {
buf0->assignSpatialReference(srs.wgs84());
polygons.emplace_back(static_cast<OGRPolygon*>(buf0.release()));
polygons.push_back(static_cast_unique_ptr<OGRPolygon>(std::move(buf0)));
(*warnings)++;
} else {
std::cerr << "Ignoring invalid polygon geometry.\n";
......@@ -95,6 +96,7 @@ polygon_vector_type create_polygons(CoastlineRingCollection& coastline_rings, Ou
}
mega_multipolygon->removeGeometry(-1, FALSE);
delete mega_multipolygon;
return polygons;
}
......@@ -183,7 +185,7 @@ int main(int argc, char *argv[]) {
} else {
vout << "Will NOT create geometry index (because you told me to using --no-index/-i).\n";
}
OutputDatabase output_database(options.output_database, options.create_index);
OutputDatabase output_database(options.output_database, srs, options.create_index);
// The collection of all coastline rings we will be filling and then
// operating on.
......
/*
Copyright 2012-2015 Jochen Topf <jochen@topf.org>.
Copyright 2012-2016 Jochen Topf <jochen@topf.org>.
This file is part of OSMCoastline.
......@@ -19,22 +19,26 @@
*/
#include <algorithm>
#include <iostream>
#include <set>
#include <getopt.h>
#include <osmium/io/any_input.hpp>
#include <osmium/io/input_iterator.hpp>
#include <osmium/io/output_iterator.hpp>
#include <osmium/io/pbf_output.hpp>
#include <osmium/handler.hpp>
#include <osmium/osm/entity_bits.hpp>
#include "osmcoastline.hpp"
#include "return_codes.hpp"
void print_help() {
std::cout << "osmcoastline_filter [OPTIONS] OSMFILE\n"
<< "\nOptions:\n"
<< " -h, --help - This help message\n"
<< " -o, --output=OSMFILE - Where to write output (default: none)\n"
<< " -V, --version - Show version and exit\n"
<< "\n";
}
......@@ -44,11 +48,12 @@ int main(int argc, char* argv[]) {
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"output", required_argument, 0, 'o'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
while (1) {
int c = getopt_long(argc, argv, "ho:", long_options, 0);
int c = getopt_long(argc, argv, "ho:V", long_options, 0);
if (c == -1)
break;
......@@ -59,6 +64,13 @@ int main(int argc, char* argv[]) {
case 'o':
output_filename = optarg;
break;
case 'V':
std::cout << "osmcoastline_filter version " OSMCOASTLINE_VERSION "\n"
<< "Copyright (C) 2012-2016 Jochen Topf <jochen@topf.org>\n"
<< "License: GNU GENERAL PUBLIC LICENSE Version 3 <http://gnu.org/licenses/gpl.html>.\n"
<< "This is free software: you are free to change and redistribute it.\n"
<< "There is NO WARRANTY, to the extent permitted by law.\n";
exit(return_code_ok);
default:
exit(return_code_fatal);
}
......@@ -82,55 +94,39 @@ int main(int argc, char* argv[]) {
try {
osmium::io::Writer writer(output_filename, header);
auto output_it = osmium::io::make_output_iterator(writer);
std::set<osmium::object_id_type> ids;
osmium::memory::Buffer output_buffer(10240);
std::vector<osmium::object_id_type> ids;
{
osmium::io::Reader reader(infile, osmium::osm_entity_bits::way);
while (auto input_buffer = reader.read()) {
for (auto it = input_buffer.begin<const osmium::Way>(); it != input_buffer.end<const osmium::Way>(); ++it) {
const char* natural = it->get_value_by_key("natural");
if (natural && !strcmp(natural, "coastline")) {
output_buffer.add_item(*it);
output_buffer.commit();
if (output_buffer.committed() >= 10240) {
osmium::memory::Buffer new_buffer(10240);
std::swap(output_buffer, new_buffer);
writer(std::move(new_buffer));
}
for (const auto& nr : it->nodes()) {
ids.insert(nr.ref());
}
auto ways = osmium::io::make_input_iterator_range<const osmium::Way>(reader);
for (const osmium::Way& way : ways) {
const char* natural = way.get_value_by_key("natural");
if (natural && !strcmp(natural, "coastline")) {
*output_it++ = way;
for (const auto& nr : way.nodes()) {
ids.push_back(nr.ref());
}
}
}
reader.close();
}