diff --git a/.github/actions/build-and-test/action.yml b/.github/actions/build-and-test/action.yml index ce5a190e7..b62fc1048 100644 --- a/.github/actions/build-and-test/action.yml +++ b/.github/actions/build-and-test/action.yml @@ -22,8 +22,8 @@ runs: else CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_LUAJIT=${LUAJIT_OPTION}" fi - if [ -n "$USE_PROJ_LIB" ]; then - CMAKE_OPTIONS="$CMAKE_OPTIONS -DUSE_PROJ_LIB=$USE_PROJ_LIB" + if [ -n "$WITH_PROJ" ]; then + CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_PROJ=$WITH_PROJ" fi if [ -n "$CPP_VERSION" ]; then CMAKE_OPTIONS="$CMAKE_OPTIONS -DCMAKE_CXX_STANDARD=$CPP_VERSION" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 543afe5bb..fdf016251 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,25 +157,6 @@ jobs: - uses: ./.github/actions/ubuntu-prerequisites - uses: ./.github/actions/build-and-test - ubuntu20-pg15-clang10-proj6: - runs-on: ubuntu-20.04 - - env: - CC: clang-10 - CXX: clang++-10 - LUA_VERSION: 5.3 - LUAJIT_OPTION: OFF - POSTGRESQL_VERSION: 15 - POSTGIS_VERSION: 3 - USE_PROJ_LIB: 6 - BUILD_TYPE: Debug - PSYCOPG: 2 - - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/ubuntu-prerequisites - - uses: ./.github/actions/build-and-test - ubuntu20-pg15-clang10-noproj: runs-on: ubuntu-20.04 @@ -186,7 +167,7 @@ jobs: LUAJIT_OPTION: OFF POSTGRESQL_VERSION: 15 POSTGIS_VERSION: 3 - USE_PROJ_LIB: off + WITH_PROJ: OFF BUILD_TYPE: Debug PSYCOPG: 2 @@ -205,7 +186,6 @@ jobs: LUAJIT_OPTION: OFF POSTGRESQL_VERSION: 16 POSTGIS_VERSION: 3 - USE_PROJ_LIB: 6 BUILD_TYPE: Debug PSYCOPG: 2 @@ -266,7 +246,7 @@ jobs: - uses: ./.github/actions/ubuntu-prerequisites - uses: ./.github/actions/build-and-test - ubuntu22-pg16-clang14-proj6: + ubuntu22-pg16-clang14-proj: runs-on: ubuntu-22.04 env: @@ -276,7 +256,6 @@ jobs: LUAJIT_OPTION: OFF POSTGRESQL_VERSION: 16 POSTGIS_VERSION: 3 - USE_PROJ_LIB: 6 BUILD_TYPE: Debug PSYCOPG: 2 @@ -295,7 +274,7 @@ jobs: LUAJIT_OPTION: OFF POSTGRESQL_VERSION: 16 POSTGIS_VERSION: 3 - USE_PROJ_LIB: off + WITH_PROJ: OFF BUILD_TYPE: Debug PSYCOPG: 2 @@ -314,7 +293,6 @@ jobs: LUAJIT_OPTION: OFF POSTGRESQL_VERSION: 15 POSTGIS_VERSION: 3 - USE_PROJ_LIB: 6 BUILD_TYPE: Debug PSYCOPG: 2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 151ddc89b..109778ae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ option(BUILD_TESTS "Build test suite" OFF) option(BUILD_COVERAGE "Build with coverage" OFF) option(WITH_LUA "Build with Lua support" ON) option(WITH_LUAJIT "Build with LuaJIT support" OFF) +option(WITH_PROJ "Build with Projection support" ON) if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) message(FATAL_ERROR "In-source builds are not allowed, please use a separate build directory like `mkdir build && cd build && cmake ..`") @@ -57,8 +58,6 @@ option(EXTERNAL_PROTOZERO "Do not use the bundled protozero" OFF) option(EXTERNAL_FMT "Do not use the bundled fmt" OFF) option(EXTERNAL_CLI11 "Do not use the bundled CLI11" OFF) -set(USE_PROJ_LIB "auto" CACHE STRING "Which version of PROJ API to use: ('4', '6', 'off', or 'auto')") - if (NOT WIN32 AND NOT APPLE) # No need for this path, just a workaround to make cmake work on all systems. # Without this we need the PostgreSQL server libraries installed. @@ -222,42 +221,18 @@ find_package(OpenCV QUIET OPTIONAL_COMPONENTS core imgcodecs imgproc) set(LIBS ${Boost_LIBRARIES} ${PostgreSQL_LIBRARY} ${OSMIUM_LIBRARIES}) -if (USE_PROJ_LIB STREQUAL "off") - message(STATUS "Proj library disabled (because USE_PROJ_LIB is set to 'off').") -else() - find_path(PROJ4_INCLUDE_DIR proj_api.h) - if (PROJ4_INCLUDE_DIR AND NOT USE_PROJ_LIB STREQUAL "6") - message(STATUS "Found proj_api.h") - find_library(PROJ_LIBRARY NAMES proj) - message(STATUS "Found Proj [API 4] ${PROJ_LIBRARY}") - add_definitions(-DHAVE_GENERIC_PROJ=4) - set(HAVE_PROJ4 1) +if (WITH_PROJ) + find_path(PROJ6_INCLUDE_DIR proj.h) + find_library(PROJ_LIBRARY NAMES proj) + if (PROJ_LIBRARY) + message(STATUS "Found Proj ${PROJ_LIBRARY}") + add_definitions(-DHAVE_GENERIC_PROJ=6) + set(HAVE_PROJ6 1) list(APPEND LIBS ${PROJ_LIBRARY}) - include_directories(SYSTEM ${PROJ4_INCLUDE_DIR}) - elseif (NOT USE_PROJ_LIB STREQUAL "4") - find_path(PROJ6_INCLUDE_DIR proj.h) - find_library(PROJ_LIBRARY NAMES proj) - if (PROJ_LIBRARY) - message(STATUS "Found Proj [API 6] ${PROJ_LIBRARY}") - add_definitions(-DHAVE_GENERIC_PROJ=6) - set(HAVE_PROJ6 1) - list(APPEND LIBS ${PROJ_LIBRARY}) - include_directories(SYSTEM ${PROJ6_INCLUDE_DIR}) - else() - message(STATUS "Proj library not found.") - message(STATUS " Only Mercartor and WGS84 projections will be available.") - endif() + include_directories(SYSTEM ${PROJ6_INCLUDE_DIR}) endif() endif() -if (USE_PROJ_LIB STREQUAL "4" AND NOT HAVE_PROJ4) - message(FATAL_ERROR "USE_PROJ_LIB was set to '4', but PROJ version 4 API not found") -endif() - -if (USE_PROJ_LIB STREQUAL "6" AND NOT HAVE_PROJ6) - message(FATAL_ERROR "USE_PROJ_LIB was set to '6', but PROJ version 6 API not found") -endif() - if (LUAJIT_FOUND) list(APPEND LIBS ${LUAJIT_LIBRARIES}) elseif (LUA_FOUND) diff --git a/README.md b/README.md index 3e1eae328..070d56826 100644 --- a/README.md +++ b/README.md @@ -171,21 +171,9 @@ Note that `Debug` builds will be much slower than release build. For production ### Using the PROJ library Osm2pgsql has builtin support for the Latlong (WGS84, EPSG:4326) and the -WebMercator (EPSG:3857) projection. If you need other projections you have to -compile with the PROJ library. - -Both the older API (PROJ version 4) and the newer API (PROJ version 6.1 and -above) are supported. Usually the CMake configuration will find a suitable -version and use it automatically, but you can set the `USE_PROJ_LIB` CMake -cache variable to choose between the following behaviours: - -* `4`: Look for PROJ library with API version 4. If it is not found, stop with - error. -* `6`: Look for PROJ library with API version 6. If it is not found, stop with - error. -* `off`: Build without PROJ library. -* `auto`: Choose API 4 if available, otherwise API 6. If both are not available - build without PROJ library. (This is the default.) +WebMercator (EPSG:3857) projection. Other projections are supported through +the [Proj library](https://proj.org/) which is used by default. Set the CMake +option `WITH_PROJ` to `OFF` to disable use of that library. ## Using LuaJIT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea1cfe979..1fe239e02 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,13 +72,7 @@ endif() target_sources(osm2pgsql_lib PRIVATE ${PROJECT_BINARY_DIR}/src/version.cpp) -if (HAVE_PROJ4) - target_sources(osm2pgsql_lib PRIVATE reprojection-generic-proj4.cpp) - if (NOT MSVC) - set_source_files_properties(reprojection-generic-proj4.cpp - PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) - endif() -elseif(HAVE_PROJ6) +if (HAVE_PROJ6) target_sources(osm2pgsql_lib PRIVATE reprojection-generic-proj6.cpp) else() target_sources(osm2pgsql_lib PRIVATE reprojection-generic-none.cpp) diff --git a/src/reprojection-generic-proj4.cpp b/src/reprojection-generic-proj4.cpp deleted file mode 100644 index 453018ccb..000000000 --- a/src/reprojection-generic-proj4.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/** - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This file is part of osm2pgsql (https://osm2pgsql.org/). - * - * Copyright (C) 2006-2024 by the osm2pgsql developer community. - * For a full list of authors see the git log. - */ - -#include "format.hpp" -#include "reprojection.hpp" - -#include - -namespace { - -/** - * Generic projection using proj library. - */ -class generic_reprojection_t : public reprojection -{ -public: - explicit generic_reprojection_t(int srs) : m_target_srs(srs), pj_target(srs) - {} - - geom::point_t reproject(geom::point_t point) const override - { - double const lon = osmium::geom::deg_to_rad(point.x()); - double const lat = osmium::geom::deg_to_rad(point.y()); - - auto const c = osmium::geom::transform( - pj_source, pj_target, osmium::geom::Coordinates{lon, lat}); - return {c.x, c.y}; - } - - geom::point_t target_to_tile(geom::point_t point) const override - { - auto const c = osmium::geom::transform( - pj_target, pj_tile, - osmium::geom::Coordinates{point.x(), point.y()}); - return {c.x, c.y}; - } - - int target_srs() const noexcept override { return m_target_srs; } - - char const *target_desc() const noexcept override - { - return pj_get_def(pj_target.get(), 0); - } - -private: - int m_target_srs; - osmium::geom::CRS pj_target; - - /// The projection of the source data. Always lat/lon (EPSG:4326). - osmium::geom::CRS pj_source{PROJ_LATLONG}; - - /** - * The projection used for tiles. Currently this is fixed to be Spherical - * Mercator. You will usually have tiles in the same projection as used - * for PostGIS, but it is theoretically possible to have your PostGIS data - * in, say, lat/lon but still create tiles in Spherical Mercator. - */ - osmium::geom::CRS pj_tile{PROJ_SPHERE_MERC}; -}; - -} // anonymous namespace - -std::shared_ptr reprojection::make_generic_projection(int srs) -{ - return std::make_shared(srs); -} - -std::string get_proj_version() -{ - return fmt::format("[API 4] {}", pj_get_release()); -} diff --git a/src/reprojection-generic-proj6.cpp b/src/reprojection-generic-proj6.cpp index 654ebc860..636ccd99a 100644 --- a/src/reprojection-generic-proj6.cpp +++ b/src/reprojection-generic-proj6.cpp @@ -119,6 +119,6 @@ std::shared_ptr reprojection::make_generic_projection(int srs) std::string get_proj_version() { - return fmt::format("[API 6] {}", proj_info().version); + return fmt::format("{}", proj_info().version); }