Skip to content

Commit

Permalink
fix: define epsg table, resolves #567
Browse files Browse the repository at this point in the history
  • Loading branch information
program-- authored and hellkite500 committed Nov 13, 2023
1 parent cac9341 commit f5e7d1c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 43 deletions.
5 changes: 3 additions & 2 deletions include/geopackage/proj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define NGEN_GEOPACKAGE_PROJ_HPP

#include <boost/geometry/srs/projection.hpp>
#include <unordered_map>

namespace ngen {
namespace srs {
Expand All @@ -21,8 +22,8 @@ struct epsg
static srs_type get(uint32_t srid);

private:
static const srs_type epsg5070_;
static const srs_type epsg3857_;
using def_type = std::unordered_map<int, srs_type>;
static const def_type defs_;
};

} // namespace srs
Expand Down
11 changes: 0 additions & 11 deletions src/geopackage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
string(COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "IntelLLVM" _cmp)
if (NOT _cmp)
message(WARNING "[NGen::geopackage] wkb.cpp cannot be optimized with "
"${CMAKE_CXX_COMPILER_ID} due to a suspected optimizer/boost issue:\n"
"https://github.com/NOAA-OWP/ngen/issues/567.\n"
"Use IntelLLVM if optimization for this source file is required.")
# !! Required due to optimizer issue with either clang or
# !! boost::geometry::srs::transformation
set_source_files_properties(wkb.cpp PROPERTIES COMPILE_OPTIONS "-O0;-fno-sanitize=all")
endif()

add_library(geopackage proj.cpp
geometry.cpp
properties.cpp
Expand Down
40 changes: 10 additions & 30 deletions src/geopackage/proj.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
#include "proj.hpp"
#include <boost/geometry/srs/projections/epsg.hpp>

namespace ngen {
namespace srs {

const epsg::srs_type epsg::epsg5070_ =
epsg::srs_type(bg::srs::dpar::proj_aea)
(bg::srs::dpar::ellps_grs80)
(bg::srs::dpar::towgs84, {0,0,0,0,0,0,0})
(bg::srs::dpar::lat_0, 23)
(bg::srs::dpar::lon_0, -96)
(bg::srs::dpar::lat_1, 29.5)
(bg::srs::dpar::lat_2, 45.5)
(bg::srs::dpar::x_0, 0)
(bg::srs::dpar::y_0, 0);

const epsg::srs_type epsg::epsg3857_ =
epsg::srs_type(bg::srs::dpar::proj_merc)
(bg::srs::dpar::units_m)
(bg::srs::dpar::no_defs)
(bg::srs::dpar::a, 6378137)
(bg::srs::dpar::b, 6378137)
(bg::srs::dpar::lat_ts, 0)
(bg::srs::dpar::lon_0, 0)
(bg::srs::dpar::x_0, 0)
(bg::srs::dpar::y_0, 0)
(bg::srs::dpar::k, 1);
const epsg::def_type epsg::defs_ = {
{4326, epsg::srs_type(bg::srs::dpar::proj_longlat)(bg::srs::dpar::ellps_wgs84)(bg::srs::dpar::datum_wgs84)(bg::srs::dpar::no_defs)},
{5070, epsg::srs_type(bg::srs::dpar::proj_aea)(bg::srs::dpar::ellps_grs80)(bg::srs::dpar::towgs84, {0,0,0,0,0,0,0})(bg::srs::dpar::lat_0, 23)(bg::srs::dpar::lon_0, -96)(bg::srs::dpar::lat_1, 29.5)(bg::srs::dpar::lat_2, 45.5)(bg::srs::dpar::x_0, 0)(bg::srs::dpar::y_0, 0)},
{3857, epsg::srs_type(bg::srs::dpar::proj_merc)(bg::srs::dpar::units_m)(bg::srs::dpar::no_defs)(bg::srs::dpar::a, 6378137)(bg::srs::dpar::b, 6378137)(bg::srs::dpar::lat_ts, 0)(bg::srs::dpar::lon_0, 0)(bg::srs::dpar::x_0, 0)(bg::srs::dpar::y_0, 0)(bg::srs::dpar::k, 1)}
};

auto epsg::get(uint32_t srid) -> srs_type
{
switch (srid) {
case 5070:
return epsg5070_;
case 3857:
return epsg3857_;
default:
return bg::projections::detail::epsg_to_parameters(srid);

if (defs_.count(srid) == 0) {
throw std::runtime_error("SRID " + std::to_string(srid) + " is not supported. Project the input data to EPSG:5070 or EPSG:4326.");
}

return defs_.at(srid);
}

} // namespace srs
Expand Down

0 comments on commit f5e7d1c

Please sign in to comment.