Skip to content
Commits on Source (5)
---
Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-runtime-references,-hicpp-invalid-access-moved,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-vararg,-misc-macro-parentheses,-misc-unused-parameters,-modernize-make-unique,-modernize-raw-string-literal,-readability-avoid-const-params-in-decls,-readability-implicit-bool-cast,-readability-implicit-bool-conversion'
Checks: '*,-android-cloexec-*,-bugprone-branch-clone,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-macro-usage,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-vararg,-fuchsia-*,-google-runtime-references,-hicpp-avoid-c-arrays,-hicpp-invalid-access-moved,-hicpp-no-array-decay,-hicpp-no-assembler,-hicpp-vararg,-misc-macro-parentheses,-misc-non-private-member-variables-in-classes,-misc-unused-parameters,-modernize-avoid-c-arrays,-modernize-make-unique,-modernize-raw-string-literal,-modernize-use-trailing-return-type,-readability-avoid-const-params-in-decls,-readability-implicit-bool-cast,-readability-implicit-bool-conversion,-readability-magic-numbers'
#
# For a list of check options, see:
# https://clang.llvm.org/extra/clang-tidy/checks/list.html
......@@ -9,6 +9,10 @@ Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-
# android-cloexec-*
# O_CLOEXEC isn't available on Windows making this non-portable.
#
# bugprone-branch-clone
# Nice idea but collides but with switch statements we'll need to use
# fall-throughs to fix this, which is also bad.
#
# bugprone-macro-parentheses
# False positive in the only place where it reports something and
# disabling locally doesn't work.
......@@ -23,6 +27,19 @@ Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-
# clang-analyzer-optin.cplusplus.VirtualCall
# Disable a warning we get from the Catch test framework.
#
# cppcoreguidelines-avoid-c-arrays
# Alias for modernize-avoid-c-arrays.
#
# cppcoreguidelines-avoid-magic-numbers
# Generally good advice, but there are too many places where this is
# useful, for instance in tests.
#
# cppcoreguidelines-macro-usage
# There are cases where we actually need macros.
#
# cppcoreguidelines-non-private-member-variables-in-classes
# Alias for misc-non-private-member-variables-in-classes
#
# cppcoreguidelines-owning-memory
# Don't want to add dependency on gsl library.
#
......@@ -55,6 +72,9 @@ Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-
# This is just a matter of preference, and we can't change the interfaces
# now anyways.
#
# hicpp-avoid-c-arrays
# Alias for modernize-avoid-c-arrays.
#
# hicpp-invalid-access-moved
# Creates false positives.
#
......@@ -70,10 +90,19 @@ Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-
# misc-macro-parentheses
# Old name for bugprone-macro-parentheses.
#
# misc-non-private-member-variables-in-classes
# Reports this also for structs, which doesn't make any sense. There is
# an option "IgnoreClassesWithAllMemberVariablesBeingPublic" which should
# disable this, but it didn't work for me.
#
# misc-unused-parameters
# Can't be fixed, because then Doxygen will complain. (In file
# include/osmium/area/problem_reporter.hpp).
#
# modernize-avoid-c-arrays
# Makes sense for some array, but especially for char arrays using
# std::array isn't a good solution.
#
# modernize-make-unique
# This is a C++11 library and C++ doesn't have std::make_unique.
#
......@@ -81,6 +110,9 @@ Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-
# Readability isn't that much better, arguably worse because of the new
# syntax.
#
# modernize-use-trailing-return-type
# I am not quite that modern.
#
# readability-avoid-const-params-in-decls
# This is header only library, so the declaration and implementation are
# often the same and we want to have the const in implementations.
......@@ -91,6 +123,9 @@ Checks: '*,-android-cloexec-*,-bugprone-macro-parentheses,-cert-dcl21-cpp,-cert-
# readability-implicit-bool-conversion
# I don't think this makes the code more readable.
#
# readability-magic-numbers
# Alias for cppcoreguidelines-avoid-magic-numbers.
#
#WarningsAsErrors: '*'
HeaderFilterRegex: '\/include\/osmium\/.*'
...
......@@ -42,6 +42,9 @@ addons_shortcuts:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'libboost-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'clang-6.0', 'g++-6', 'gcc-6']
addons_clang7: &clang7
apt:
packages: [ 'libboost-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'clang-7' ]
addons_gcc48: &gcc48
apt:
packages: [ 'libboost-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'g++-4.8', 'gcc-4.8' ]
......@@ -57,8 +60,18 @@ addons_shortcuts:
packages: [ 'libboost-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'g++-6', 'gcc-6' ]
addons_gcc7: &gcc7
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'libboost-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin', 'g++-7', 'gcc-7' ]
packages: [ 'libboost-all-dev', 'libgdal-dev', 'libproj-dev', 'libsparsehash-dev', 'spatialite-bin' ]
#-----------------------------------------------------------------------------
addons:
homebrew:
packages:
- cmake
- boost
- google-sparsehash
- gdal
update: true
#-----------------------------------------------------------------------------
......@@ -104,6 +117,20 @@ matrix:
env: CC='clang-6.0' CXX='clang++-6.0' BUILD_TYPE='Release'
addons: *clang60
- os: linux
compiler: linux-clang7-debug
env: CC='clang-7' CXX='clang++-7' BUILD_TYPE='Debug'
CXXFLAGS="-fsanitize=address,undefined,integer -fno-sanitize-recover=all -fno-omit-frame-pointer"
LDFLAGS="-fsanitize=address,undefined,integer"
addons: *clang7
dist: bionic
- os: linux
compiler: linux-clang7-release
env: CC='clang-7' CXX='clang++-7' BUILD_TYPE='Release'
addons: *clang7
dist: bionic
# Linux GCC Builds
- os: linux
compiler: linux-gcc48-dev
......@@ -130,16 +157,19 @@ matrix:
compiler: linux-gcc7-dev
env: CC='gcc-7' CXX='g++-7' BUILD_TYPE='Dev'
addons: *gcc7
dist: bionic
- os: linux
compiler: linux-gcc7-coverage
env: CC='gcc-7' CXX='g++-7' BUILD_TYPE='Coverage'
addons: *gcc7
dist: bionic
- os: linux
compiler: linux-gcc7-release
env: CC='gcc-7' CXX='g++-7' BUILD_TYPE='Release'
addons: *gcc7
dist: bionic
# OSX Clang Builds
- os: osx
......@@ -153,23 +183,23 @@ matrix:
env: CC='clang' CXX='clang++' BUILD_TYPE='Dev'
- os: osx
osx_image: xcode10.1
osx_image: xcode10.2
compiler: xcode10-clang-dev
env: CC='clang' CXX='clang++' BUILD_TYPE='Dev'
- os: osx
osx_image: xcode10.1
compiler: xcode10-clang-release
osx_image: xcode11
compiler: xcode11-clang-dev
env: CC='clang' CXX='clang++' BUILD_TYPE='Dev'
- os: osx
osx_image: xcode11
compiler: xcode11-clang-release
env: CC='clang' CXX='clang++' BUILD_TYPE='Release'
install:
- git clone --quiet --depth 1 https://github.com/mapbox/protozero.git ../protozero
- |
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
brew remove gdal
brew install cmake boost google-sparsehash gdal || true
fi
- cmake --version
before_script:
......
......@@ -13,6 +13,44 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed
## [2.15.2] - 2019-08-16
### Added
* Instead of handler classes, the `apply` function can now also take
lambdas (or objects from classes implementing `operator()`).
* Add swap, copy constructor and assignment operator to IdSetDense.
### Changed
* Enable use of the old proj API in proj version 6. This is a stopgap
solution until we find a better one.
* Better error messages when there is an error parsing a timestamp.
* Cleaned up a lot of code based on clang-tidy warnings.
* Ignore <bbox> or <bounds> subelement of <way> or <relation>. <bounds>
elements are created by Overpass API as subelements of ways or relations
when the "out bb" format is used. <bbox> subelements turn up in files
downloaded from http://download.openstreetmap.fr/replication . Libosmium
used to throw an error like "Unknown element in <way>: bbox". With this
commit, these subelements are ignored, ie. there is no error any more,
but the data is not read.
* Add swap, copy constructor and assignment operator to IdSetDense.
* Update included catch.hpp to 1.12.2.
* Retire use of `OSMIUM_NORETURN` macro. Use `[[noreturn]]` instead.
### Fixed
* Do not build areas with more than 100 locations where rings touch.
Places where rings touch are unusual for normal multipolygons and the
algorithm in libosmium that assembles multipolygons does not handle
them well. If there are too many touching points it becomes very slow.
This is not a problem for almost all multipolygons. As I am writing
this there are only three relations in the OSM database with more than
100 touching points, all of them rather weird boundaries in the US.
With this commit libosmium will simply ignore those areas to keep the
processing speed within reasonable bounds.
## [2.15.1] - 2019-02-26
### Added
......@@ -918,7 +956,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
Doxygen (up to version 1.8.8). This version contains a workaround to fix
this.
[unreleased]: https://github.com/osmcode/libosmium/compare/v2.15.1...HEAD
[unreleased]: https://github.com/osmcode/libosmium/compare/v2.15.2...HEAD
[2.15.2]: https://github.com/osmcode/libosmium/compare/v2.15.1...v2.15.2
[2.15.1]: https://github.com/osmcode/libosmium/compare/v2.15.0...v2.15.1
[2.15.0]: https://github.com/osmcode/libosmium/compare/v2.14.2...v2.15.0
[2.14.2]: https://github.com/osmcode/libosmium/compare/v2.14.1...v2.14.2
......
......@@ -40,7 +40,7 @@ project(libosmium)
set(LIBOSMIUM_VERSION_MAJOR 2)
set(LIBOSMIUM_VERSION_MINOR 15)
set(LIBOSMIUM_VERSION_PATCH 1)
set(LIBOSMIUM_VERSION_PATCH 2)
set(LIBOSMIUM_VERSION
"${LIBOSMIUM_VERSION_MAJOR}.${LIBOSMIUM_VERSION_MINOR}.${LIBOSMIUM_VERSION_PATCH}")
......@@ -424,7 +424,7 @@ endif()
#
#-----------------------------------------------------------------------------
message(STATUS "Looking for clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-7 clang-tidy-7.0 clang-tidy-6.0 clang-tidy-5.0)
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-10 clang-tidy-9 clang-tidy-8 clang-tidy-7 clang-tidy-7.0 clang-tidy-6.0 clang-tidy-5.0)
if(CLANG_TIDY)
message(STATUS "Looking for clang-tidy - found ${CLANG_TIDY}")
......
......@@ -7,7 +7,7 @@ A fast and flexible C++ library for working with OpenStreetMap data.
Libosmium works on Linux, Mac OSX and Windows.
[![Travis Build Status](https://secure.travis-ci.org/osmcode/libosmium.svg)](https://travis-ci.org/osmcode/libosmium)
[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/ep07l3x5rk3hd8sp/branch/master?svg=true)](https://ci.appveyor.com/project/lonvia/libosmium/branch/master)
[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/yy099a4vxcb604rn/branch/master?svg=true)](https://ci.appveyor.com/project/lonvia/libosmium-eq41p/branch/master)
[![Coverage Status](https://codecov.io/gh/osmcode/libosmium/branch/master/graph/badge.svg)](https://codecov.io/gh/osmcode/libosmium)
[![Packaging status](https://repology.org/badge/tiny-repos/libosmium.svg)](https://repology.org/metapackage/libosmium)
......
......@@ -52,7 +52,7 @@ int main(int argc, char* argv[]) {
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
const auto buffer_size = buffer.committed() / (1024 * 1024); // buffer size in MBytes
const int runs = std::max(10, static_cast<int>(5000ull / buffer_size));
const int runs = std::max(10, static_cast<int>(5000ULL / buffer_size));
std::cout << "input: filename=" << input_filename << " buffer_size=" << buffer_size << "MBytes\n";
std::cout << "runs: " << runs << "\n";
......
......@@ -13,8 +13,8 @@ bash -lc "pacman -S --needed --noconfirm mingw-w64-x86_64-gcc mingw-w64-x86_64-g
bash -lc "pacman -S --needed --noconfirm mingw-w64-x86_64-postgresql mingw-w64-x86_64-netcdf mingw-w64-x86_64-crypto++"
call C:\msys64\mingw64\bin\gem.cmd install json
REM Workaround for problem with gdal (see https://github.com/osmcode/libosmium/issues/262)
copy /y C:\msys64\mingw64\bin\libjson-c-4.dll C:\msys64\mingw64\bin\libjson-c-3.dll
REM Workaround for problem with spatialite (see https://github.com/osmcode/libosmium/issues/262)
copy /y C:\msys64\mingw64\bin\libreadline8.dll C:\msys64\mingw64\bin\libreadline7.dll
echo "Setting PROJ_LIB variable for correct PROJ.4 working"
set PROJ_LIB=c:\msys64\mingw64\share\proj
......
libosmium (2.15.2-1) unstable; urgency=medium
* New upstream release.
* Don't define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H, done upstream.
-- Bas Couwenberg <sebastic@debian.org> Sat, 17 Aug 2019 08:04:26 +0200
libosmium (2.15.1-2) unstable; urgency=medium
* Define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H for PROJ 6.0.0 compatibility.
......
......@@ -5,9 +5,6 @@
# Verbose make output
export VERBOSE=1
# Workaround for proj_api.h deprecation in PROJ 6.0.0
export DEB_CXXFLAGS_MAINT_APPEND=-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
%:
......
......@@ -58,12 +58,12 @@ using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
class AmenityHandler : public osmium::handler::Handler {
// Print info about one amenity to stdout.
void print_amenity(const char* type, const char* name, const osmium::geom::Coordinates& c) {
static void print_amenity(const char* type, const char* name, const osmium::geom::Coordinates& c) {
std::printf("%8.4f,%8.4f %-15s %s\n", c.x, c.y, type, name ? name : "");
}
// Calculate the center point of a NodeRefList.
osmium::geom::Coordinates calc_center(const osmium::NodeRefList& nr_list) {
static osmium::geom::Coordinates calc_center(const osmium::NodeRefList& nr_list) {
// Coordinates simply store an X and Y coordinate pair as doubles.
// (Unlike osmium::Location which stores them more efficiently as
// 32 bit integers.) Use Coordinates when you want to do calculations
......
......@@ -66,7 +66,7 @@ class RewriteHandler : public osmium::handler::Handler {
// Copy all tags with two changes:
// * Do not copy "created_by" tags
// * Change "landuse=forest" into "natural=wood"
void copy_tags(osmium::builder::Builder& parent, const osmium::TagList& tags) {
static void copy_tags(osmium::builder::Builder& parent, const osmium::TagList& tags) {
// The TagListBuilder is used to create a list of tags. The parameter
// to create it is a reference to the builder of the object that
......
......@@ -182,7 +182,7 @@ class Options {
bool m_array_format = false;
bool m_list_format = false;
void print_help() {
static void print_help() {
std::cout << "Usage: osmium_index_lookup [OPTIONS]\n\n"
<< "-h, --help Print this help message\n"
<< "-a, --array=FILE Read given index file in array format\n"
......@@ -193,7 +193,7 @@ class Options {
;
}
void print_usage(const char* prgname) {
static void print_usage(const char* prgname) {
std::cout << "Usage: " << prgname << " [OPTIONS]\n\n";
std::exit(0);
}
......
......@@ -33,7 +33,7 @@
class NamesHandler : public osmium::handler::Handler {
void output_pubs(const osmium::OSMObject& object) {
static void output_pubs(const osmium::OSMObject& object) {
const osmium::TagList& tags = object.tags();
if (tags.has_tag("amenity", "pub")) {
......
......@@ -72,10 +72,6 @@ namespace osmium {
*/
class AssemblerLegacy : public detail::BasicAssemblerWithTags {
void add_tags_to_area(osmium::builder::AreaBuilder& builder, const osmium::Way& way) const {
builder.add_item(way.tags());
}
void add_common_tags(osmium::builder::TagListBuilder& tl_builder, std::set<const osmium::Way*>& ways) const {
std::map<std::string, std::size_t> counter;
for (const osmium::Way* way : ways) {
......@@ -166,7 +162,7 @@ namespace osmium {
const bool area_okay = create_rings();
if (area_okay || config().create_empty_areas) {
add_tags_to_area(builder, way);
builder.add_item(way.tags());
}
if (area_okay) {
add_rings_to_area(builder);
......
......@@ -103,10 +103,12 @@ namespace osmium {
*/
class BasicAssembler {
static constexpr const std::size_t max_split_locations = 100ULL;
struct slocation {
enum {
invalid_item = 1u << 30u
invalid_item = 1U << 30U
};
uint32_t item : 31;
......@@ -271,7 +273,7 @@ namespace osmium {
using rings_stack = std::vector<rings_stack_element>;
void remove_duplicates(rings_stack& outer_rings) {
static void remove_duplicates(rings_stack& outer_rings) {
while (true) {
const auto it = std::adjacent_find(outer_rings.begin(), outer_rings.end());
if (it == outer_rings.end()) {
......@@ -352,7 +354,8 @@ namespace osmium {
std::cerr << " Segment is below (nesting=" << nesting << ")\n";
}
if (segment->ring()->is_outer()) {
const double y = ay + (by - ay) * (lx - ax) / double(bx - ax);
const double y = static_cast<double>(ay) +
static_cast<double>((by - ay) * (lx - ax)) / static_cast<double>(bx - ax);
if (debug()) {
std::cerr << " Segment belongs to outer ring (y=" << y << " ring=" << *segment->ring() << ")\n";
}
......@@ -502,7 +505,12 @@ namespace osmium {
void create_locations_list() {
m_locations.reserve(m_segment_list.size() * 2);
for (uint32_t n = 0; n < m_segment_list.size(); ++n) {
// static_cast is okay here: The 32bit limit is way past
// anything that makes sense here and even if there are
// 2^32 segments here, it would simply not go through
// all of them not building the multipolygon correctly.
assert(m_segment_list.size() < std::numeric_limits<uint32_t>::max());
for (uint32_t n = 0; n < static_cast<uint32_t>(m_segment_list.size()); ++n) {
m_locations.emplace_back(n, false);
m_locations.emplace_back(n, true);
}
......@@ -1079,6 +1087,15 @@ namespace osmium {
timer_simple_case.start();
create_rings_simple_case();
timer_simple_case.stop();
} else if (m_split_locations.size() > max_split_locations) {
if (debug()) {
std::cerr << " Ignoring polygon with "
<< m_split_locations.size()
<< " split locations (>"
<< max_split_locations
<< ")\n";
}
return false;
} else {
if (debug()) {
std::cerr << " Found split locations -> using complex algorithm\n";
......
......@@ -38,6 +38,7 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/osm/node_ref.hpp>
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <iosfwd>
......@@ -195,7 +196,7 @@ namespace osmium {
}
const char* role_name() const noexcept {
static const char* names[] = { "unknown", "outer", "inner", "empty" };
static const std::array<const char*, 4> names = {{ "unknown", "outer", "inner", "empty" }};
return names[int(m_role)];
}
......@@ -348,14 +349,14 @@ namespace osmium {
osmium::Location location;
};
seg_loc sl[4] = {
std::array<seg_loc, 4> sl = {{
{0, s1.first().location() },
{0, s1.second().location()},
{1, s2.first().location() },
{1, s2.second().location()},
};
}};
std::sort(sl, sl+4, [](const seg_loc& lhs, const seg_loc& rhs) {
std::sort(sl.begin(), sl.end(), [](const seg_loc& lhs, const seg_loc& rhs) {
return lhs.location < rhs.location;
});
......
......@@ -86,11 +86,11 @@ namespace osmium {
area_stats m_stats;
enum {
initial_output_buffer_size = 1024ul * 1024ul
initial_output_buffer_size = 1024UL * 1024UL
};
enum {
max_buffer_size_for_flush = 100ul * 1024ul
max_buffer_size_for_flush = 100UL * 1024UL
};
void flush_output_buffer() {
......
......@@ -63,8 +63,8 @@ namespace osmium {
/**
* This class collects all data needed for creating areas from
* relations tagged with type=multipolygon or type=boundary.
* Most of its functionality is derived from the parent class
* osmium::relations::Collector.
* Most of its functionality is derived from the parent template class
* osmium::relations::RelationsManager.
*
* The actual assembling of the areas is done by the assembler
* class given as template argument.
......
......@@ -49,7 +49,7 @@ namespace osmium {
constexpr double earth_radius_for_epsg3857 = 6378137.0;
constexpr double max_coordinate_epsg3857 = 20037508.34;
constexpr inline double lon_to_x(double lon) {
constexpr inline double lon_to_x(double lon) noexcept {
return earth_radius_for_epsg3857 * deg_to_rad(lon);
}
......@@ -116,6 +116,9 @@ namespace osmium {
* Convert the coordinates from WGS84 lon/lat to web mercator.
*
* @pre @code c.valid() @endcode
* @pre Coordinates must be in valid range, longitude between
* -180 and +180 degree, latitude between -MERCATOR_MAX_LAT
* and MERCATOR_MAX_LAT.
*/
inline Coordinates lonlat_to_mercator(const Coordinates& c) {
return Coordinates{detail::lon_to_x(c.x), detail::lat_to_y(c.y)};
......@@ -125,6 +128,8 @@ namespace osmium {
* Convert the coordinates from web mercator to WGS84 lon/lat.
*
* @pre @code c.valid() @endcode
* @pre Coordinates must be in valid range (longitude and
* latidude between -/+20037508.34).
*/
inline Coordinates mercator_to_lonlat(const Coordinates& c) {
return Coordinates{detail::x_to_lon(c.x), detail::y_to_lat(c.y)};
......@@ -145,6 +150,13 @@ namespace osmium {
MercatorProjection() { // NOLINT(hicpp-use-equals-default, modernize-use-equals-default)
}
/**
* Do coordinate transformation.
*
* @pre Coordinates must be in valid range, longitude between
* -180 and +180 degree, latitude between -MERCATOR_MAX_LAT
* and MERCATOR_MAX_LAT.
*/
Coordinates operator()(osmium::Location location) const {
return Coordinates{detail::lon_to_x(location.lon()), detail::lat_to_y(location.lat())};
}
......
......@@ -47,7 +47,13 @@ DEALINGS IN THE SOFTWARE.
#include <osmium/geom/util.hpp>
#include <osmium/osm/location.hpp>
#include <proj_api.h>
#ifdef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
# include <proj_api.h>
#else
# define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
# include <proj_api.h>
# undef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <memory>
#include <string>
......@@ -158,6 +164,12 @@ namespace osmium {
m_crs_user(epsg) {
}
/**
* Do coordinate transformation.
*
* @pre Location must be in valid range (depends on projection
* used).
*/
Coordinates operator()(osmium::Location location) const {
if (m_epsg == 4326) {
return Coordinates{location.lon(), location.lat()};
......