Commit 7db9ecb4 authored by Bas Couwenberg's avatar Bas Couwenberg

Imported Upstream version 2.1.4

parent 6ce404e7
#-----------------------------------------------------------------------------
#
# Configuration for continuous integration service at travis-ci.org
#
#-----------------------------------------------------------------------------
language: generic
sudo: false
#-----------------------------------------------------------------------------
matrix:
include:
# 1/ Linux Clang Builds
- os: linux
compiler: linux-clang36-release
addons:
apt:
sources: ['llvm-toolchain-precise-3.6', 'ubuntu-toolchain-r-test', 'boost-latest']
packages: ['clang-3.6', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='clang++-3.6' BUILD_TYPE='Release'
- os: linux
compiler: linux-clang37-dev
addons:
apt:
sources: ['llvm-toolchain-precise-3.6', 'ubuntu-toolchain-r-test', 'boost-latest']
packages: ['clang-3.6', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='clang++-3.6' BUILD_TYPE='Dev'
- os: linux
compiler: linux-clang38-release
addons:
apt:
sources: ['llvm-toolchain-precise-3.8', 'ubuntu-toolchain-r-test', 'boost-latest']
packages: ['clang-3.8', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='clang++-3.8' BUILD_TYPE='Release'
- os: linux
compiler: linux-clang38-dev
addons:
apt:
sources: ['llvm-toolchain-precise-3.8', 'ubuntu-toolchain-r-test', 'boost-latest']
packages: ['clang-3.8', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='clang++-3.8' BUILD_TYPE='Dev'
# 2/ Linux GCC Builds
- os: linux
compiler: linux-gcc48-release
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'boost-latest']
packages: ['g++-4.8', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='g++-4.8' COMPILER_FLAGS='-Wno-return-type' BUILD_TYPE='Release'
- os: linux
compiler: linux-gcc48-dev
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'boost-latest']
packages: ['g++-4.8', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='g++-4.8' COMPILER_FLAGS='-Wno-return-type' BUILD_TYPE='Dev'
- os: linux
compiler: linux-gcc49-release
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'boost-latest']
packages: ['g++-4.9', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='g++-4.9' BUILD_TYPE='Release'
- os: linux
compiler: linux-gcc49-dev
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'boost-latest']
packages: ['g++-4.9', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='g++-4.9' BUILD_TYPE='Dev'
- os: linux
compiler: linux-gcc5-release
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'boost-latest']
packages: ['g++-5', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='g++-5' BUILD_TYPE='Release'
- os: linux
compiler: linux-gcc5-dev
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'boost-latest']
packages: ['g++-5', 'libboost1.55-all-dev', 'pandoc', 'libgdal1-dev', 'libgeos-dev', 'sqlite3']
env: COMPILER='g++-5' BUILD_TYPE='Dev'
# 3/ OSX Clang Builds
- os: osx
osx_image: xcode6.4
compiler: xcode64-clang-release
env: COMPILER='clang++' BUILD_TYPE='Release'
- os: osx
osx_image: xcode6.4
compiler: xcode64-clang-dev
env: COMPILER='clang++' BUILD_TYPE='Dev'
- os: osx
osx_image: xcode7
compiler: xcode7-clang-release
env: COMPILER='clang++' BUILD_TYPE='Release'
- os: osx
osx_image: xcode7
compiler: xcode7-clang-dev
env: COMPILER='clang++' BUILD_TYPE='Dev'
#-----------------------------------------------------------------------------
install:
- git clone --quiet --depth 1 https://github.com/osmcode/libosmium.git ../libosmium
- |
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
brew install cmake boost || true
fi
- cmake --version
before_script:
- cd ${TRAVIS_BUILD_DIR}
- mkdir build && cd build
- CXX=${COMPILER} CXXFLAGS=${COMPILER_FLAGS} cmake -LA .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
script:
- make VERBOSE=1 && ctest --output-on-failure
#-----------------------------------------------------------------------------
......@@ -29,6 +29,11 @@ flags = [
'-x',
'c++',
# workaround for https://github.com/Valloric/YouCompleteMe/issues/303
# also see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800618
'-isystem',
'/usr/lib/ycmd/clang_includes/',
'-Iinclude',
'-I%s/../libosmium/include' % basedir,
'-I/usr/include/gdal',
......
......@@ -13,16 +13,27 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
## [2.1.4] - 2016-09-16
### Changed
- Miscellaneous code cleanups.
### Fixed
- Windows build.
## [2.1.3] - 2016-03-30
### Added
- Add verbose option to osmcoastline_filter.
- osmcoastline_filter now shows memory used in verbose mode.
- Add verbose option to `osmcoastline_filter`.
- `osmcoastline_filter` now shows memory used in verbose mode.
### Changed
- Optimized osmcoastline_filter program.
- Optimized `osmcoastline_filter` program.
- Use more features from newest libosmium.
### Fixed
......@@ -44,7 +55,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- 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.
- Improved internal code using `unique_ptr` where possible.
### Fixed
......@@ -77,7 +88,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added man pages
[unreleased]: https://github.com/osmcode/osmium-tool/compare/v2.1.3...HEAD
[unreleased]: https://github.com/osmcode/osmium-tool/compare/v2.1.4...HEAD
[2.1.4]: https://github.com/osmcode/osmium-tool/compare/v2.1.3...v2.1.4
[2.1.3]: https://github.com/osmcode/osmium-tool/compare/v2.1.2...v2.1.3
[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
......
......@@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#-----------------------------------------------------------------------------
#
......@@ -22,7 +20,7 @@ project(osmcoastline)
set(OSMCOASTLINE_VERSION_MAJOR 2)
set(OSMCOASTLINE_VERSION_MINOR 1)
set(OSMCOASTLINE_VERSION_PATCH 3)
set(OSMCOASTLINE_VERSION_PATCH 4)
set(OSMCOASTLINE_VERSION
${OSMCOASTLINE_VERSION_MAJOR}.${OSMCOASTLINE_VERSION_MINOR}.${OSMCOASTLINE_VERSION_PATCH})
......@@ -31,6 +29,8 @@ add_definitions(-DOSMCOASTLINE_VERSION="${OSMCOASTLINE_VERSION}")
set(AUTHOR "Jochen Topf <jochen@topf.org>")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#-----------------------------------------------------------------------------
#
......@@ -48,7 +48,6 @@ if(MSVC)
find_library(GETOPT_LIBRARY NAMES wingetopt)
if(GETOPT_INCLUDE_DIR AND GETOPT_LIBRARY)
include_directories(${GETOPT_INCLUDE_DIR})
list(APPEND OSMIUM_LIBRARIES ${GETOPT_LIBRARY})
else()
set(GETOPT_MISSING 1)
endif()
......@@ -148,7 +147,7 @@ if(CPPCHECK)
# cpp doesn't find system includes for some reason, suppress that report
set(CPPCHECK_OPTIONS ${CPPCHECK_OPTIONS} --suppress=missingIncludeSystem)
file(GLOB ALL_CODE *.cpp)
file(GLOB ALL_CODE src/*.cpp)
set(CPPCHECK_FILES ${ALL_CODE})
......@@ -163,6 +162,23 @@ else()
endif(CPPCHECK)
#-----------------------------------------------------------------------------
#
# Optional "iwyu" target to check headers
# http://include-what-you-use.org/
#
#-----------------------------------------------------------------------------
find_program(IWYU_TOOL iwyu_tool.py)
if(IWYU_TOOL)
message(STATUS "Looking for iwyu_tool.py - found")
add_custom_target(iwyu ${IWYU_TOOL} -p ${CMAKE_BINARY_DIR})
else()
message(STATUS "Looking for iwyu_tool.py - not found")
message(STATUS " Make target iwyu not available")
endif()
#-----------------------------------------------------------------------------
#
# Optional "man" target to generate man pages
......@@ -223,6 +239,7 @@ endif(PANDOC)
#-----------------------------------------------------------------------------
find_library(GEOS_C_LIBRARIES NAMES geos_c)
include_directories (SYSTEM ${GEOS_C_INCLUDE_DIR})
add_definitions(${OSMIUM_WARNING_OPTIONS})
......
......@@ -8,6 +8,7 @@ http://wiki.openstreetmap.org/wiki/OSMCoastline
https://github.com/osmcode/osmcoastline
[![Build Status](https://secure.travis-ci.org/osmcode/osmcoastline.svg)](http://travis-ci.org/osmcode/osmcoastline)
## Prerequisites
......
......@@ -7,15 +7,15 @@
#-----------------------------------------------------------------------------
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})
target_link_libraries(osmcoastline ${OSMIUM_IO_LIBRARIES} ${GDAL_LIBRARIES} ${GEOS_C_LIBRARIES} ${GETOPT_LIBRARY})
install(TARGETS osmcoastline DESTINATION bin)
add_executable(osmcoastline_filter osmcoastline_filter.cpp)
target_link_libraries(osmcoastline_filter ${OSMIUM_IO_LIBRARIES})
target_link_libraries(osmcoastline_filter ${OSMIUM_IO_LIBRARIES} ${GETOPT_LIBRARY})
install(TARGETS osmcoastline_filter DESTINATION bin)
add_executable(osmcoastline_segments osmcoastline_segments.cpp srs.cpp)
target_link_libraries(osmcoastline_segments ${GDAL_LIBRARIES})
target_link_libraries(osmcoastline_segments ${GDAL_LIBRARIES} ${GETOPT_LIBRARY})
install(TARGETS osmcoastline_segments DESTINATION bin)
add_executable(osmcoastline_ways osmcoastline_ways.cpp return_codes.hpp)
......
......@@ -42,23 +42,21 @@ class CoastlineHandlerPass1 : public osmium::handler::Handler {
public:
CoastlineHandlerPass1(CoastlineRingCollection& coastline_rings) :
explicit CoastlineHandlerPass1(CoastlineRingCollection& coastline_rings) :
m_coastline_rings(coastline_rings) {
}
void way(const osmium::Way& way) {
// We are only interested in ways tagged with natural=coastline.
const char* natural = way.tags().get_value_by_key("natural");
if (natural && !strcmp(natural, "coastline")) {
const char* bogus = way.tags().get_value_by_key("coastline");
if (bogus && !strcmp(bogus, "bogus")) {
if (way.tags().has_tag("natural", "coastline")) {
if (way.tags().has_tag("coastline", "bogus")) {
return; // ignore bogus coastline in Antarctica
}
m_coastline_rings.add_way(way);
}
}
};
}; // class CoastlineHandlerPass1
/**
* Osmium handler for the second pass over the input file in which
......@@ -89,11 +87,10 @@ public:
}
void node(const osmium::Node& node) {
const char* natural = node.tags().get_value_by_key("natural");
if (natural && !strcmp(natural, "coastline")) {
if (node.tags().has_tag("natural", "coastline")) {
try {
m_output.add_error_point(m_factory.create_point(node), "tagged_node", node.id());
} catch (osmium::geometry_error&) {
} catch (const osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for node " << node.id() << ".\n";
}
}
......@@ -104,6 +101,6 @@ public:
}
}
};
}; // class CoastlineHandlerPass2
#endif // COASTLINE_HANDLERS_HPP
......@@ -20,15 +20,15 @@
*/
#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>
#include <ogr_geometry.h>
class OGRSpatialReference;
#include "coastline_polygons.hpp"
#include "output_database.hpp"
#include "return_codes.hpp"
#include "srs.hpp"
#include "util.hpp"
......@@ -46,14 +46,14 @@ std::unique_ptr<OGRPolygon> CoastlinePolygons::create_rectangular_polygon(double
// make sure we are inside the bounds for the output SRS
e.Intersect(srs.max_extent());
std::unique_ptr<OGRLinearRing> ring { new OGRLinearRing() };
std::unique_ptr<OGRLinearRing> ring{new OGRLinearRing()};
ring->addPoint(e.MinX, e.MinY);
ring->addPoint(e.MinX, e.MaxY);
ring->addPoint(e.MaxX, e.MaxY);
ring->addPoint(e.MaxX, e.MinY);
ring->closeRings();
std::unique_ptr<OGRPolygon> polygon { new OGRPolygon() };
std::unique_ptr<OGRPolygon> polygon{new OGRPolygon()};
polygon->addRingDirectly(ring.release());
polygon->assignSpatialReference(srs.out());
......@@ -95,7 +95,7 @@ void CoastlinePolygons::split_geometry(std::unique_ptr<OGRGeometry>&& geom, int
} else { // wkbMultiPolygon
const auto mp = static_cast_unique_ptr<OGRMultiPolygon>(std::move(geom));
while (mp->getNumGeometries() > 0) {
std::unique_ptr<OGRPolygon> polygon { static_cast<OGRPolygon*>(mp->getGeometryRef(0)) };
std::unique_ptr<OGRPolygon> polygon{static_cast<OGRPolygon*>(mp->getGeometryRef(0))};
mp->removeGeometry(0, false);
polygon->assignSpatialReference(srs.out());
split_polygon(std::move(polygon), level);
......@@ -108,7 +108,7 @@ void CoastlinePolygons::split_polygon(std::unique_ptr<OGRPolygon>&& polygon, int
m_max_split_depth = level;
}
int num_points = polygon->getExteriorRing()->getNumPoints();
const int num_points = polygon->getExteriorRing()->getNumPoints();
if (num_points <= m_max_points_in_polygon) {
// do not split the polygon if it is small enough
m_polygons.push_back(std::move(polygon));
......@@ -139,7 +139,7 @@ void CoastlinePolygons::split_polygon(std::unique_ptr<OGRPolygon>&& polygon, int
}
// split vertically
double MidY = (envelope.MaxY+envelope.MinY) / 2;
const double MidY = (envelope.MaxY+envelope.MinY) / 2;
b1 = create_rectangular_polygon(envelope.MinX, envelope.MinY, envelope.MaxX, MidY, m_expand);
b2 = create_rectangular_polygon(envelope.MinX, MidY, envelope.MaxX, envelope.MaxY, m_expand);
......@@ -151,15 +151,15 @@ void CoastlinePolygons::split_polygon(std::unique_ptr<OGRPolygon>&& polygon, int
}
// split horizontally
double MidX = (envelope.MaxX+envelope.MinX) / 2;
const double MidX = (envelope.MaxX+envelope.MinX) / 2;
b1 = create_rectangular_polygon(envelope.MinX, envelope.MinY, MidX, envelope.MaxY, m_expand);
b2 = create_rectangular_polygon(MidX, envelope.MinY, envelope.MaxX, envelope.MaxY, m_expand);
}
// Use intersection with bbox polygons to split polygon into two halfes
std::unique_ptr<OGRGeometry> geom1 { polygon->Intersection(b1.get()) };
std::unique_ptr<OGRGeometry> geom2 { polygon->Intersection(b2.get()) };
std::unique_ptr<OGRGeometry> geom1{polygon->Intersection(b1.get())};
std::unique_ptr<OGRGeometry> geom2{polygon->Intersection(b2.get())};
if (geom1 && (geom1->getGeometryType() == wkbPolygon || geom1->getGeometryType() == wkbMultiPolygon) &&
geom2 && (geom2->getGeometryType() == wkbPolygon || geom2->getGeometryType() == wkbMultiPolygon)) {
......@@ -247,12 +247,12 @@ void CoastlinePolygons::add_line_to_output(std::unique_ptr<OGRLineString> line,
// Add a coastline ring as LineString to output. Segments in this line that are
// near the southern edge of the map or near the antimeridian are suppressed.
void CoastlinePolygons::output_polygon_ring_as_lines(int max_points, const OGRLinearRing* ring) const {
int num = ring->getNumPoints();
const int num = ring->getNumPoints();
assert(num > 2);
std::unique_ptr<OGRPoint> point1 { new OGRPoint };
std::unique_ptr<OGRPoint> point2 { new OGRPoint };
std::unique_ptr<OGRLineString> line { new OGRLineString };
std::unique_ptr<OGRPoint> point1{new OGRPoint};
std::unique_ptr<OGRPoint> point2{new OGRPoint};
std::unique_ptr<OGRLineString> line{new OGRLineString};
ring->getPoint(0, point1.get());
for (int i=1; i < num; ++i) {
......@@ -262,7 +262,7 @@ void CoastlinePolygons::output_polygon_ring_as_lines(int max_points, const OGRLi
if (line->getNumPoints() >= max_points || !added) {
if (line->getNumPoints() >= 2) {
std::unique_ptr<OGRLineString> new_line { new OGRLineString };
std::unique_ptr<OGRLineString> new_line{new OGRLineString};
using std::swap;
swap(line, new_line);
add_line_to_output(std::move(new_line), ring->getSpatialReference());
......@@ -333,7 +333,7 @@ void CoastlinePolygons::split_bbox(OGREnvelope e, polygon_vector_type&& v) {
if (e.MaxX - e.MinX < e.MaxY-e.MinY) {
// split vertically
double MidY = (e.MaxY+e.MinY) / 2;
const double MidY = (e.MaxY+e.MinY) / 2;
e1.MinX = e.MinX;
e1.MinY = e.MinY;
......@@ -347,7 +347,7 @@ void CoastlinePolygons::split_bbox(OGREnvelope e, polygon_vector_type&& v) {
} else {
// split horizontally
double MidX = (e.MaxX+e.MinX) / 2;
const double MidX = (e.MaxX+e.MinX) / 2;
e1.MinX = e.MinX;
e1.MinY = e.MinY;
......@@ -371,8 +371,8 @@ void CoastlinePolygons::split_bbox(OGREnvelope e, polygon_vector_type&& v) {
OGREnvelope e;
polygon->getEnvelope(&e);
bool e1_intersects_e = e1.Intersects(e);
bool e2_intersects_e = e2.Intersects(e);
const bool e1_intersects_e = e1.Intersects(e);
const bool e2_intersects_e = e2.Intersects(e);
if (e1_intersects_e && e2_intersects_e) {
v1.emplace_back(static_cast<OGRPolygon*>(polygon->clone()));
......
......@@ -23,18 +23,15 @@
*/
#include <memory>
#include <utility>
#include <vector>
class OGRGeometry;
class OGRLinearRing;
class OGRLineString;
class OGRPoint;
class OGRPolygon;
class OGRMultiPolygon;
class OGREnvelope;
#include <ogr_geometry.h>
class OGRSpatialReference;
class OutputDatabase;
typedef std::vector<std::unique_ptr<OGRPolygon>> polygon_vector_type;
using polygon_vector_type = std::vector<std::unique_ptr<OGRPolygon>>;
/**
* A collection of land polygons created out of coastlines.
......@@ -123,6 +120,6 @@ public:
/// Write all coastlines to the output database (as lines).
void output_lines(int max_points) const;
};
}; // class CoastlinePolygons
#endif // COASTLINE_POLYGONS_HPP
......@@ -19,9 +19,14 @@
*/
#include <cassert>
#include <iostream>
#include <utility>
#include <ogr_geometry.h>
#include <osmium/geom/ogr.hpp>
#include <osmium/osm/undirected_segment.hpp>
#include "coastline_ring.hpp"
......@@ -90,7 +95,7 @@ void CoastlineRing::close_ring() {
}
void CoastlineRing::close_antarctica_ring(int epsg) {
double min = epsg == 4326 ? -90.0 : -85.0511288;
const double min = epsg == 4326 ? -90.0 : -85.0511288;
for (int lat = -78; lat > int(min); --lat) {
m_way_node_list.emplace_back(0, osmium::Location(-179.99999, double(lat)));
......@@ -110,7 +115,7 @@ void CoastlineRing::close_antarctica_ring(int epsg) {
std::unique_ptr<OGRPolygon> CoastlineRing::ogr_polygon(osmium::geom::OGRFactory<>& geom_factory, bool reverse) const {
geom_factory.polygon_start();
size_t num_points = 0;
std::size_t num_points = 0;
if (reverse) {
num_points = geom_factory.fill_polygon(m_way_node_list.crbegin(), m_way_node_list.crend());
} else {
......@@ -121,7 +126,7 @@ std::unique_ptr<OGRPolygon> CoastlineRing::ogr_polygon(osmium::geom::OGRFactory<
std::unique_ptr<OGRLineString> CoastlineRing::ogr_linestring(osmium::geom::OGRFactory<>& geom_factory, bool reverse) const {
geom_factory.linestring_start();
size_t num_points = 0;
std::size_t num_points = 0;
if (reverse) {
num_points = geom_factory.fill_linestring(m_way_node_list.crbegin(), m_way_node_list.crend());
} else {
......@@ -132,18 +137,18 @@ std::unique_ptr<OGRLineString> CoastlineRing::ogr_linestring(osmium::geom::OGRFa
std::unique_ptr<OGRPoint> CoastlineRing::ogr_first_point() const {
const osmium::NodeRef& node_ref = m_way_node_list.front();
return std::unique_ptr<OGRPoint>(new OGRPoint(node_ref.lon(), node_ref.lat()));
return std::unique_ptr<OGRPoint>{new OGRPoint(node_ref.lon(), node_ref.lat())};
}
std::unique_ptr<OGRPoint> CoastlineRing::ogr_last_point() const {
const osmium::NodeRef& node_ref = m_way_node_list.back();
return std::unique_ptr<OGRPoint>(new OGRPoint(node_ref.lon(), node_ref.lat()));
return std::unique_ptr<OGRPoint>{new OGRPoint(node_ref.lon(), node_ref.lat())};
}
// Pythagoras doesn't work on a round earth but that is ok here, we only need a
// rough measure anyway
double CoastlineRing::distance_to_start_position(osmium::Location pos) const {
osmium::Location p = m_way_node_list.front().location();
const osmium::Location p = m_way_node_list.front().location();
return (pos.lon() - p.lon()) * (pos.lon() - p.lon()) + (pos.lat() - p.lat()) * (pos.lat() - p.lat());
}
......
......@@ -22,6 +22,7 @@
*/
#include <cassert>
#include <map>
#include <memory>
#include <ostream>
......@@ -35,7 +36,7 @@ class OGRPoint;
class OGRLineString;
class OGRPolygon;
typedef std::multimap<osmium::object_id_type, osmium::Location*> posmap_type;
using posmap_type = std::multimap<osmium::object_id_type, osmium::Location*>;
/**
* The CoastlineRing class models a (possibly unfinished) ring of
......@@ -88,7 +89,7 @@ public:
/**
* Create CoastlineRing from a way.
*/
CoastlineRing(const osmium::Way& way) :
explicit CoastlineRing(const osmium::Way& way) :
m_way_node_list(),
m_ring_id(way.id()),
m_nways(1),
......@@ -108,26 +109,30 @@ public:
/// ID of first node in the ring.
osmium::object_id_type first_node_id() const {
assert(!m_way_node_list.empty());
return m_way_node_list.front().ref();
}
/// ID of last node in the ring.
osmium::object_id_type last_node_id() const {
assert(!m_way_node_list.empty());
return m_way_node_list.back().ref();
}
/// Position of the first node in the ring.
osmium::Location first_position() const {
assert(!m_way_node_list.empty());
return m_way_node_list.front().location();
}
/// Position of the last node in the ring.
osmium::Location last_position() const {
assert(!m_way_node_list.empty());
return m_way_node_list.back().location();
}
/// Return ID of this ring (defined as smallest ID of the ways making up the ring).
osmium::object_id_type ring_id() const {
osmium::object_id_type ring_id() const noexcept {
return m_ring_id;
}
......@@ -135,14 +140,14 @@ public:
* Set ring ID. The ring will only get the new ID if it is smaller than the
* old one.
*/
void update_ring_id(osmium::object_id_type new_id) {
void update_ring_id(osmium::object_id_type new_id) noexcept {
if (new_id < m_ring_id) {
m_ring_id = new_id;
}
}
/// Returns the number of ways making up this ring.
unsigned int nways() const {
unsigned int nways() const noexcept {
return m_nways;
}
......@@ -157,7 +162,7 @@ public:
}
/// Was this ring fixed because of missing/wrong OSM data?
bool is_fixed() const {
bool is_fixed() const noexcept {
return m_fixed;
}
......@@ -170,6 +175,7 @@ public:
* method does this.
*/
void fake_close() {
assert(!m_way_node_list.empty());
m_way_node_list.back().set_ref(first_node_id());
}
......@@ -258,7 +264,7 @@ public:
friend std::ostream& operator<<(std::ostream& out, const CoastlineRing& cp);
};
}; // class CoastlineRing
inline bool operator<(const CoastlineRing& lhs, const CoastlineRing& rhs) {
return lhs.first_position() < rhs.first_position();
......
......@@ -29,6 +29,12 @@
#include "output_database.hpp"
#include "srs.hpp"
#ifdef _MSC_VER
#include <io.h>
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
extern SRS srs;
extern bool debug;
......@@ -77,7 +83,7 @@ void CoastlineRingCollection::add_partial_ring(const osmium::Way& way) {
// way at the front. This means that the way together with the
// ring at front and the ring at back are now a complete ring.
if (mnext != m_start_nodes.end()) {
coastline_rings_list_t::iterator next = mnext->second;
auto next = mnext->second;
(*prev)->join(**next);
m_start_nodes.erase(mnext);
if ((*prev)->is_closed()) {
......@@ -99,7 +105,7 @@ void CoastlineRingCollection::add_partial_ring(const osmium::Way& way) {
// We found a CoastlineRing where we can add the way at the front.
if (mnext != m_start_nodes.end()) {
coastline_rings_list_t::iterator next = mnext->second;
auto next = mnext->second;
(*next)->add_at_front(way);
m_start_nodes.erase(mnext);
if ((*next)->is_closed()) {
......@@ -145,7 +151,7 @@ std::vector<OGRGeometry*> CoastlineRingCollection::add_polygons_to_vector() {
p->assignSpatialReference(srs.wgs84());
vector.push_back(p.release());
} else {
std::unique_ptr<OGRGeometry> geom { p->Buffer(0) };
std::unique_ptr<OGRGeometry> geom{p->Buffer(0)};
if (is_valid_polygon(geom.get())) {
geom->assignSpatialReference(srs.wgs84());
vector.push_back(geom.release());
......@@ -194,21 +200,21 @@ osmium::Location intersection(const osmium::Segment& s1, const osmium::Segment&s
return osmium::Location();
}
double denom = ((s2.second().lat() - s2.first().lat())*(s1.second().lon() - s1.first().lon())) -
const double denom = ((s2.second().lat() - s2.first().lat())*(s1.second().lon() - s1.first().lon())) -
((s2.second().lon() - s2.first().lon())*(s1.second().lat() - s1.first().lat()));